underscore/flatmap_test.go
Ruidy c87f3f88b7 add flatmap
Signed-off-by: Ruidy <rnemausat@newstore.com>
2022-08-10 16:57:00 +02:00

16 lines
347 B
Go

package underscore_test
import (
"testing"
u "github.com/rjNemo/underscore"
"github.com/stretchr/testify/assert"
)
func TestFlatmap(t *testing.T) {
nums := []int{1, 2, 3, 4}
transform := func(n int) []int { return []int{(n - 1) * n, (n) * n} }
want := []int{0, 1, 2, 4, 6, 9, 12, 16}
assert.Equal(t, want, u.Flatmap(nums, transform))
}