test: slice 包新增部分单元测试

This commit is contained in:
kercylan98 2023-09-11 14:50:27 +08:00
parent 7a5e2c1e7e
commit 4982e6d7b6
2 changed files with 50 additions and 0 deletions

35
utils/slice/chunk_test.go Normal file
View File

@ -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)
}
}

View File

@ -1,6 +1,7 @@
package slice_test
import (
"fmt"
"github.com/kercylan98/minotaur/utils/slice"
"testing"
)
@ -9,3 +10,17 @@ func TestDrop(t *testing.T) {
s := []int{1, 2, 3, 4, 5}
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)
}
}