-
Notifications
You must be signed in to change notification settings - Fork 0
/
values_test.go
154 lines (145 loc) · 2.64 KB
/
values_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package expect
import (
"testing"
)
func TestEqual(t *testing.T) {
var (
one = 1
onePrime = 1
two = 2
)
testCases := []struct {
name string
first *int
second *int
fail bool
}{
{
name: "NotEqual",
first: &one,
second: &two,
fail: true,
},
{
name: "SameReferents",
first: &one,
second: &onePrime,
fail: false,
},
{
name: "SamePointer",
first: &one,
second: &one,
fail: false,
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
tt := newTMock()
Equal(tt, testCase.first, testCase.second)
fail := tt.ErrorfCalled > 0
if testCase.fail != fail {
t.Errorf("Expected failure: %v\nActual failure: %v", testCase.fail, fail)
}
})
}
}
func TestEqualUnordered(t *testing.T) {
testCases := []struct {
name string
first sliceWrapper
second sliceWrapper
fail bool
}{
{
name: "Nil/Nil",
first: nil,
second: nil,
fail: false,
},
{
name: "Nil/Empty",
first: nil,
second: []intWrapper{},
fail: true,
},
{
name: "Nil/NonNil",
first: nil,
second: []intWrapper{1},
fail: true,
},
{
name: "DifferentElements",
first: []intWrapper{1, 2, 3},
second: []intWrapper{4, 5, 6},
fail: true,
},
{
name: "SameElements/SameOrder",
first: []intWrapper{1, 2, 3},
second: []intWrapper{1, 2, 3},
fail: false,
},
{
name: "SameElements/DifferentOrder",
first: []intWrapper{1, 2, 3},
second: []intWrapper{3, 1, 2},
fail: false,
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
tt := new(testing.T)
EqualUnordered(tt, testCase.first, testCase.second)
fail := tt.Failed()
if testCase.fail != fail {
t.Errorf("Expected failure: %v\nActual failure: %v", testCase.fail, fail)
}
})
}
}
type intWrapper int
type sliceWrapper []intWrapper
func TestDeepEqual(t *testing.T) {
var (
one = 1
onePrime = 1
two = 2
)
testCases := []struct {
name string
first *int
second *int
fail bool
}{
{
name: "NotEqual",
first: &one,
second: &two,
fail: true,
},
{
name: "SameReferents",
first: &one,
second: &onePrime,
fail: false,
},
{
name: "SamePointer",
first: &one,
second: &one,
fail: false,
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
tt := new(testing.T)
DeepEqual(tt, testCase.first, testCase.second)
fail := tt.Failed()
if testCase.fail != fail {
t.Errorf("Expected failure: %v\nActual failure: %v", testCase.fail, fail)
}
})
}
}