Files
timmy-config/go/pkg/mod/fiatjaf.com/lib@v0.2.0/combinations/lib_test.go
2026-03-31 20:02:01 +00:00

42 lines
1.1 KiB
Go

package combinations
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestCombinations(t *testing.T) {
{
base := []string{"1", "2"}
require.ElementsMatch(t, [][]string{{"1"}, {"2"}}, Combinations(base, 1))
require.ElementsMatch(t, [][]string{{"1", "2"}}, Combinations(base, 2))
}
{
base := []int{1, 2, 3}
require.ElementsMatch(t, [][]int{{1}, {2}, {3}}, Combinations(base, 1))
require.ElementsMatch(t, [][]int{{1, 2}, {1, 3}, {2, 3}}, Combinations(base, 2))
require.ElementsMatch(t, [][]int{{1, 2, 3}}, Combinations(base, 3))
}
{
base := []int{1, 2, 3, 4}
require.ElementsMatch(t, [][]int{{1}, {2}, {3}, {4}}, Combinations(base, 1))
require.ElementsMatch(t, [][]int{{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4}}, Combinations(base, 2))
require.ElementsMatch(t, [][]int{{1, 2, 3}, {1, 3, 4}, {2, 3, 4}, {1, 2, 4}}, Combinations(base, 3))
require.ElementsMatch(t, [][]int{{1, 2, 3, 4}}, Combinations(base, 4))
}
for n := 0; n < 21; n++ {
arr := make([]int, n)
for i, v := range arr {
arr[i] = v
}
for r := n; r > 0; r-- {
require.Len(t, Combinations(arr, r), resultSize(n, r), "comb(%d)")
}
}
}