test: slice 包新增部分单元测试
This commit is contained in:
parent
7a5e2c1e7e
commit
4982e6d7b6
|
@ -0,0 +1,35 @@
|
||||||
|
package slice_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/kercylan98/minotaur/utils/slice"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestChunk(t *testing.T) {
|
||||||
|
var collection = []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
|
||||||
|
var chunks = slice.Chunk(collection, 3)
|
||||||
|
for _, chunk := range chunks {
|
||||||
|
t.Log(chunk)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExampleChunk() {
|
||||||
|
var collection = []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
|
||||||
|
var chunks = slice.Chunk(collection, 3)
|
||||||
|
for _, chunk := range chunks {
|
||||||
|
fmt.Println(chunk)
|
||||||
|
}
|
||||||
|
// Output:
|
||||||
|
// [1 2 3]
|
||||||
|
// [4 5 6]
|
||||||
|
// [7 8 9]
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkChunk(b *testing.B) {
|
||||||
|
var collection = []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
slice.Chunk(collection, 3)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package slice_test
|
package slice_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/kercylan98/minotaur/utils/slice"
|
"github.com/kercylan98/minotaur/utils/slice"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -9,3 +10,17 @@ func TestDrop(t *testing.T) {
|
||||||
s := []int{1, 2, 3, 4, 5}
|
s := []int{1, 2, 3, 4, 5}
|
||||||
t.Log(s, slice.Drop(1, 3, s))
|
t.Log(s, slice.Drop(1, 3, s))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleDrop() {
|
||||||
|
fmt.Println(slice.Drop(1, 3, []int{1, 2, 3, 4, 5}))
|
||||||
|
// Output:
|
||||||
|
// [1 5]
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkDrop(b *testing.B) {
|
||||||
|
s := []int{1, 2, 3, 4, 5}
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
slice.Drop(1, 3, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue