-
Notifications
You must be signed in to change notification settings - Fork 2
/
searchRange_test.go
36 lines (32 loc) · 1.1 KB
/
searchRange_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
package searchforarange
import (
"testing"
"github.com/WindomZ/testify/assert"
)
func Test_searchRange(t *testing.T) {
assert.Equal(t, []int{-1, -1}, searchRange([]int{}, 0))
assert.Equal(t, []int{0, 0}, searchRange([]int{4}, 4))
assert.Equal(t, []int{1, 1}, searchRange([]int{4, 5}, 5))
assert.Equal(t, []int{2, 2}, searchRange([]int{4, 5, 6}, 6))
assert.Equal(t, []int{2, 3}, searchRange([]int{4, 5, 6, 6, 7}, 6))
assert.Equal(t, []int{4, 5}, searchRange([]int{4, 5, 6, 6, 7, 7, 8}, 7))
assert.Equal(t, []int{4, 6}, searchRange([]int{4, 5, 6, 6, 7, 7, 7, 8}, 7))
assert.Equal(t, []int{7, 8}, searchRange([]int{4, 5, 6, 6, 7, 7, 7, 8, 8}, 8))
}
func Benchmark_searchRange(b *testing.B) {
b.StopTimer()
b.ReportAllocs()
b.StartTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
searchRange([]int{}, 0)
searchRange([]int{4}, 4)
searchRange([]int{4, 5}, 5)
searchRange([]int{4, 5, 6}, 6)
searchRange([]int{4, 5, 6, 6, 7}, 6)
searchRange([]int{4, 5, 6, 6, 7, 7, 8}, 7)
searchRange([]int{4, 5, 6, 6, 7, 7, 7, 8}, 7)
searchRange([]int{4, 5, 6, 6, 7, 7, 7, 8, 8}, 8)
}
})
}