mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-15 18:22:27 +08:00
test: add test and example for DropWhile
This commit is contained in:
@@ -504,6 +504,29 @@ func ExampleDropRight() {
|
|||||||
// []
|
// []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleDropWhile() {
|
||||||
|
numbers := []int{1, 2, 3, 4, 5}
|
||||||
|
|
||||||
|
result1 := DropWhile(numbers, func(n int) bool {
|
||||||
|
return n != 2
|
||||||
|
})
|
||||||
|
result2 := DropWhile(numbers, func(n int) bool {
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
result3 := DropWhile(numbers, func(n int) bool {
|
||||||
|
return n == 0
|
||||||
|
})
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
fmt.Println(result3)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// [2 3 4 5]
|
||||||
|
// []
|
||||||
|
// [1 2 3 4 5]
|
||||||
|
}
|
||||||
|
|
||||||
func ExampleInsertAt() {
|
func ExampleInsertAt() {
|
||||||
result1 := InsertAt([]string{"a", "b", "c"}, 0, "1")
|
result1 := InsertAt([]string{"a", "b", "c"}, 0, "1")
|
||||||
result2 := InsertAt([]string{"a", "b", "c"}, 1, "1")
|
result2 := InsertAt([]string{"a", "b", "c"}, 1, "1")
|
||||||
|
|||||||
@@ -377,7 +377,7 @@ func TestDeleteAt(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDrop(t *testing.T) {
|
func TestDrop(t *testing.T) {
|
||||||
assert := internal.NewAssert(t, "TestInterfaceSlice")
|
assert := internal.NewAssert(t, "TestDrop")
|
||||||
|
|
||||||
assert.Equal([]int{}, Drop([]int{}, 0))
|
assert.Equal([]int{}, Drop([]int{}, 0))
|
||||||
assert.Equal([]int{}, Drop([]int{}, 1))
|
assert.Equal([]int{}, Drop([]int{}, 1))
|
||||||
@@ -392,7 +392,7 @@ func TestDrop(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDropRight(t *testing.T) {
|
func TestDropRight(t *testing.T) {
|
||||||
assert := internal.NewAssert(t, "TestInterfaceSlice")
|
assert := internal.NewAssert(t, "TestDropRight")
|
||||||
|
|
||||||
assert.Equal([]int{}, DropRight([]int{}, 0))
|
assert.Equal([]int{}, DropRight([]int{}, 0))
|
||||||
assert.Equal([]int{}, DropRight([]int{}, 1))
|
assert.Equal([]int{}, DropRight([]int{}, 1))
|
||||||
@@ -406,6 +406,27 @@ func TestDropRight(t *testing.T) {
|
|||||||
assert.Equal([]int{1, 2, 3, 4, 5}, DropRight([]int{1, 2, 3, 4, 5}, -1))
|
assert.Equal([]int{1, 2, 3, 4, 5}, DropRight([]int{1, 2, 3, 4, 5}, -1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDropWhile(t *testing.T) {
|
||||||
|
assert := internal.NewAssert(t, "TestDropWhile")
|
||||||
|
|
||||||
|
numbers := []int{1, 2, 3, 4, 5}
|
||||||
|
|
||||||
|
r1 := DropWhile(numbers, func(n int) bool {
|
||||||
|
return n != 2
|
||||||
|
})
|
||||||
|
assert.Equal([]int{2, 3, 4, 5}, r1)
|
||||||
|
|
||||||
|
r2 := DropWhile(numbers, func(n int) bool {
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
assert.Equal([]int{}, r2)
|
||||||
|
|
||||||
|
r3 := DropWhile(numbers, func(n int) bool {
|
||||||
|
return n == 0
|
||||||
|
})
|
||||||
|
assert.Equal([]int{1, 2, 3, 4, 5}, r3)
|
||||||
|
}
|
||||||
|
|
||||||
func TestInsertAt(t *testing.T) {
|
func TestInsertAt(t *testing.T) {
|
||||||
assert := internal.NewAssert(t, "TestInsertAt")
|
assert := internal.NewAssert(t, "TestInsertAt")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user