- Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path237.deleteNode_test.go
54 lines (49 loc) · 955 Bytes
/
237.deleteNode_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
package linkedList
import (
"reflect"
"testing"
"Leetcode/algorithms/kit"
)
type (
entry237struct {
namestring
inputentry237input
expected []int
}
entry237inputstruct {
ints []int
valint
}
)
// run: go test -v base.go 237.*
funcTest_deleteNode(t*testing.T) {
cases:= []entry237{
{
name: "x1",
input: entry237input{
ints: []int{4, 5, 1, 9},
val: 5,
},
expected: []int{4, 1, 9},
},
{
name: "x2",
input: entry237input{
ints: []int{4, 5, 1, 9},
val: 1,
},
expected: []int{4, 5, 9},
},
}
for_, tt:=rangecases {
t.Run(tt.name, func(t*testing.T) {
head:=kit.Ints2List(tt.input.ints)
node:=head.GetNodeWith(tt.input.val)
deleteNode(node)
output:=kit.List2Ints(head)
if!reflect.DeepEqual(output, tt.expected) {
t.Errorf("origin Link=%v after deleteNode(%d)=%v, expected=%v", tt.input.ints, tt.input.val, output, tt.expected)
}
})
}
}