-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathkeep_repetitions_test.go
More file actions
37 lines (31 loc) · 958 Bytes
/
keep_repetitions_test.go
File metadata and controls
37 lines (31 loc) · 958 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
package linkedlist
import "testing"
/*
TestKeepRepetitions tests solution(s) with the following signature and problem description:
func KeepRepetitions(head *Node) *Node
Given a linked list of sorted integers, create a copy of the list that contains one example of
each repeated item.
For example given 1->1->4->4->6->6->7, return 1->4->6 because
1,4,6 are items that are repeated in this list and 7 is not repeated.
*/
func TestKeepRepetitions(t *testing.T) {
tests := []struct {
list, solution string
}{
{"", ""},
{"1", ""},
{"1->1", "1"},
{"1->4->6", ""},
{"1->4->4->4->6", "4"},
{"1->1->4->4->4->6", "1->4"},
{"1->1->4->4->4->6->6", "1->4->6"},
{"1->1->4->4->6->6->7", "1->4->6"},
{"1->1->4->4->4->6->7->7", "1->4->7"},
}
for i, test := range tests {
got := Serialize(KeepRepetitions(Deserialize(test.list)))
if got != test.solution {
t.Fatalf("Failed test case #%d. Want %s got %s", i, test.solution, got)
}
}
}