forked from spring1843/go-dsa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoin_sorted_lists_test.go
More file actions
36 lines (31 loc) · 942 Bytes
/
join_sorted_lists_test.go
File metadata and controls
36 lines (31 loc) · 942 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
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.
*/
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(Unserialize(test.list1), Unserialize(test.list2)))
if got != test.joined {
t.Fatalf("Failed test case #%d. Want %s got %s", i, test.joined, got)
}
}
}