-
Notifications
You must be signed in to change notification settings - Fork 0
/
jaro_winkler_test.go
48 lines (43 loc) · 1.36 KB
/
jaro_winkler_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package stringdist_test
import (
"math"
"testing"
"github.com/alextanhongpin/stringdist"
)
func TestJaroWinkler(t *testing.T) {
tests := []struct {
s1, s2 string
jaro, winkler float64
}{
{"SHACKLEFORD", "SHACKELFORD", 0.970, 0.982},
{"DUNNINGHAM", "CUNNIGHAM", 0.896, 0.896},
{"NICHLESON", "NICHULSON", 0.926, 0.956},
{"JONES", "JOHNSON", 0.790, 0.832},
{"MASSEY", "MASSIE", 0.889, 0.933},
{"ABROMS", "ABRAMS", 0.889, 0.922},
// {"HARDIN", "MARTINEZ", 0.000, 0.000},
{"HARDIN", "MARTINEZ", 0.722, 0.722},
// {"ITMAN", "SMITH", 0.622, 0.622},
{"ITMAN", "SMITH", 0.467, 0.467},
{"JERALDINE", "GERALDINE", 0.926, 0.926},
{"MARHTA", "MARTHA", 0.944, 0.961},
{"MICHELLE", "MICHAEL", 0.869, 0.921},
{"JULIES", "JULIUS", 0.889, 0.933},
{"TANYA", "TONYA", 0.867, 0.880},
{"DWAYNE", "DUANE", 0.822, 0.840},
{"SEAN", "SUSAN", 0.783, 0.805},
{"JON", "JOHN", 0.917, 0.933},
// {"JON", "JAN", 0.000, 0.000},
{"JON", "JAN", 0.778, 0.800},
}
for _, tt := range tests {
jaro := stringdist.Jaro(tt.s1, tt.s2)
winkler := stringdist.JaroWinkler(tt.s1, tt.s2)
if math.Round(jaro*1000)/1000 != tt.jaro {
t.Fatalf("expected jaro %f, got %f for %s and %s", tt.jaro, jaro, tt.s1, tt.s2)
}
if math.Round(winkler*1000)/1000 != tt.winkler {
t.Fatalf("expected winkler %f, got %f for %s and %s", tt.winkler, winkler, tt.s1, tt.s2)
}
}
}