summaryrefslogtreecommitdiff
path: root/go/mixed-server_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/mixed-server_test.go')
-rw-r--r--go/mixed-server_test.go29
1 files changed, 22 insertions, 7 deletions
diff --git a/go/mixed-server_test.go b/go/mixed-server_test.go
index 6e33b1f..63e545b 100644
--- a/go/mixed-server_test.go
+++ b/go/mixed-server_test.go
@@ -4,21 +4,36 @@ import (
"testing"
)
+func eq_slice(t *testing.T, got, 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 == 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)
- if !(got[0] == "a" && got[1] == "b") {
- t.Errorf("bad order, got %v", got)
- }
+ eq_slice(t,got,[]string{"a","b"})
}
func TestModel2(t *testing.T) {
m := NewModel()
m.AddWords([]string{"a", "b", "a"})
- m.AddWords([]string{"b", "c", "b"})
+
got := m.GetMostCommonPairs(2)
- if !(got[0] == "b" && got[1] == "a") {
- t.Errorf("bad order, got %v", got)
- }
+ eq_slice(t,got,[]string{"a","b"})
+
+ m.AddWords([]string{"b", "c", "b"})
+ got = m.GetMostCommonPairs(2)
+ eq_slice(t,got,[]string{"b","a"})
}