-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathjaro_test.go
61 lines (58 loc) · 1.63 KB
/
jaro_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
49
50
51
52
53
54
55
56
57
58
59
60
61
package edlib
import (
"testing"
)
func TestJaroSimilarity(t *testing.T) {
type args struct {
str1 string
str2 string
}
tests := []struct {
name string
args args
want float32
}{
{"First arg empty", args{"", "abcde"}, 0.0},
{"Second arg empty", args{"abcde", ""}, 0.0},
{"Same args", args{"abcde", "abcde"}, 1.0},
{"No characters match", args{"abcd", "effgghh"}, 0.0},
{"CRATE/TRACE", args{"CRATE", "TRACE"}, 0.73333335},
{"MARTHA/MARHTA", args{"MARTHA", "MARHTA"}, 0.9444444},
{"DIXON/DICKSONX", args{"DIXON", "DICKSONX"}, 0.76666665},
{"jellyfish/smellyfish", args{"jellyfish", "smellyfish"}, 0.8962963},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := JaroSimilarity(tt.args.str1, tt.args.str2); got != tt.want {
t.Errorf("JaroSimilarity() = %v, want %v", got, tt.want)
}
})
}
}
func TestJaroWinklerSimilarity(t *testing.T) {
type args struct {
str1 string
str2 string
}
tests := []struct {
name string
args args
want float32
}{
{"First arg empty", args{"", "abcde"}, 0.0},
{"Second arg empty", args{"abcde", ""}, 0.0},
{"Same args", args{"abcde", "abcde"}, 1.0},
{"No characters match", args{"abcd", "effgghh"}, 0.0},
{"TRACE/TRACE", args{"TRACE", "TRACE"}, 1.0},
{"CRATE/TRACE", args{"CRATE", "TRACE"}, 0.73333335},
{"TRATE/TRACE", args{"TRATE", "TRACE"}, 0.90666664},
{"DIXON/DICKSONX", args{"DIXON", "DICKSONX"}, 0.81333333},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := JaroWinklerSimilarity(tt.args.str1, tt.args.str2); got != tt.want {
t.Errorf("JaroWinklerSimilarity() = %v, want %v", got, tt.want)
}
})
}
}