underscore/groupby_test.go
2022-04-20 22:23:59 +02:00

22 lines
361 B
Go

package underscore_test
import (
"math"
"testing"
"github.com/stretchr/testify/assert"
u "github.com/rjNemo/underscore"
)
func TestGroupBy(t *testing.T) {
nums := []float64{1.3, 2.1, 2.4}
want := map[int][]float64{
1: {1.3},
2: {2.1, 2.4},
}
f := func(n float64) int {
return int(math.Floor(n))
}
assert.Equal(t, want, u.GroupBy(nums, f))
}