MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / TestCombinations

Function TestCombinations

math/binomialcoefficient_test.go:14–37  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestCombinations(t *testing.T) {
15 var tests = []struct {
16 name string
17 n int
18 k int
19 expectedValue int
20 expectedError error
21 }{
22 {"n = 5, k = 2", 5, 2, 10, nil},
23 {"n = 7, k = 4", 7, 4, 35, nil},
24 {"n = 0, k = 0", 0, 0, 1, nil},
25 {"n = -1, k = 1", -1, 1, -1, math.ErrPosArgsOnly},
26 {"n = 1, k = -1", 1, -1, -1, math.ErrPosArgsOnly},
27 {"n = -1, k = -1", -1, -1, -1, math.ErrPosArgsOnly},
28 }
29 for _, test := range tests {
30 t.Run(test.name, func(t *testing.T) {
31 result, err := math.Combinations(test.n, test.k)
32 if result != test.expectedValue || test.expectedError != err {
33 t.Errorf("expected error: %s, got: %s; expected value: %v, got: %v", test.expectedError, err, test.expectedValue, result)
34 }
35 })
36 }
37}
38func BenchmarkCombinations(b *testing.B) {
39 for i := 0; i < b.N; i++ {
40 _, _ = math.Combinations(65536, 65536)

Callers

nothing calls this directly

Calls 1

CombinationsFunction · 0.92

Tested by

no test coverage detected