From 4982e6d7b691c16b634d6d79c1cf5119eaf89524 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Mon, 11 Sep 2023 14:50:27 +0800 Subject: [PATCH] =?UTF-8?q?test:=20slice=20=E5=8C=85=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/slice/chunk_test.go | 35 +++++++++++++++++++++++++++++++++++ utils/slice/drop_test.go | 15 +++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 utils/slice/chunk_test.go diff --git a/utils/slice/chunk_test.go b/utils/slice/chunk_test.go new file mode 100644 index 0000000..334fdbe --- /dev/null +++ b/utils/slice/chunk_test.go @@ -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) + } +} diff --git a/utils/slice/drop_test.go b/utils/slice/drop_test.go index 33fbe0d..a4c1aa1 100644 --- a/utils/slice/drop_test.go +++ b/utils/slice/drop_test.go @@ -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) + } +}