-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenumerate_test.go
63 lines (45 loc) · 1.11 KB
/
enumerate_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
package ranges
import "testing"
func TestEnumerate(t *testing.T) {
t.Parallel()
keys := Slice(Map(
Enumerate[int](Only(7, 9, 1)),
func(x Pair[int, int]) int { return x.A },
))
assertEqual(t, keys, []int{0, 1, 2})
values := Slice(Map(
Enumerate[int](Only(7, 9, 1)),
func(x Pair[int, int]) int { return x.B },
))
assertEqual(t, values, []int{7, 9, 1})
}
func TestEnumerateN(t *testing.T) {
t.Parallel()
keys := Slice(Map(
EnumerateN[int](Only(7, 9, 1), 3),
func(x Pair[int, int]) int { return x.A },
))
assertEqual(t, keys, []int{3, 4, 5})
}
func TestEnumerateF(t *testing.T) {
t.Parallel()
enumerateRange := EnumerateF(Only(7, 9, 1))
keys := SliceF(MapF(
enumerateRange.Save(),
func(x Pair[int, int]) int { return x.A },
))
assertEqual(t, keys, []int{0, 1, 2})
values := SliceF(MapF(
enumerateRange,
func(x Pair[int, int]) int { return x.B },
))
assertEqual(t, values, []int{7, 9, 1})
}
func TestEnumerateNF(t *testing.T) {
t.Parallel()
keys := SliceF(MapF(
EnumerateNF(Only(7, 9, 1), 3),
func(x Pair[int, int]) int { return x.A },
))
assertEqual(t, keys, []int{3, 4, 5})
}