forked from kokardy/listing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc__test.go
117 lines (106 loc) · 1.95 KB
/
c__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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package listing
import (
"strings"
"testing"
)
func TestComtStringSlice(t *testing.T) {
buf := 5
list := StringReplacer([]string{
"ab",
"cd",
"ef",
"gh",
})
n := len(list)
m := 3
expected := cCount(n, m)
count := 0
for comb := range Combinations(list, m, false, buf) {
count++
_ = comb
}
if count != expected {
t.Fatalf("%dC%d != %d", n, m, expected)
}
}
func TestCombInt(t *testing.T) {
buf := 5
list := []int{
1, 2, 3, 4, 5,
}
n := len(list)
m := 4
expected := cCount(n, m)
count := 0
for comb := range combinations(list, m, buf) {
count++
_ = comb
}
if count != expected {
t.Fatalf("%dC%d != %d", n, m, expected)
}
}
func TestRepeatedlyCombInt(t *testing.T) {
buf := 5
list := []int{
1, 2, 3, 4, 5,
}
n := len(list)
m := 4
expected := hCount(n, m)
count := 0
for comb := range repeatedCombinations(list, m, buf) {
count++
_ = comb
}
if count != expected {
t.Fatalf("%dC%d != %d", n, m, expected)
}
}
type CustomStruct struct {
Name string
// something
}
func (cs CustomStruct) Stringer() string {
return cs.Name
}
type CustomReplacer []CustomStruct
func (cr CustomReplacer) Len() int {
return len(cr)
}
func (cr CustomReplacer) Replace(indices []int) Replacer {
result := make(CustomReplacer, len(indices))
for i, idx := range indices {
result[i] = cr[idx]
}
return result
}
func (cr CustomReplacer) Stringer() string {
css := make([]string, cr.Len())
for i, cs := range cr {
css[i] = cs.Stringer()
}
return "[" + strings.Join(css, ", ") + "]"
}
func TestCustomStruct(t *testing.T) {
selectNum := 5
repeatable := false
buf := 3
var custom = CustomReplacer{
{Name: "custom1"},
{Name: "custom2"},
{Name: "custom3"},
{Name: "custom4"},
{Name: "custom5"},
{Name: "custom6"},
}
count := 0
expected := 6
for comb := range Combinations(custom, selectNum, repeatable, buf) {
_ = comb
count++
}
if count != expected {
t.Fatalf("count: %d but expected: %d", count, expected)
}
}