forked from awesee/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_element_test.go
More file actions
52 lines (48 loc) · 831 Bytes
/
remove_element_test.go
File metadata and controls
52 lines (48 loc) · 831 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package problem27
import (
"reflect"
"testing"
)
type testType struct {
in []int
val int
want []int
}
func TestRemoveElement(t *testing.T) {
tests := [...]testType{
{
in: []int{3, 2, 2, 3},
val: 3,
want: []int{2, 2},
},
{
in: []int{0, 1, 2, 2, 3, 0, 4, 2},
val: 2,
want: []int{0, 1, 3, 0, 4},
},
{
in: []int{1, 2, 3, 4, 5},
val: 6,
want: []int{1, 2, 3, 4, 5},
},
{
in: []int{1, 2, 2, 3, 3, 3, 4, 4, 4, 4},
val: 4,
want: []int{1, 2, 2, 3, 3, 3},
},
{
in: []int{},
val: 1,
want: []int{},
},
}
for _, tt := range tests {
nums := make([]int, len(tt.in))
copy(nums, tt.in)
l := removeElement(nums, tt.val)
got := nums[:l]
if !reflect.DeepEqual(got, tt.want) {
t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want)
}
}
}