-
-
Notifications
You must be signed in to change notification settings - Fork 168
/
min_test.go
70 lines (62 loc) · 1.34 KB
/
min_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package stats_test
import (
"fmt"
"testing"
"github.com/montanaflynn/stats"
)
func ExampleMin() {
d := stats.LoadRawData([]interface{}{1.1, "2", 3.0, 4, "5"})
a, _ := stats.Min(d)
fmt.Println(a)
// Output: 1.1
}
func TestMin(t *testing.T) {
for _, c := range []struct {
in []float64
out float64
}{
{[]float64{1.1, 2, 3, 4, 5}, 1.1},
{[]float64{10.534, 3, 5, 7, 9}, 3.0},
{[]float64{-5, 1, 5}, -5.0},
{[]float64{5}, 5},
} {
got, err := stats.Min(c.in)
if err != nil {
t.Errorf("Returned an error")
}
if got != c.out {
t.Errorf("Min(%.1f) => %.1f != %.1f", c.in, got, c.out)
}
}
_, err := stats.Min([]float64{})
if err == nil {
t.Errorf("Empty slice didn't return an error")
}
}
func BenchmarkMinSmallFloatSlice(b *testing.B) {
testData := makeFloatSlice(5)
for i := 0; i < b.N; i++ {
_, _ = stats.Min(testData)
}
}
func BenchmarkMinSmallRandFloatSlice(b *testing.B) {
testData := makeRandFloatSlice(5)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = stats.Min(testData)
}
}
func BenchmarkMinLargeFloatSlice(b *testing.B) {
testData := makeFloatSlice(100000)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = stats.Min(testData)
}
}
func BenchmarkMinLargeRandFloatSlice(b *testing.B) {
testData := makeRandFloatSlice(100000)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = stats.Min(testData)
}
}