-
Notifications
You must be signed in to change notification settings - Fork 0
/
combinatorics_test.go
46 lines (35 loc) · 1.03 KB
/
combinatorics_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
package generics_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zeroflucs-given/generics"
)
func TestCombinations(t *testing.T) {
// Arrange
input := []string{"a", "b", "c", "d"}
// Act
output := generics.Combinations(input, 2)
// Assert
assert.Len(t, output, 6, "Should have correct number of combinations")
}
func TestCombinationsSize(t *testing.T) {
// Arrange
input := []string{"a", "b", "c"}
// Act
output := generics.Combinations(input, 4)
// Assert
require.Nil(t, output)
}
func TestCombinationsFiltered(t *testing.T) {
// Arrange
input := []string{"a", "b", "c", "d"}
// Act
output := generics.CombinationsFiltered(input, 2, func(i int, v string) bool {
return i%2 == 0 // Only include even indexes
})
// Assert
assert.Len(t, output, 1, "Should have correct number of combinations")
assert.Equal(t, generics.IndexedItem[string]{Index: 0, Item: "a"}, output[0][0])
assert.Equal(t, generics.IndexedItem[string]{Index: 2, Item: "c"}, output[0][1])
}