-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsuite_test.go
More file actions
132 lines (107 loc) · 2.58 KB
/
Copy pathsuite_test.go
File metadata and controls
132 lines (107 loc) · 2.58 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package testo
import (
"reflect"
"slices"
"testing"
)
type MySuite struct{ Suite[*T] }
func (MySuite) CasesNumbers() []int {
return []int{1, 2, 3}
}
func (MySuite) CasesEmpty() []string {
return []string{}
}
func TestSuiteCasesOf(t *testing.T) {
t.Parallel()
cases := suiteCasesOf[MySuite](t)
// Expect two case sets: "Numbers" and "Empty"
if _, ok := cases["Numbers"]; !ok {
t.Error("case set for Numbers not found")
}
if _, ok := cases["Empty"]; !ok {
t.Error("case set for Empty not found")
}
// Test "Numbers" provides type int
numCase := cases["Numbers"]
if reflect.TypeFor[int]() != numCase.Provides {
t.Error("Numbers case does not provide int")
}
// Run the case function
numVals := numCase.Func(MySuite{})
ints := make([]int, len(numVals))
for i, rv := range numVals {
ints[i] = int(rv.Int())
}
if !slices.Equal(ints, []int{1, 2, 3}) {
t.Error("case values for Numbers does not match")
}
// Test "Empty" provides type string
emptyCase := cases["Empty"]
if reflect.TypeFor[string]() != emptyCase.Provides {
t.Error("Empty case does not provide string")
}
// Run the case function
emptyVals := emptyCase.Func(MySuite{})
if len(emptyVals) > 0 {
t.Error("Empty case is not empty")
}
}
func BenchmarkCasesPermutations(b *testing.B) {
// Small input: 2 keys with 2 values each (4 permutations)
b.Run("small", func(b *testing.B) {
input := map[string][]int{
"a": {1, 2},
"b": {3, 4},
}
b.ResetTimer()
for range b.N {
casesPermutations(input)
}
})
// Medium input: 3 keys with 3 values each (27 permutations)
b.Run("medium", func(b *testing.B) {
input := map[string][]int{
"a": {1, 2, 3},
"b": {4, 5, 6},
"c": {7, 8, 9},
}
b.ResetTimer()
for range b.N {
casesPermutations(input)
}
})
// Large input: 5 keys with 5 values each (3_125 permutations)
b.Run("large", func(b *testing.B) {
input := map[string][]int{
"a": {1, 2, 3, 4, 5},
"b": {6, 7, 8, 9, 10},
"c": {11, 12, 13, 14, 15},
"d": {16, 17, 18, 19, 20},
"e": {21, 22, 23, 24, 25},
}
b.ResetTimer()
for range b.N {
casesPermutations(input)
}
})
}
type SubSuiteParent struct {
Suite[*T]
}
func (s SubSuiteParent) Test(t *T) {
if !RunSubSuite(t, new(SubSuiteChild)) {
t.Fatal("run sub suite failed")
}
}
type SubSuiteChild struct{ Suite[*T] }
func (s SubSuiteChild) Test(t *T) {
if reflect.TypeOf(Reflect(t).Suite.Parent.Value) != reflect.TypeFor[*SubSuiteParent]() {
t.Fatal("unexpected parent suite type")
}
}
func TestSubSuite(t *testing.T) {
t.Parallel()
if !RunSuite(t, new(SubSuiteParent)) {
t.Fatal("run suite failed")
}
}