forked from kokardy/listing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp__test.go
65 lines (61 loc) · 1.03 KB
/
p__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
package listing
import (
"testing"
)
func TestPermStringSlice(t *testing.T) {
buf := 5
list := StringReplacer([]string{
"a", "b", "c", "d", "e",
})
n := len(list)
m := 4
expected := pCount(n, m)
count := 0
for perm := range Permutations(list, m, false, buf) {
count++
//t.Log(count, comb)
_ = perm
}
if count != expected {
t.Fatalf("%dC%d != %d", n, m, expected)
}
}
func TestPermInt(t *testing.T) {
buf := 5
list := []int{
1, 2, 3, 4, 5,
}
n := len(list)
m := 4
expected := pCount(n, m)
count := 0
for perm := range permutations(list, m, buf) {
count++
//t.Log(count, comb)
_ = perm
}
if count != expected {
t.Fatalf("%dC%d != %d", n, m, expected)
}
}
func TestRepeatedlyPermInt(t *testing.T) {
buf := 5
list := []int{
1, 2, 3, 4,
}
n := len(list)
m := 2
expected := 1
for i := 0; i < m; i++ {
expected *= n
}
count := 0
for perm := range repeatedPermutations(list, m, buf) {
count++
//t.Log(count, comb)
_ = perm
}
if count != expected {
t.Fatalf("%dC%d != %d", n, m, expected)
}
}