-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathsolution_test.go
93 lines (85 loc) · 1.41 KB
/
solution_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"fmt"
"reflect"
"testing"
)
type TestItemInput struct {
head *ListNode
n int
}
type TestItem struct {
input TestItemInput
output *ListNode
}
func TestTask(t *testing.T) {
for i, v := range generateTasks() {
t.Run(fmt.Sprintf("Test %d", i+1), func(t *testing.T) {
res := removeNthFromEnd(v.input.head, v.input.n)
if !reflect.DeepEqual(res, v.output) {
t.Errorf("Wrong test.\nOutput: \n%v \nExpected: \n%v", getListView(res), getListView(v.output))
}
})
}
}
func generateTasks() []TestItem {
return []TestItem{
{
input: TestItemInput{head: &ListNode{
Val: 1,
Next: &ListNode{
Val: 2,
Next: &ListNode{
Val: 3,
Next: &ListNode{
Val: 4,
Next: &ListNode{
Val: 5,
Next: nil,
},
},
},
},
}, n: 2},
output: &ListNode{
Val: 1,
Next: &ListNode{
Val: 2,
Next: &ListNode{
Val: 3,
Next: &ListNode{
Val: 5,
Next: nil,
},
},
},
},
},
{
input: TestItemInput{head: &ListNode{
Val: 1,
Next: nil,
}, n: 1},
output: nil,
},
{
input: TestItemInput{head: &ListNode{
Val: 1,
Next: &ListNode{
Val: 2,
},
}, n: 1},
output: &ListNode{
Val: 1,
},
},
}
}
func getListView(node *ListNode) []int {
var res []int
for node != nil {
res = append(res, node.Val)
node = node.Next
}
return res
}