1
0
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:
dudaodong
2022-03-21 15:29:10 +08:00
parent 3ae4a35d04
commit 50ef63e27d
2 changed files with 34 additions and 0 deletions

View File

@@ -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 {