@@ -10,18 +10,63 @@ func TestSolution(t *testing.T) {
10
10
// 测试用例
11
11
cases := []struct {
12
12
name string
13
- inputs bool
14
- expect bool
13
+ inputs [] int
14
+ expect int
15
15
}{
16
- {"TestCase" , true , true },
17
- {"TestCase" , true , true },
18
- {"TestCase" , false , false },
16
+ {"TestCase" , []int {2 , 2 , 1 }, 1 },
17
+ {"TestCase" , []int {4 , 1 , 2 , 1 , 2 }, 4 },
19
18
}
20
19
21
20
// 开始测试
22
21
for i , c := range cases {
23
22
t .Run (c .name + " " + strconv .Itoa (i ), func (t * testing.T ) {
24
- got := Solution (c .inputs )
23
+ got := singleNumber (c .inputs )
24
+ if ! reflect .DeepEqual (got , c .expect ) {
25
+ t .Fatalf ("expected: %v, but got: %v, with inputs: %v" ,
26
+ c .expect , got , c .inputs )
27
+ }
28
+ })
29
+ }
30
+ }
31
+
32
+ func TestSolution2 (t * testing.T ) {
33
+ // 测试用例
34
+ cases := []struct {
35
+ name string
36
+ inputs []int
37
+ expect int
38
+ }{
39
+ {"TestCase" , []int {2 , 2 , 1 }, 1 },
40
+ {"TestCase" , []int {4 , 1 , 2 , 1 , 2 }, 4 },
41
+ }
42
+
43
+ // 开始测试
44
+ for i , c := range cases {
45
+ t .Run (c .name + " " + strconv .Itoa (i ), func (t * testing.T ) {
46
+ got := singleNumber2 (c .inputs )
47
+ if ! reflect .DeepEqual (got , c .expect ) {
48
+ t .Fatalf ("expected: %v, but got: %v, with inputs: %v" ,
49
+ c .expect , got , c .inputs )
50
+ }
51
+ })
52
+ }
53
+ }
54
+
55
+ func TestSolution3 (t * testing.T ) {
56
+ // 测试用例
57
+ cases := []struct {
58
+ name string
59
+ inputs []int
60
+ expect int
61
+ }{
62
+ {"TestCase" , []int {2 , 2 , 1 }, 1 },
63
+ {"TestCase" , []int {4 , 1 , 2 , 1 , 2 }, 4 },
64
+ }
65
+
66
+ // 开始测试
67
+ for i , c := range cases {
68
+ t .Run (c .name + " " + strconv .Itoa (i ), func (t * testing.T ) {
69
+ got := singleNumber3 (c .inputs )
25
70
if ! reflect .DeepEqual (got , c .expect ) {
26
71
t .Fatalf ("expected: %v, but got: %v, with inputs: %v" ,
27
72
c .expect , got , c .inputs )
0 commit comments