-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombine_test.go
More file actions
104 lines (95 loc) · 2.23 KB
/
Copy pathcombine_test.go
File metadata and controls
104 lines (95 loc) · 2.23 KB
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
103
104
package algorithm
import "testing"
func TestCombNumber(t *testing.T) {
testcase := []struct {
n uint64
m uint64
r uint64
}{
{2, 1, 2},
{5, 3, 10},
{7, 5, 21},
}
for i := 0; i < len(testcase); i++ {
cn := CombNumber(testcase[i].n, testcase[i].m)
if cn != testcase[i].r {
t.Errorf("[fail] C(%d,%d)=%d, but result=%d", testcase[i].n, testcase[i].m, testcase[i].r, cn)
} else {
t.Logf("[ok] C(%d,%d)=%d", testcase[i].n, testcase[i].m, testcase[i].r)
}
}
}
func BenchmarkCombNumber(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
CombNumber(52, 7)
}
}
func TestCombinerSelectNoRecursion(t *testing.T) {
testcase := []struct {
atable []int32
n int
}{
{[]int32{0, 1, 2, 3, 4, 5, 6}, 5},
}
for i := 0; i < len(testcase); i++ {
result := CombinerSelectNoRecursion(testcase[i].atable, testcase[i].n)
for i := 0; i < len(result); i++ {
t.Log(i, result[i])
}
t.Logf("Combiner(%v,%v)=cnt=%v \n", testcase[i].atable, testcase[i].n, len(result))
}
}
func TestCombinerSelectUseRecursion(t *testing.T) {
testcase := []struct {
atable []int32
n int
}{
{[]int32{0, 1, 2, 3, 4, 5, 6}, 5},
}
var ints []int32
for i := 0; i < 43; i++ {
ints = append(ints, int32(i))
}
for i := 0; i < len(testcase); i++ {
result := CombinerSelectUseRecursion(ints, 2)
for i := 0; i < len(result); i++ {
t.Log(i, result[i])
}
t.Logf("Combiner2(%v,%v)=cnt=%v \n", testcase[i].atable, testcase[i].n, len(result))
}
}
func BenchmarkCombinerSelectNoRecursion(b *testing.B) {
atable := make([]int32, 45)
for i := 0; i < 45; i++ {
atable[i] = int32(i)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
CombinerSelectNoRecursion(atable, 2)
}
}
func BenchmarkCombinerSelectUseRecursion(b *testing.B) {
atable := make([]int32, 45)
for i := 0; i < 45; i++ {
atable[i] = int32(i)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
CombinerSelectUseRecursion(atable, 2)
}
}
func TestFullPermutation(t *testing.T) {
var test = []int32{0, 1, 2, 3, 4}
r := FullPermutation(test)
for i := 0; i < len(r); i++ {
t.Log("FullPermutation", i, "===", r[i])
}
}
func BenchmarkFullPermutation(b *testing.B) {
var test = []int32{0, 1, 2, 3, 4}
b.ResetTimer()
for i := 0; i < b.N; i++ {
FullPermutation(test)
}
}