-
Notifications
You must be signed in to change notification settings - Fork 62
/
string_permutations_test.go
34 lines (29 loc) · 898 Bytes
/
string_permutations_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
package queue
import (
"reflect"
"testing"
)
/*
TestStringPermutations tests solution(s) with the following signature and problem description:
func StringPermutations(input string) []string
Given a string like "abc", return all possible permutations like "abc,acb,bac,bca,cab,cba" using
a queue.
*/
func TestStringPermutations(t *testing.T) {
tests := []struct {
input string
permutations []string
}{
{"", []string{""}},
{"a", []string{"a"}},
{"ab", []string{"ab", "ba"}},
{"ba", []string{"ba", "ab"}},
{"abc", []string{"abc", "acb", "bac", "bca", "cab", "cba"}},
{"123", []string{"123", "132", "213", "231", "312", "321"}},
}
for i, test := range tests {
if got := StringPermutations(test.input); !reflect.DeepEqual(got, test.permutations) {
t.Fatalf("Failed test #%d, Failed getting list of maximums. Want %#v got %#v", i, test.permutations, got)
}
}
}