package spell import "testing" func TestSuggestReturnsClosestWord(t *testing.T) { d := loadT(t) got := d.Suggest("recieve", 5) if len(got) == 0 { t.Fatal("Suggest(recieve) returned nothing") } if !contains(got, "receive") { t.Errorf("Suggest(recieve) = %v, want it to include \"receive\"", got) } } func TestSuggestRanksByDistanceThenFrequency(t *testing.T) { d := loadT(t) // "teh" is one edit from "the" (most common word) and from "ten"/"tea"/etc. // The most frequent close word should rank first. got := d.Suggest("teh", 5) if len(got) == 0 { t.Fatal("Suggest(teh) returned nothing") } if got[0] != "the" { t.Errorf("Suggest(teh)[0] = %q, want \"the\" (closest + most frequent)", got[0]) } } func TestSuggestCapsResults(t *testing.T) { d := loadT(t) got := d.Suggest("seperate", 3) if len(got) > 3 { t.Errorf("Suggest with max=3 returned %d results", len(got)) } if !contains(got, "separate") { t.Errorf("Suggest(seperate) = %v, want it to include \"separate\"", got) } } func contains(xs []string, s string) bool { for _, x := range xs { if x == s { return true } } return false }