-
Notifications
You must be signed in to change notification settings - Fork 0
/
count_test.go
92 lines (80 loc) · 1.95 KB
/
count_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package collections
import (
"reflect"
"testing"
)
func TestNewCounter(t *testing.T) {
cases := []struct {
sample []float64
want *Counter
}{
{[]float64{1.0, 2.0}, &Counter{map[float64]int{1.0: 1, 2.0: 1}}},
{[]float64{1.0, 1.0}, &Counter{map[float64]int{1.0: 2}}},
}
for _, c := range cases {
gotCounter := NewCounter(c.sample)
if !reflect.DeepEqual(gotCounter, c.want) {
t.Errorf("NewCounter(%v) want: %v but got: %v",
c.sample, c.want, gotCounter)
}
}
}
func TestNewCounter_WhenSampleIsEmpty(t *testing.T) {
defer func() {
if recover() == nil {
t.Errorf("Expected NewCounter panic when empty sample")
}
}()
NewCounter([]float64{})
}
func TestMaxValues(t *testing.T) {
cases := []struct {
sample []float64
want int
}{
{[]float64{1.0, 2.0, 3.0, 1.0}, 2.0},
{[]float64{1.0, 1.0}, 2.0},
{[]float64{1.0, 2.0}, 1.0},
}
for _, c := range cases {
gotMaxValue := NewCounter(c.sample).MaxValue()
if c.want != gotMaxValue {
t.Errorf("Counter(%v).MaxValue() want: %v but got %v.",
c.sample, c.want, gotMaxValue)
}
}
}
func TestMaxValues_WhenCounterIsEmpty(t *testing.T) {
defer func() {
if recover() == nil {
t.Errorf("Expected Counter.MaxValue() panic when empty sample")
}
}()
NewCounter([]float64{}).MaxValue()
}
func TestValues(t *testing.T) {
cases := []struct {
sample []float64
want []int
}{
{[]float64{1.0, 2.0, 3.0, 4.0}, []int{1}},
{[]float64{1.0, 2.0, 1.0, 4.0}, []int{1, 2}},
{[]float64{1.0, 2.0, 1.0, 1.0}, []int{1, 3}},
{[]float64{1.0, 1.0, 1.0, 1.0}, []int{4}},
}
for _, c := range cases {
gotValues := NewCounter(c.sample).Values()
if !reflect.DeepEqual(gotValues, c.want) {
t.Errorf("Counter(%v).Values() want: %v but got %v",
c.sample, c.want, gotValues)
}
}
}
func TestValues_WhenCounterIsEmpty(t *testing.T) {
defer func() {
if recover() == nil {
t.Errorf("Expected Counter.Values() panic when empty sample")
}
}()
NewCounter([]float64{}).Values()
}