-
Notifications
You must be signed in to change notification settings - Fork 0
/
matchRatingApproach_test.go
103 lines (93 loc) · 1.57 KB
/
matchRatingApproach_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
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
101
102
103
package textdistance
import (
"fmt"
"math"
"testing"
)
const floatThreshold = 0.0000000001
func TestMRA_Minimum(t *testing.T) {
tests := []struct {
in [2]string
want float64
}{
{
in: [2]string{"Byrne", "Boern"},
want: 4,
},
{
in: [2]string{"Smith ", "Smyth"},
want: 3,
},
// TODO Reimplement
// {
// in: [2]string{"Catherine ", "Kathryn"},
// want: 3,
// },
}
for _, tt := range tests {
t.Run(fmt.Sprintf("%s & %s", tt.in[0], tt.in[1]), func(t *testing.T) {
mra := NewMRA()
got, err := mra.Minimum(tt.in[0], tt.in[1])
if math.Abs(got-tt.want) > floatThreshold {
t.Errorf("want %f, got %f", tt.want, got)
}
if err != nil {
t.Errorf("expect empty error, got %+v", err)
}
})
}
}
func TestMRA_Encoding(t *testing.T) {
tests := []struct {
in string
want string
}{
{
in: "Byrne",
want: "BYRN",
},
{
in: "Boern",
want: "BRN",
},
{
in: "Smith",
want: "SMTH",
},
{
in: "Smyth",
want: "SMYTH",
},
{
in: "Catherine",
want: "CTHRN",
},
{
in: "Kathryn",
want: "KTHRYN",
},
}
for _, tt := range tests {
t.Run(tt.in, func(t *testing.T) {
mra := NewMRA()
got, err := mra.Encoding(tt.in)
if got != tt.want {
t.Errorf("want %s, got %s", tt.want, got)
}
if err != nil {
t.Errorf("expect empty error, got %+v", err)
}
})
}
}
func BenchmarkMRA_Encoding(b *testing.B) {
const in = "boern"
mra := NewMRA()
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, err := mra.Encoding(in)
if err != nil {
b.Fatal(err)
}
}
}