english_test.go raw
1 package shadow
2
3 import "testing"
4
5 func TestPhonemeToShadow(t *testing.T) {
6 tests := []struct {
7 name string
8 phonemes string
9 want string
10 }{
11 {"cat", "K AE1 T", "KA'T"},
12 {"dog", "D AO1 G", "DO'G"},
13 {"fish", "F IH1 SH", "FI'Σ"},
14 {"thin", "TH IH1 N", "ΘI'N"},
15 {"the", "DH AH0", "ÐA"},
16 {"moon", "M UW1 N", "MU'N"},
17 {"ring", "R IH1 NG", "RI'Ŋ"},
18 {"church", "CH ER1 CH", "ЧR'Ч"},
19 {"measure", "M EH1 ZH ER0", "ME'Ζ̌R"},
20 {"judge", "JH AH1 JH", "ЏA'Џ"},
21 {"queen", "K W IY1 N", "KWI'N"},
22 {"box", "B AA1 K S", "BA'KS"},
23 {"boy", "B OY1", "BOY'"},
24 {"day", "D EY1", "DEY'"},
25 {"cow", "K AW1", "KAU'"},
26 }
27
28 for _, tt := range tests {
29 t.Run(tt.name, func(t *testing.T) {
30 got := phonemesToShadow(tt.phonemes)
31 if got != tt.want {
32 t.Errorf("phonemesToShadow(%q) = %q, want %q", tt.phonemes, got, tt.want)
33 }
34 })
35 }
36 }
37
38 func TestLoadAndLookup(t *testing.T) {
39 d, err := LoadEnglishDict()
40 if err != nil {
41 t.Fatalf("LoadEnglishDict: %v", err)
42 }
43
44 if d.Size() < 100000 {
45 t.Errorf("dict size = %d, expected > 100000", d.Size())
46 }
47
48 // Spot-check some words
49 checks := []struct {
50 word string
51 ok bool
52 }{
53 {"the", true},
54 {"cat", true},
55 {"hello", true},
56 {"xyzzyplugh", false},
57 }
58
59 for _, c := range checks {
60 _, found := d.Lookup(c.word)
61 if found != c.ok {
62 t.Errorf("Lookup(%q) found=%v, want %v", c.word, found, c.ok)
63 }
64 }
65 }
66
67 func TestFromEnglish(t *testing.T) {
68 d, err := LoadEnglishDict()
69 if err != nil {
70 t.Fatalf("LoadEnglishDict: %v", err)
71 }
72
73 // Test full sentence transliteration
74 got := d.FromEnglish("the cat")
75 // "the" = DH AH0 = ÐA
76 // "cat" = K AE1 T = KA'T
77 want := "ÐA KA'T"
78 if got != want {
79 t.Errorf("FromEnglish(\"the cat\") = %q, want %q", got, want)
80 }
81 }
82