-
Notifications
You must be signed in to change notification settings - Fork 0
/
anagrams_test.go
60 lines (49 loc) · 1.56 KB
/
anagrams_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package pkg
import (
"testing"
"strings"
// "fmt"
)
func AssertTrue(t *testing.T, condition bool, desc string) {
if !condition {
t.Error(desc)
}
}
func anagramMatchingSeed(anagram, seed string) bool {
if strings.Contains(strings.Join(anagrams(seed), "|"), anagram) {
return true
}
return false
}
func TestOneChar(t *testing.T) {
seed := "A"
AssertTrue(t, anagramMatchingSeed("A", seed), "")
seed = "B"
AssertTrue(t, anagramMatchingSeed("B", seed), "")
}
func TestTwoChars (t *testing.T) {
seed := "AB"
AssertTrue(t, anagramMatchingSeed("AB", seed), "")
AssertTrue(t, anagramMatchingSeed("BA", seed), "")
// fmt.Print(anagrams("ABC"))
seed = "BC"
AssertTrue(t, anagramMatchingSeed("BC", seed), "")
AssertTrue(t, anagramMatchingSeed("CB", seed), "")
seed = "YZ"
AssertTrue(t, anagramMatchingSeed("YZ", seed), "")
AssertTrue(t, anagramMatchingSeed("ZY", seed), "")
}
func TestThreeChars (t *testing.T) {
seed := "ABC"
// fmt.Print(anagrams("ABC"))
AssertTrue(t, anagramMatchingSeed("ABC", seed), "")
AssertTrue(t, anagramMatchingSeed("ACB", seed), "")
AssertTrue(t, anagramMatchingSeed("BAC", seed), "")
AssertTrue(t, anagramMatchingSeed("BCA", seed), "")
seed = "ABCD"
//fmt.Print(anagrams(seed))
AssertTrue(t, anagramMatchingSeed("ABCD", seed), "")
AssertTrue(t, anagramMatchingSeed("ACBD", seed), "")
AssertTrue(t, anagramMatchingSeed("BACD", seed), "")
AssertTrue(t, anagramMatchingSeed("BCDA", seed), "")
}