-
Notifications
You must be signed in to change notification settings - Fork 0
/
testcase_test.go
108 lines (90 loc) · 2.62 KB
/
testcase_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
package testcase
import (
"reflect"
"testing"
)
func TestGenerateTestCases(t *testing.T) {
type testCase struct {
Enabled bool `tc:"[true, false]"`
Size int `tc:"[1,2]"`
}
expected := []testCase{{true, 1}, {true, 2}, {false, 1}, {false, 2}}
var generated []testCase
var tc testCase
for gen := GenerateTestCases(t, &tc); gen.Next(); {
generated = append(generated, tc)
}
if !reflect.DeepEqual(expected, generated) {
t.Errorf("Expected\n%+v\nFound\n%+v\n", expected, generated)
}
}
func TestGnerateMixedTestCases(t *testing.T) {
type testCase struct {
Enabled bool `tc:"[true, false]"`
Size int `tc:"[1,2]"`
i int
}
expected := []testCase{
{true, 1, 1}, {true, 2, 1}, {false, 1, 1}, {false, 2, 1},
{true, 1, 2}, {true, 2, 2}, {false, 1, 2}, {false, 2, 2},
{true, 1, 3}, {true, 2, 3}, {false, 1, 3}, {false, 2, 3},
}
var generated []testCase
for _, tc := range []testCase{
{i: 1}, {i: 2}, {i: 3},
} {
for gen := GenerateTestCases(t, &tc); gen.Next(); {
generated = append(generated, tc)
}
}
if !reflect.DeepEqual(expected, generated) {
t.Errorf("Expected\n%+v\nFound\n%+v\n", expected, generated)
}
}
func TestGenerateComplexTypes(t *testing.T) {
type testCase struct {
Slice []int `tc:"[[1,2,3],[9,8],[0]]"`
KV map[string]int `tc:"[{\"one\":1, \"two\":2}, {\"zero\":0}]"`
}
a1 := []int{1, 2, 3}
a2 := []int{9, 8}
a3 := []int{0}
m1 := map[string]int{"one": 1, "two": 2}
m2 := map[string]int{"zero": 0}
expected := []testCase{
{a1, m1}, {a1, m2},
{a2, m1}, {a2, m2},
{a3, m1}, {a3, m2},
}
var generated []testCase
var tc testCase
for gen := GenerateTestCases(t, &tc); gen.Next(); {
generated = append(generated, tc)
}
if !reflect.DeepEqual(expected, generated) {
t.Errorf("Expected\n%+v\nFound\n%+v\n", expected, generated)
}
}
func TestGenerateNextedComplexTypes(t *testing.T) {
type testCase struct {
Enabled bool `tc:"[true, false]"`
Slice [][]int `tc:"[[[1],[2,3]],[[9],[8]]]"`
KV map[string][]int `tc:"[{\"1-2\":[1,2], \"3-4\":[3, 4]}, {\"5-7\": [5,6,7]}]"`
}
a1 := [][]int{{1}, {2, 3}}
a2 := [][]int{{9}, {8}}
m1 := map[string][]int{"1-2": {1, 2}, "3-4": {3, 4}}
m2 := map[string][]int{"5-7": {5, 6, 7}}
expected := []testCase{
{true, a1, m1}, {true, a1, m2}, {true, a2, m1}, {true, a2, m2},
{false, a1, m1}, {false, a1, m2}, {false, a2, m1}, {false, a2, m2},
}
var generated []testCase
var tc testCase
for gen := GenerateTestCases(t, &tc); gen.Next(); {
generated = append(generated, tc)
}
if !reflect.DeepEqual(expected, generated) {
t.Errorf("Expected\n%+v\nFound\n%+v\n", expected, generated)
}
}