-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdropwhile_test.go
More file actions
55 lines (44 loc) · 1.39 KB
/
dropwhile_test.go
File metadata and controls
55 lines (44 loc) · 1.39 KB
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
package underscore_test
import (
"testing"
"github.com/stretchr/testify/assert"
u "github.com/rjNemo/underscore"
)
func TestDropWhile(t *testing.T) {
nums := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
result := u.DropWhile(nums, func(n int) bool { return n < 5 })
assert.Equal(t, []int{5, 6, 7, 8, 9}, result)
}
func TestDropWhileEmpty(t *testing.T) {
result := u.DropWhile([]int{}, func(n int) bool { return n < 5 })
assert.Equal(t, []int{}, result)
}
func TestDropWhileNoneMatch(t *testing.T) {
nums := []int{5, 6, 7, 8, 9}
result := u.DropWhile(nums, func(n int) bool { return n < 5 })
assert.Equal(t, []int{5, 6, 7, 8, 9}, result)
}
func TestDropWhileAllMatch(t *testing.T) {
nums := []int{1, 2, 3, 4}
result := u.DropWhile(nums, func(n int) bool { return n < 10 })
assert.Equal(t, []int{}, result)
}
func TestDropWhileSingleElement(t *testing.T) {
result := u.DropWhile([]int{5}, func(n int) bool { return n < 10 })
assert.Equal(t, []int{}, result)
}
func TestDropWhileStrings(t *testing.T) {
words := []string{"apple", "banana", "cherry", "date"}
result := u.DropWhile(words, func(s string) bool { return len(s) < 6 })
assert.Equal(t, []string{"banana", "cherry", "date"}, result)
}
func BenchmarkDropWhile(b *testing.B) {
nums := make([]int, 1000)
for i := range nums {
nums[i] = i
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
u.DropWhile(nums, func(n int) bool { return n < 500 })
}
}