-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitertools_test.go
47 lines (42 loc) · 968 Bytes
/
itertools_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
43
44
45
46
47
package godino
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCombinations(t *testing.T) {
arr := []int{1, 2, 3}
combos := Combinations(arr, 2)
comboArr := GeneratorToArray(combos)
expected := [][]int{{1, 2}, {1, 3}, {2, 3}}
assert.Equal(t, expected, comboArr)
}
func TestPermutations(t *testing.T) {
t.Run("permutations of the entire array", func(t *testing.T) {
arr := []int{1, 2, 3}
perms := Permutations(arr, -1)
permArry := GeneratorToArray(perms)
expected := [][]int{
{1, 2, 3},
{1, 3, 2},
{2, 1, 3},
{2, 3, 1},
{3, 2, 1},
{3, 1, 2},
}
assert.ElementsMatch(t, expected, permArry)
})
t.Run("permutations of a length less than the array", func(t *testing.T) {
arr := []int{1, 2, 3}
perms := Permutations(arr, 2)
permArry := GeneratorToArray(perms)
expected := [][]int{
{1, 2},
{1, 3},
{2, 1},
{2, 3},
{3, 2},
{3, 1},
}
assert.ElementsMatch(t, expected, permArry)
})
}