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:
@@ -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 }))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user