-
Notifications
You must be signed in to change notification settings - Fork 0
/
levenshtein_test.go
83 lines (72 loc) · 1.34 KB
/
levenshtein_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
package textdistance
import (
"fmt"
"testing"
)
func TestLevenshtein_Minimum(t *testing.T) {
t.Parallel()
tts := []struct {
ins [2]string
want float64
}{
{
ins: [2]string{"heath", "heath"},
want: 0,
},
{
ins: [2]string{"dresser", "d"},
want: 6,
},
{
ins: [2]string{"d", "dresser"},
want: 6,
},
}
for _, tt := range tts {
t.Run(fmt.Sprintf("%s", tt.ins), func(t *testing.T) {
l := NewLevenshtein()
got, err := l.Minimum(tt.ins[0], tt.ins[1])
if got != tt.want {
t.Errorf("got %f, want %f", got, tt.want)
}
if err != nil {
t.Errorf("expect empty error, got %+v", err)
}
})
}
}
func TestLevenshtein_Distance(t *testing.T) {
t.Parallel()
tts := []struct {
ins [2]string
want float64
}{
{
ins: [2]string{"flaw", "lawn"},
want: 2,
},
}
for _, tt := range tts {
t.Run(fmt.Sprintf("%s", tt.ins), func(t *testing.T) {
l := NewLevenshtein()
got, err := l.Distance(tt.ins[0], tt.ins[1])
if got != tt.want {
t.Errorf("got %f, want %f", got, tt.want)
}
if err != nil {
t.Errorf("expect empty error, got %+v", err)
}
})
}
}
func BenchmarkLevenshtein_Distance(b *testing.B) {
const s1, s2 = "flaw", "lawn"
l := NewLevenshtein()
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, err := l.Distance(s1, s2)
if err != nil {
b.Fatal(err)
}
}
}