forked from avito-tech/normalize
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmp_test.go
More file actions
100 lines (97 loc) · 2.31 KB
/
cmp_test.go
File metadata and controls
100 lines (97 loc) · 2.31 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package normalize_test
import (
"testing"
"github.com/avito-tech/normalize"
)
func Test_areStringsSimilar(t *testing.T) {
tests := []struct {
name string
one string
other string
threshold float64
normalizers []normalize.Option
want bool
}{
{
name: "same_strings_must_be_similar",
one: "hello",
other: "hello",
want: true,
},
{
name: "non_normalized_strings_distance",
one: "hella",
other: "hello",
want: false,
},
{
name: "non_normalized_strings_distance_with_threshold",
one: "hella",
other: "hello",
threshold: 0.25,
want: true,
},
{
name: "non_normalized_strings_distance_with_threshold",
one: "hela",
other: "hello",
threshold: 0.25,
want: false,
},
{
name: "non_normalized_stringds_of_different_length",
one: "hell",
other: "hello",
threshold: 0.34,
want: true,
},
{
name: "non_normalized_stringds_of_different_length_flipped",
one: "hello",
other: "hell",
threshold: 0.34,
want: true,
},
{
name: "non_normalized_strings_of_different_length_flipped",
one: "hello",
other: "hell",
threshold: 0.34,
want: true,
},
{
name: "normalized_strings",
one: "A b",
other: "АВ", // all cyrillic
want: true,
},
{
name: "normalized_strings_with_threshold",
one: "AB-test",
other: "АВ тест", // all cyrillic
threshold: 0.17,
want: true,
},
{
name: "normalized_strings_with_custom_options",
one: "AB",
other: "АВ", // all cyrillic
normalizers: []normalize.Option{normalize.WithLowerCase()}, // no cyr2lat
want: false,
},
{
name: "normalized_strings_with_custom_options",
one: "AB",
other: "АВ", // all cyrillic
normalizers: []normalize.Option{normalize.WithLowerCase(), normalize.WithCyrillicToLatinLookAlike()},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := normalize.AreStringsSimilar(tt.one, tt.other, tt.threshold, tt.normalizers...); got != tt.want {
t.Errorf("AreStringsSimilar() = %v, want %v", got, tt.want)
}
})
}
}