-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathintersection_of_two_linked_lists_test.go
59 lines (55 loc) · 1.16 KB
/
intersection_of_two_linked_lists_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
package problem160
import (
"testing"
"github.com/awesee/leetcode/internal/kit"
)
type testType struct {
headA []int
headB []int
intersection []int
}
func TestGetIntersectionNode(t *testing.T) {
tests := [...]testType{
{
headA: []int{4, 1},
headB: []int{5, 0, 1},
intersection: []int{8, 4, 5},
},
{
headA: []int{0, 9, 1, 2},
headB: []int{3},
intersection: []int{2, 4},
},
{
headA: []int{2, 4, 6},
headB: []int{1, 5},
intersection: []int{},
},
{
headA: []int{1},
headB: []int{},
intersection: []int{},
},
}
for _, tt := range tests {
intersection := kit.SliceInt2ListNode(tt.intersection)
headA := kit.SliceInt2ListNode(tt.headA)
headB := kit.SliceInt2ListNode(tt.headB)
for n := headA; n != nil; n = n.Next {
if n.Next == nil {
n.Next = intersection
break
}
}
for n := headB; n != nil; n = n.Next {
if n.Next == nil {
n.Next = intersection
break
}
}
got := getIntersectionNode(headA, headB)
if got != intersection {
t.Fatalf("in: %v, got: %v %v, want: %v", tt.headA, tt.headB, got, tt.intersection)
}
}
}