-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
64 lines (59 loc) · 1.46 KB
/
main_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
61
62
63
64
package main
import (
"reflect"
"testing"
)
func TestIsAnagram(t *testing.T) {
testCases := []struct {
input1 string
input2 string
expectedResult bool
description string
}{
{
description: "case senstive anagram strings",
input1: "Listen",
input2: "Silent",
expectedResult: false,
}, {
description: "simple anagrams",
input1: "triangle",
input2: "integral",
expectedResult: true,
}, {
description: "invalid anagrams",
input1: "aavvbbccd",
input2: "dffeed",
expectedResult: false,
},
}
for _, tC := range testCases {
t.Run(tC.description, func(t *testing.T) {
actual := isAnagram(tC.input1, tC.input2)
if actual != tC.expectedResult {
t.Fatalf("Input1 %s, Input2 %s | expected %v got %v", tC.input1, tC.input2, tC.expectedResult, actual)
}
})
}
}
func TestGetChracterOccurenceMapFromString(t *testing.T) {
testCases := []struct {
input string
occurence map[string]int
description string
}{
{
description: "case 1",
input: "Listened",
occurence: map[string]int{"L": 1, "i": 1, "s": 1, "t": 1, "e": 2, "n": 1, "d": 1},
},
}
for _, tC := range testCases {
t.Run(tC.description, func(t *testing.T) {
actual := getChracterOccurenceMapFromString(tC.input)
if !reflect.DeepEqual(actual, tC.occurence) {
t.Fatalf("Input %s | expected %v got %v", tC.input, tC.occurence, actual)
}
})
}
}