- Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2.addTwoNumbers_test.go
40 lines (36 loc) · 846 Bytes
/
2.addTwoNumbers_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
package linkedList
import (
"reflect"
"testing"
"Leetcode/algorithms/kit"
)
// run: go test -v base.go 2.*
funcTest_addTwoNumbers(t*testing.T) {
cases:= []struct {
namestring
input [][]int
expected []int
}{
{
name: "x1",
input: [][]int{{2, 4, 3}, {5, 6, 4}},
expected: []int{7, 0, 8},
},
{
name: "x2",
input: [][]int{{9, 9, 9, 9, 9, 9, 9}, {9, 9, 9, 9}},
expected: []int{8, 9, 9, 9, 0, 0, 0, 1},
},
}
for_, tt:=rangecases {
t.Run(tt.name, func(t*testing.T) {
l1:=kit.Ints2List(tt.input[0])
l2:=kit.Ints2List(tt.input[1])
output:=addTwoNumbers(l1, l2)
out2ints:=kit.List2Ints(output)
if!reflect.DeepEqual(out2ints, tt.expected) {
t.Errorf("addTwoNumbers(%v, %v)=%v, expected=%v", tt.input[0], tt.input[1], out2ints, tt.expected)
}
})
}
}