diff options
author | Gianni Ceccarelli <gianni.ceccarelli@broadbean.com> | 2019-08-01 13:10:03 +0100 |
---|---|---|
committer | Gianni Ceccarelli <gianni.ceccarelli@broadbean.com> | 2019-08-01 13:10:03 +0100 |
commit | 6710227fe39b5d9ae0c635d875b0c4d02b4a23e8 (patch) | |
tree | bdeb8feca109d2ab86facb9ebef183302035352b | |
parent | go model (diff) | |
download | mixed-server-6710227fe39b5d9ae0c635d875b0c4d02b4a23e8.tar.gz mixed-server-6710227fe39b5d9ae0c635d875b0c4d02b4a23e8.tar.bz2 mixed-server-6710227fe39b5d9ae0c635d875b0c4d02b4a23e8.zip |
more tests
-rw-r--r-- | go/mixed-server_test.go | 29 |
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"}) } |