-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpull_test.go
112 lines (103 loc) · 2.05 KB
/
pull_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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package slices
import (
"fmt"
"strconv"
"testing"
"github.com/golodash/godash/generals"
"github.com/golodash/godash/internal"
)
type TPull struct {
name string
arr interface{}
rems interface{}
want interface{}
}
var tPullBenchs = []TPull{
{
name: "10",
arr: []int{},
rems: []int{},
},
{
name: "100",
arr: []int{},
rems: []int{},
},
{
name: "1000",
arr: []int{},
rems: []int{},
},
{
name: "10000",
arr: []int{},
rems: []int{},
},
{
name: "100000",
arr: []int{},
rems: []int{},
},
}
func init() {
for j := 0; j < len(tPullBenchs); j++ {
length, _ := strconv.Atoi(tPullBenchs[j].name)
for i := 0; i < length/10; i++ {
tPullBenchs[j].arr = append(tPullBenchs[j].arr.([]int), []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}...)
tPullBenchs[j].rems = append(tPullBenchs[j].rems.([]int), (i+1)*10, 1+((i+1)*10), 2+((i+1)*10), 3+((i+1)*10), 4+((i+1)*10), 5+((i+1)*10))
}
}
}
func TestPull(t *testing.T) {
var tests = []TPull{
{
name: "nil",
arr: nil,
rems: nil,
want: nil,
},
{
name: "empty",
arr: []int{},
rems: []int{},
want: []int{},
},
{
name: "normal",
arr: []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
rems: []int{0, 1, 2},
want: []int{3, 4, 5, 6, 7, 8, 9},
},
{
name: "shuffle",
arr: []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
rems: []int{0, 4, 9, 4, 9, 0},
want: []int{1, 2, 3, 5, 6, 7, 8},
},
{
name: "all remove",
arr: []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
rems: []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
want: []int{},
},
}
for _, subject := range tests {
t.Run(subject.name, func(t *testing.T) {
defer internal.DeferTestCases(t, subject.want)
got := Pull(subject.arr, subject.rems)
if !generals.Same(got, subject.want) {
t.Errorf("got = %v, wanted = %v", got, subject.want)
return
}
})
}
}
func BenchmarkPull(b *testing.B) {
for j := 0; j < len(tPullBenchs); j++ {
b.Run(fmt.Sprintf("slice_size_%s", tPullBenchs[j].name), func(b *testing.B) {
for i := 0; i < b.N; i++ {
Pull(tPullBenchs[j].arr, tPullBenchs[j].rems)
}
})
}
}