-
Notifications
You must be signed in to change notification settings - Fork 0
/
dictionary_test.go
62 lines (54 loc) · 1.19 KB
/
dictionary_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
package main
import (
_ "embed"
"strings"
"testing"
)
//go:embed dictionary/test-dictionary
var dictFile string
func contains(s []string, str string) bool {
for _, v := range s {
if v == str {
return true
}
}
return false
}
func assertTrue(t *testing.T, value bool) {
if !value {
t.Error()
}
}
func assertFalse(t *testing.T, value bool) {
if value {
t.Error()
}
}
func TestNewDictionaryFromPathFiltersOutShortWords(t *testing.T) {
d, err := NewDictionaryFromReader(strings.NewReader(dictFile))
if err != nil {
t.Error(err)
}
words := d.Words()
assertTrue(t, contains(words, "dogs"))
assertFalse(t, contains(words, "cat"))
}
func TestNewDictionaryFromStringRemovesDuplicates(t *testing.T) {
d, err := NewDictionaryFromReader(strings.NewReader("dogs\ndogs\ndogs\n"))
if err != nil {
t.Error(err)
}
words := d.Words()
assertTrue(t, contains(words, "dogs"))
if len(words) != 1 {
t.Errorf("Expected 1 word, got %d. Words: %s", len(words), words)
}
}
func TestNewDictionaryFromStringNormalizesAccents(t *testing.T) {
d, err := NewDictionaryFromReader(strings.NewReader(dictFile))
if err != nil {
t.Error(err)
}
words := d.Words()
assertTrue(t, contains(words, "eclair"))
}