-
Notifications
You must be signed in to change notification settings - Fork 1
/
group_test.go
69 lines (56 loc) · 1.04 KB
/
group_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
package ranges
import "testing"
func TestGroup(t *testing.T) {
t.Parallel()
result := Slice(
Group(
Only("a", "b", "b", "b", "c", "c", "d"),
func(a, b string) bool { return a == b },
),
)
assertEqual(t, result, []Pair[string, int]{
{"a", 1},
{"b", 3},
{"c", 2},
{"d", 1},
})
}
func TestGroupS(t *testing.T) {
t.Parallel()
result := Slice(
GroupS(
[]string{"a", "b", "b", "b", "c", "c", "d"},
func(a, b string) bool { return a == b },
),
)
assertEqual(t, result, []Pair[string, int]{
{"a", 1},
{"b", 3},
{"c", 2},
{"d", 1},
})
}
func TestGroupComparable(t *testing.T) {
t.Parallel()
result := Slice(
GroupComparable(Only("a", "b", "b", "b", "c", "c", "d")),
)
assertEqual(t, result, []Pair[string, int]{
{"a", 1},
{"b", 3},
{"c", 2},
{"d", 1},
})
}
func TestGroupComparableS(t *testing.T) {
t.Parallel()
result := Slice(
GroupComparableS([]string{"a", "b", "b", "b", "c", "c", "d"}),
)
assertEqual(t, result, []Pair[string, int]{
{"a", 1},
{"b", 3},
{"c", 2},
{"d", 1},
})
}