-
Notifications
You must be signed in to change notification settings - Fork 1
/
common_test.go
65 lines (57 loc) · 1.23 KB
/
common_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 next
import "testing"
type testbase bool
func (t testbase) of(int) <-chan []interface{} { return nil }
func newCases(n int) []base {
b := make([]interface{}, n)
for i := range b {
b[i] = string('a' + i)
}
return []base{
combination(b[:]),
permutation(b[:]),
repeatCombination(b[:]),
repeatPermutation(b[:]),
}
}
func TestUnknown(t *testing.T) {
if c := count(testbase(false), 2); c != 0 {
t.Fail()
}
}
func TestSizes(t *testing.T) {
size := 7
cases := newCases(size)
for _, c := range cases {
for i := 0; i < size+2; i++ {
var tot int
ch := c.of(i)
for _ = range ch {
tot++
}
if expected := count(c, i); tot != expected {
t.Errorf("%T (%2d %2d) = %d (expected %d)", c, size, i, tot, expected)
} else {
t.Logf("%T (%2d %2d) = %d", c, size, i, tot)
}
}
}
}
func TestCreation(t *testing.T) {
base := []interface{}{1, 2, 3}
Combination(base, 2, false)
Combination(base, -1, true)
Permutation(base, 2, false)
Permutation(base, -1, true)
}
func TestShowcase(t *testing.T) {
size := 5
cases := newCases(size)
for _, c := range cases {
var r = make([][]interface{}, 0, count(c, size))
for v := range c.of(3) {
r = append(r, v)
}
t.Logf("Result for %T: %v", c, r)
}
}