mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-08 06:32:28 +08:00
feat: add GroupWith func
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package slice
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
|
||||
"github.com/duke-git/lancet/v2/internal"
|
||||
@@ -142,6 +143,20 @@ func TestGroupBy(t *testing.T) {
|
||||
assert.Equal(expectedOdd, odd)
|
||||
}
|
||||
|
||||
func TestGroupWith(t *testing.T) {
|
||||
nums := []float64{6.1, 4.2, 6.3}
|
||||
floor := func(num float64) float64 {
|
||||
return math.Floor(num)
|
||||
}
|
||||
expected := map[float64][]float64{
|
||||
4: {4.2},
|
||||
6: {6.1, 6.3},
|
||||
}
|
||||
actual := GroupWith(nums, floor)
|
||||
assert := internal.NewAssert(t, "TestGroupWith")
|
||||
assert.Equal(expected, actual)
|
||||
}
|
||||
|
||||
func TestCount(t *testing.T) {
|
||||
nums := []int{1, 2, 3, 4, 5, 6}
|
||||
evenFunc := func(i, num int) bool {
|
||||
|
||||
Reference in New Issue
Block a user