Permutation library using Go 1.18's generics
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
955 B

package permutation
import (
"testing"
)
func TestPermutations(t *testing.T) {
testCases := []struct {
name string
seed []int
permsExpected int
}{
{
"basic",
[]int{1, 2, 3},
6,
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
perms := Permutations(testCase.seed)
if len(perms) != testCase.permsExpected {
t.Errorf("len(perms) == %d, expected %d", len(perms), testCase.permsExpected)
}
})
}
}
func TestPermutationsAllSizes(t *testing.T) {
testCases := []struct {
name string
seed []int
permsExpected int
}{
{
"3 ints",
[]int{1, 2, 3},
15,
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
perms := PermutationsAllSizes(testCase.seed)
if len(perms) != testCase.permsExpected {
t.Errorf("len(perms) == %d, expected %d", len(perms), testCase.permsExpected)
}
})
}
}