From 169d0d10b0634a8d76444d2a45bd7b7fd2aa3ec0 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sat, 12 Jul 2025 06:57:39 -0700 Subject: Rewrite in Go --- words_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 words_test.go (limited to 'words_test.go') diff --git a/words_test.go b/words_test.go new file mode 100644 index 0000000..9c79464 --- /dev/null +++ b/words_test.go @@ -0,0 +1,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) + } +} -- cgit v1.3.1