-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
61 lines (49 loc) · 910 Bytes
/
util_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
package algo
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAllComb(t *testing.T) {
n := 2
actual := AllComb(n)
expected := [][]int{
[]int{0, 0},
[]int{0, 1},
[]int{1, 0},
[]int{1, 1},
}
assert.ElementsMatch(t, expected, actual)
}
func TestAllCombChan(t *testing.T) {
n := 2
nPatterns := 1 << uint(n)
// prepare channels
c := make(chan []int, nPatterns)
go AllCombChan(n, c)
actual := Ints2d(nPatterns, n)
i := 0
for p := range c {
actual[i] = p
i++
}
expected := [][]int{
[]int{0, 0},
[]int{0, 1},
[]int{1, 0},
[]int{1, 1},
}
assert.ElementsMatch(t, expected, actual)
}
func TestPermuteInts(t *testing.T) {
nums := []int{1, 2, 3}
actual := PermuteInts(nums)
expected := [][]int{
[]int{1, 2, 3},
[]int{1, 3, 2},
[]int{2, 1, 3},
[]int{2, 3, 1},
[]int{3, 1, 2},
[]int{3, 2, 1},
}
assert.ElementsMatch(t, expected, actual)
}