summaryrefslogtreecommitdiff
path: root/go/mixed-server_test.go
blob: c7e3624b195a27a6008aa4e704f999eaa8b0cfad (plain)
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
package main
 
import (
"testing"
)
 
func eq_slice(t *testing.T, got []WordAndCount, expected []string) {
if !(len(got)==len(expected)) {
t.Errorf("bad length, got %d expected %d",len(got),len(expected))
return
}
for i,got_elem := range got {
if !(got_elem.word == expected[i]) {
t.Errorf("slices differ at %d, got %v expected %v",
i,got_elem,expected[i])
return
}
}
return
}
 
func TestModel1(t *testing.T) {
m := NewModel()
m.AddWords([]string{"a", "b", "a"})
got := m.GetMostCommonPairs(2)
eq_slice(t,got,[]string{"a","b"})
}
 
func TestModel2(t *testing.T) {
m := NewModel()
m.AddWords([]string{"a", "b", "a"})
 
got := m.GetMostCommonPairs(2)
eq_slice(t,got,[]string{"a","b"})
 
m.AddWords([]string{"b", "c", "b"})
got = m.GetMostCommonPairs(2)
eq_slice(t,got,[]string{"b","a"})
}