-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathword_counter_test.go
More file actions
65 lines (53 loc) · 1.28 KB
/
word_counter_test.go
File metadata and controls
65 lines (53 loc) · 1.28 KB
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
package stats
import (
"fmt"
"testing"
)
func TestTokenCounter_Word(t *testing.T) {
t.Parallel()
tc := NewWordCounter()
if len(tc.Top) != 0 {
t.Error("Top tokens should be empty.")
}
if len(tc.All) != 0 {
t.Error("All tokens should be empty.")
}
m := &Message{Message: "foo bar bar baz"}
tc.addMessage(m)
if len(tc.Top) != 3 {
t.Error("Top tokens should have three unique tokens.")
}
if len(tc.All) != 3 {
t.Error("All tokens should have three unique tokens.")
}
if count, ok := tc.All["foo"]; !ok {
t.Error("Should have foo in All tokens.")
} else if count != 1 {
t.Error("Should get correct count for token.")
}
if count, ok := tc.All["bar"]; !ok {
t.Error("Should have bar in All tokens.")
} else if count != 2 {
t.Error("Should get correct count for token.")
}
if tok := tc.Top[0]; tok.Token != "bar" || tok.Count != 2 {
t.Error("Top token is incorrect")
}
tc = NewWordCounter()
for i := 'a'; i < 'z'; i++ {
url := fmt.Sprintf("foo%c", i)
m := &Message{Message: url}
tc.addMessage(m)
url = fmt.Sprintf("bar%c", i)
m = &Message{Message: url}
tc.addMessage(m)
url = fmt.Sprintf("baz%c", i)
m = &Message{Message: url}
tc.addMessage(m)
}
for _, v := range tc.Top {
if v.Count != uint(1) {
t.Error("Count is incorrect. ")
}
}
}