-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatn_test.go
More file actions
62 lines (49 loc) · 949 Bytes
/
atn_test.go
File metadata and controls
62 lines (49 loc) · 949 Bytes
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
package main
import "testing"
func TestCase1(t *testing.T) {
l1 := &ListNode{Val: 9}
l2 := &ListNode{Val: 9}
t1, t2 := l1, l2
for _, v := range []int{9, 9, 9, 9, 9, 9} {
t1 = insert(t1, v)
}
for _, v := range []int{9, 9, 9} {
t2 = insert(t2, v)
}
ans := addTwoNumbers(l1, l2)
trueAns, i := []int{8, 9, 9, 9, 0, 0, 0, 1}, 0
for ; ans != nil; ans = ans.Next {
if ans.Val != trueAns[i] {
t.Error("Wrong Answer!")
return
}
i++
if i >= len(trueAns) {
break
}
}
if ans != nil && ans.Next != nil {
t.Error("Wrong Answer!")
return
}
}
func TestCase2(t *testing.T) {
l1 := &ListNode{Val: 0}
l2 := &ListNode{Val: 0}
ans := addTwoNumbers(l1, l2)
trueAns, i := []int{0}, 0
for ; ans != nil; ans = ans.Next {
if ans.Val != trueAns[i] {
t.Error("Wrong Answer!")
return
}
i++
if i >= len(trueAns) {
break
}
}
if ans != nil && ans.Next != nil {
t.Error("Wrong Answer!")
return
}
}