-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathtrigrams_test.go
54 lines (46 loc) · 1.35 KB
/
trigrams_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
package whatlanggo
import "testing"
func TestCount(t *testing.T) {
tests := map[string]map[string]int{
"": {"": 0},
",": {"": 0},
"a": {" a ": 1},
"-a-": {" a ": 1},
"yes": {" ye": 1, "yes": 1, "es ": 1},
"Give - IT...": {" gi": 1, "giv": 1, "ive": 1, "ve ": 1, " it": 1, "it ": 1},
}
for key, value := range tests {
got := count(key)
for key1, value1 := range value {
if got[key1] != value1 {
t.Fatalf("%s got %d want %d", key1, got[key1], value1)
}
}
}
}
func TestToTrigramChar(t *testing.T) {
tests := map[rune]rune{
'a': 'a', 'z': 'z', 'A': 'A', 'Z': 'Z', 'Ж': 'Ж', 'ß': 'ß',
//punctuation, digits, ... etc
'\t': ' ', '\n': ' ', ' ': ' ', '.': ' ', '0': ' ', '9': ' ', ',': ' ', '@': ' ',
'[': ' ', ']': ' ', '^': ' ', '\\': ' ', '`': ' ', '|': ' ', '{': ' ', '}': ' ', '~': ' '}
for r, want := range tests {
got := toTrigramChar(r)
if got != want {
t.Fatalf("%q got %q want %q", r, got, want)
}
}
}
func TestGetTrigramsWithPositions(t *testing.T) {
tests := map[string]map[string]int{
"xaaaaabbbbd": {"aaa": 0, "bbb": 1},
}
for key, value := range tests {
got := getTrigramsWithPositions(key)
for trigram, position := range value {
if got[trigram] != position {
t.Fatalf("%s : want %d got %d", trigram, position, got[trigram])
}
}
}
}