-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathproduct_test.go
42 lines (35 loc) · 981 Bytes
/
product_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package iterium
import (
"github.com/stretchr/testify/assert"
"strings"
"testing"
)
func TestProduct(t *testing.T) {
product := Product([]string{"A", "B", "C", "D"}, 2)
merged := Map(product, func(val []string) string {
return strings.Join(val, "")
})
if slice, err := merged.Slice(); assert.Nil(t, err) {
expected := []string{
"AA", "AB", "AC", "AD", "BA",
"BB", "BC", "BD", "CA", "CB",
"CC", "CD", "DA", "DB", "DC", "DD",
}
assert.Exactly(t, expected, slice)
assert.Exactly(t, int64(16), product.Count())
}
}
func TestProductInteger(t *testing.T) {
product := Product([]int{0, 1}, 2)
if slice, err := product.Slice(); assert.Nil(t, err) {
expected := [][]int{
{0, 0}, {0, 1}, {1, 0}, {1, 1},
}
assert.Exactly(t, expected, slice)
}
}
func TestProductCount(t *testing.T) {
assert.Exactly(t, int64(16), ProductCount(4, 2))
assert.Exactly(t, int64(1600), ProductCount(40, 2))
assert.Exactly(t, int64(20511149), ProductCount(29, 5))
}