-
Notifications
You must be signed in to change notification settings - Fork 0
/
words_test.go
79 lines (66 loc) · 1.52 KB
/
words_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package txt
import (
"testing"
)
func TestReadTime(t *testing.T) {
words := map[string]int{
"": 10,
}
for k, v := range words {
if ReadTime(k) != v {
t.Fatalf("'%s' read time not equal to %v", k, v)
}
}
}
func TestWords(t *testing.T) {
examples := []string{
"The quick brown fox jumped over the sly dog",
"the-rest-of-the-word",
"This contains two sentences. This is the second!",
}
words := [][]string{
{"The", "quick", "brown", "fox", "jumped", "over", "the", "sly", "dog"},
{"the", "rest", "of", "the", "word"},
{"This", "contains", "two", "sentences", "This", "is", "the", "second"},
}
for idx, v := range examples {
for index, word := range Words(v) {
if words[idx][index] != word {
t.Fatalf("expected %v, got %v", words[idx][index], word)
}
}
}
}
func TestWordOffsets(t *testing.T) {
examples := []string{
"The quick brown fox",
}
words := [][]int{
{0, 4, 10, 16},
}
for idx, v := range examples {
for index, word := range WordOffsets(v) {
if words[idx][index] != word.Offset {
t.Fatalf("expected %v, got %v", words[idx][index], word)
}
}
}
}
func TestWordFrequency(t *testing.T) {
examples := []string{
"The quick brown fox ran over the slow gray fox.",
}
words := [][]string{
{"the", "fox", "ran"},
}
freqs := [][]uint{
{2, 2, 1},
}
for idx, v := range examples {
for index, word := range words[idx] {
if WordFrequency(v, word) != freqs[idx][index] {
t.Fatalf("expected %v, got %v", freqs[idx][index], WordFrequency(v, word))
}
}
}
}