-
Notifications
You must be signed in to change notification settings - Fork 1
/
cartesianproduct_test.go
102 lines (93 loc) · 2.35 KB
/
cartesianproduct_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
93
94
95
96
97
98
99
100
101
102
package ranges
import "testing"
func TestCartesianProduct2(t *testing.T) {
t.Parallel()
assertEqual(
t,
SliceF(CartesianProduct2(Iota(2), Iota(3))),
[]Pair[int, int]{
{0, 0},
{0, 1},
{0, 2},
{1, 0},
{1, 1},
{1, 2},
},
)
assertEqual(
t,
SliceF(CartesianProduct2(Iota(3), Iota(2))),
[]Pair[int, int]{
{0, 0},
{0, 1},
{1, 0},
{1, 1},
{2, 0},
{2, 1},
},
)
}
func TestCartesianProduct3(t *testing.T) {
t.Parallel()
assertEqual(
t,
SliceF(CartesianProduct3(Runes("abc"), Iota(2), Runes("xyz"))),
[]Triplet[rune, int, rune]{
{'a', 0, 'x'}, {'a', 0, 'y'}, {'a', 0, 'z'}, {'a', 1, 'x'}, {'a', 1, 'y'}, {'a', 1, 'z'}, {'b', 0, 'x'}, {'b', 0, 'y'}, {'b', 0, 'z'}, {'b', 1, 'x'}, {'b', 1, 'y'}, {'b', 1, 'z'}, {'c', 0, 'x'}, {'c', 0, 'y'}, {'c', 0, 'z'}, {'c', 1, 'x'}, {'c', 1, 'y'}, {'c', 1, 'z'},
},
)
}
func TestCartesianProduct4(t *testing.T) {
t.Parallel()
assertEqual(
t,
SliceF(CartesianProduct4(Runes("abc"), Iota(2), Runes("xyz"), Runes("42"))),
[]Quartet[rune, int, rune, rune]{
{'a', 0, 'x', '4'}, {'a', 0, 'x', '2'}, {'a', 0, 'y', '4'}, {'a', 0, 'y', '2'}, {'a', 0, 'z', '4'},
{'a', 0, 'z', '2'}, {'a', 1, 'x', '4'}, {'a', 1, 'x', '2'}, {'a', 1, 'y', '4'}, {'a', 1, 'y', '2'},
{'a', 1, 'z', '4'}, {'a', 1, 'z', '2'}, {'b', 0, 'x', '4'}, {'b', 0, 'x', '2'}, {'b', 0, 'y', '4'},
{'b', 0, 'y', '2'}, {'b', 0, 'z', '4'}, {'b', 0, 'z', '2'}, {'b', 1, 'x', '4'}, {'b', 1, 'x', '2'},
{'b', 1, 'y', '4'}, {'b', 1, 'y', '2'}, {'b', 1, 'z', '4'}, {'b', 1, 'z', '2'}, {'c', 0, 'x', '4'},
{'c', 0, 'x', '2'}, {'c', 0, 'y', '4'}, {'c', 0, 'y', '2'}, {'c', 0, 'z', '4'}, {'c', 0, 'z', '2'},
{'c', 1, 'x', '4'}, {'c', 1, 'x', '2'}, {'c', 1, 'y', '4'}, {'c', 1, 'y', '2'}, {'c', 1, 'z', '4'},
{'c', 1, 'z', '2'},
},
)
}
func TestCartesianProduct10(t *testing.T) {
t.Parallel()
assertEqual(
t,
SliceF(CartesianProduct10(
Iota(2),
Iota(2),
Iota(2),
Iota(2),
Iota(2),
Iota(2),
Iota(2),
Iota(2),
Iota(2),
Iota(2),
)),
SliceF(
MapF(
Iota(1024),
func(num int) Decade[int, int, int, int, int, int, int, int, int, int] {
return MakeDecade(
(num&512)>>9,
(num&256)>>8,
(num&128)>>7,
(num&64)>>6,
(num&32)>>5,
(num&16)>>4,
(num&8)>>3,
(num&4)>>2,
(num&2)>>1,
num&1,
)
},
),
),
)
}