3 changed files with 83 additions and 17 deletions
@ -0,0 +1,2 @@
@@ -0,0 +1,2 @@
|
||||
golang.org/x/exp v0.0.0-20221031165847-c99f073a8326 h1:QfTh0HpN6hlw6D3vu8DAwC8pBIwikq0AI1evdm+FksE= |
||||
golang.org/x/exp v0.0.0-20221031165847-c99f073a8326/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= |
@ -1,12 +1,51 @@
@@ -1,12 +1,51 @@
|
||||
package permutation |
||||
|
||||
import ( |
||||
"fmt" |
||||
"testing" |
||||
) |
||||
|
||||
func Test(t *testing.T) { |
||||
a := []int{1, 2, 3, 4} |
||||
p := Permutations(a) |
||||
fmt.Println(p) |
||||
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) |
||||
} |
||||
}) |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue