-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgorithm_test.go
More file actions
72 lines (55 loc) · 1.29 KB
/
algorithm_test.go
File metadata and controls
72 lines (55 loc) · 1.29 KB
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
package algorithm
import (
"reflect"
"testing"
)
func TestFindIndexesForSum(t *testing.T) {
if !reflect.DeepEqual(findIndexesForSum([]int{1, 2}, 3), []int{0, 1}) {
t.Fatal("fail")
}
if !reflect.DeepEqual(findIndexesForSum([]int{3, 2, 4}, 6), []int{1, 2}) {
t.Fatal("fail")
}
}
func TestAddTwoListNode(t *testing.T) {
listNode := addTwoListNode(&ListNode{3, nil}, &ListNode{2, nil})
if listNode.Val != 5 {
t.Fatal("fail")
}
listNodeAppend := addTwoListNode(&ListNode{5, nil}, &ListNode{5, nil})
if listNodeAppend.Val != 0 {
t.Fatal("fail")
}
if listNodeAppend.Next.Val != 1 {
t.Fatal("fail")
}
listNodeDifferentLength := addTwoListNode(
&ListNode{3, &ListNode{7, &ListNode{5, nil}}},
&ListNode{5, nil},
)
if listNodeDifferentLength.Val != 8 {
t.Fatal("fail")
}
if listNodeDifferentLength.Next.Val != 7 {
t.Fatal("fail")
}
if listNodeDifferentLength.Next.Next.Val != 5 {
t.Fatal("fail")
}
listNodeNested := addTwoListNode(
&ListNode{2, &ListNode{8, &ListNode{9, nil}}},
&ListNode{3, &ListNode{9, &ListNode{9, nil}}},
)
if listNodeNested.Val != 5 {
t.Fatal("fail")
}
if listNodeNested.Next.Val != 7 {
t.Fatal("fail")
}
if listNodeNested.Next.Next.Val != 9 {
t.Fatal("fail")
}
if listNodeNested.Next.Next.Next.Val != 1 {
t.Fatal("fail")
}
}