mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package linguistics
|
|
|
|
import "testing"
|
|
|
|
func TestPhoneticEncoder_Soundex(t *testing.T) {
|
|
e := NewPhoneticEncoder()
|
|
cases := map[string]string{
|
|
"Robert": "R163",
|
|
"Ashcraft": "A261",
|
|
}
|
|
for in, want := range cases {
|
|
got := e.Encode(in)
|
|
if got != want {
|
|
t.Errorf("Encode(%q) = %q; want %q", in, got, want)
|
|
}
|
|
}
|
|
// property checks
|
|
if got := e.Encode("P"); got != "P000" {
|
|
t.Errorf("Encode(P) = %q; want P000", got)
|
|
}
|
|
}
|
|
|
|
func TestPhoneticEncoder_DoubleMetaphoneVariation(t *testing.T) {
|
|
e := NewPhoneticEncoder()
|
|
p, s := e.DoubleMetaphone("Robert")
|
|
if p != "R163" {
|
|
t.Fatalf("primary code = %q; want R163", p)
|
|
}
|
|
if s == p || len(s) != len(p) {
|
|
t.Errorf("secondary variation should differ but have same length: p=%q s=%q", p, s)
|
|
}
|
|
}
|
|
|
|
func TestPhoneticEncoder_Empty(t *testing.T) {
|
|
e := NewPhoneticEncoder()
|
|
if got := e.Encode(""); got != "" {
|
|
t.Errorf("Encode(\"\") = %q; want empty", got)
|
|
}
|
|
p, s := e.DoubleMetaphone("")
|
|
if p != "" || s != "" {
|
|
t.Errorf("DoubleMetaphone(\"\") = (%q,%q); want empty codes", p, s)
|
|
}
|
|
}
|