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
|
package main
import (
"strings"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestBuildNGrams(t *testing.T) {
const testWordList = `abc
abd
def
`
got, err := buildNGrams(strings.NewReader(testWordList))
if err != nil {
t.Fatalf("buildNGrams failed: %s", err)
}
want := map[biGram][]choice{
{-1, -1}: {{'a', 2}, {'d', 3}},
{-1, 'a'}: {{'b', 2}},
{-1, 'd'}: {{'e', 1}},
{'a', 'b'}: {{'c', 1}, {'d', 2}},
{'b', 'c'}: {{-1, 1}},
{'b', 'd'}: {{-1, 1}},
{'d', 'e'}: {{'f', 1}},
{'e', 'f'}: {{-1, 1}},
}
if diff := cmp.Diff(want, got, cmp.AllowUnexported(biGram{}, choice{})); diff != "" {
t.Errorf("buildNGrams(%q) returned unexpected diff (-want +got):\n%s", testWordList, diff)
}
}
|