-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathjoin_sorted_lists_test.go
36 lines (30 loc) · 1008 Bytes
/
join_sorted_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
package linkedlist
import "testing"
/*
TestJoinTwoSortedLinkedLists tests solution(s) with the following signature and problem description:
func JoinTwoSortedLinkedLists(l1, l2 *Node) *Node
Given two sorted linked lists of integers, merge them into one sorted linked list.
For example given 1->4->6 and 2->3->5->7, return 1->2->3->4->5->6->7.
*/
func TestJoinTwoSortedLinkedLists(t *testing.T) {
tests := []struct {
list1, list2, joined string
}{
{"", "", ""},
{"1", "", "1"},
{"", "1", "1"},
{"1", "2", "1->2"},
{"1", "2->3", "1->2->3"},
{"1->3", "2", "1->2->3"},
{"1->4->6", "2->3->5->7", "1->2->3->4->5->6->7"},
{"1->4->5->6", "2->3->7", "1->2->3->4->5->6->7"},
{"1->2", "1->2->3", "1->1->2->2->3"},
{"1->4", "2->3->7", "1->2->3->4->7"},
}
for i, test := range tests {
got := Serialize(JoinTwoSortedLinkedLists(Deserialize(test.list1), Deserialize(test.list2)))
if got != test.joined {
t.Fatalf("Failed test case #%d. Want %s got %s", i, test.joined, got)
}
}
}