1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-08 22:52:29 +08:00

feat: add Partition for slice

This commit is contained in:
dudaodong
2023-09-04 11:30:50 +08:00
parent 4037b96cc4
commit 541e6d4ea3
3 changed files with 59 additions and 2 deletions

View File

@@ -1175,3 +1175,13 @@ func TestJoin(t *testing.T) {
assert.Equal("1,2,3,4,5", result1)
assert.Equal("1-2-3-4-5", result2)
}
func TestPartition(t *testing.T) {
t.Parallel()
assert := internal.NewAssert(t, "TestPartition")
assert.Equal([][]int{{1, 2, 3, 4, 5}}, Partition([]int{1, 2, 3, 4, 5}))
assert.Equal([][]int{{2, 4}, {1, 3, 5}}, Partition([]int{1, 2, 3, 4, 5}, func(n int) bool { return n%2 == 0 }))
assert.Equal([][]int{{1, 2}, {3, 4}, {5}}, Partition([]int{1, 2, 3, 4, 5}, func(n int) bool { return n == 1 || n == 2 }, func(n int) bool { return n == 2 || n == 3 || n == 4 }))
}