-
Notifications
You must be signed in to change notification settings - Fork 2
/
searchInsert_test.go
38 lines (34 loc) · 1.16 KB
/
searchInsert_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
package searchinsertposition
import (
"testing"
"github.com/WindomZ/testify/assert"
)
func Test_searchInsert(t *testing.T) {
assert.Equal(t, 0, searchInsert([]int{}, 0))
assert.Equal(t, 0, searchInsert([]int{4}, 4))
assert.Equal(t, 1, searchInsert([]int{4, 5}, 5))
assert.Equal(t, 2, searchInsert([]int{4, 5, 6}, 6))
assert.Equal(t, 0, searchInsert([]int{0, 1, 2, 4, 5, 6, 7}, 0))
assert.Equal(t, 1, searchInsert([]int{0, 1, 2, 4, 5, 6, 7}, 1))
assert.Equal(t, 2, searchInsert([]int{0, 1, 2, 4, 5, 6, 7}, 2))
assert.Equal(t, 3, searchInsert([]int{0, 1, 2, 4, 5, 6, 7}, 3))
assert.Equal(t, 6, searchInsert([]int{0, 1, 2, 4, 5, 6, 7}, 7))
assert.Equal(t, 7, searchInsert([]int{0, 1, 2, 4, 5, 6, 7}, 8))
}
func Benchmark_searchInsert(b *testing.B) {
b.StopTimer()
b.ReportAllocs()
b.StartTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
searchInsert([]int{}, 0)
searchInsert([]int{4}, 4)
searchInsert([]int{4, 5}, 5)
searchInsert([]int{4, 5, 6}, 6)
searchInsert([]int{0, 1, 2, 4, 5, 6, 7}, 2)
searchInsert([]int{0, 1, 2, 4, 5, 6, 7}, 3)
searchInsert([]int{0, 1, 2, 4, 5, 6, 7}, 7)
searchInsert([]int{0, 1, 2, 4, 5, 6, 7}, 8)
}
})
}