package shadow import "testing" func TestPhonemeToShadow(t *testing.T) { tests := []struct { name string phonemes string want string }{ {"cat", "K AE1 T", "KA'T"}, {"dog", "D AO1 G", "DO'G"}, {"fish", "F IH1 SH", "FI'Σ"}, {"thin", "TH IH1 N", "ΘI'N"}, {"the", "DH AH0", "ÐA"}, {"moon", "M UW1 N", "MU'N"}, {"ring", "R IH1 NG", "RI'Ŋ"}, {"church", "CH ER1 CH", "ЧR'Ч"}, {"measure", "M EH1 ZH ER0", "ME'Ζ̌R"}, {"judge", "JH AH1 JH", "ЏA'Џ"}, {"queen", "K W IY1 N", "KWI'N"}, {"box", "B AA1 K S", "BA'KS"}, {"boy", "B OY1", "BOY'"}, {"day", "D EY1", "DEY'"}, {"cow", "K AW1", "KAU'"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := phonemesToShadow(tt.phonemes) if got != tt.want { t.Errorf("phonemesToShadow(%q) = %q, want %q", tt.phonemes, got, tt.want) } }) } } func TestLoadAndLookup(t *testing.T) { d, err := LoadEnglishDict() if err != nil { t.Fatalf("LoadEnglishDict: %v", err) } if d.Size() < 100000 { t.Errorf("dict size = %d, expected > 100000", d.Size()) } // Spot-check some words checks := []struct { word string ok bool }{ {"the", true}, {"cat", true}, {"hello", true}, {"xyzzyplugh", false}, } for _, c := range checks { _, found := d.Lookup(c.word) if found != c.ok { t.Errorf("Lookup(%q) found=%v, want %v", c.word, found, c.ok) } } } func TestFromEnglish(t *testing.T) { d, err := LoadEnglishDict() if err != nil { t.Fatalf("LoadEnglishDict: %v", err) } // Test full sentence transliteration got := d.FromEnglish("the cat") // "the" = DH AH0 = ÐA // "cat" = K AE1 T = KA'T want := "ÐA KA'T" if got != want { t.Errorf("FromEnglish(\"the cat\") = %q, want %q", got, want) } }