-
Notifications
You must be signed in to change notification settings - Fork 2
/
strsim_test.go
64 lines (56 loc) · 1.39 KB
/
strsim_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
package strsim
import (
"reflect"
"testing"
)
func TestCompare(t *testing.T) {
for _, test := range testCases1 {
observed := Compare(test.a, test.b)
if observed != test.expected {
t.Fatalf("Compare(%s, %s) = %f, want %f",
test.a, test.b, observed, test.expected)
}
}
}
func TestFindBestMatch(t *testing.T) {
for _, test := range testCases2 {
observed, err := FindBestMatch(test.s, test.targets)
if err != nil && err.Error() != test.err.Error() {
t.Fatalf("Unexpected error from FindBestMatch: %v", err)
}
if !reflect.DeepEqual(observed, test.expected) {
t.Fatalf("FindBestMatch(%s, %v) = %+v, want %+v", test.s, test.targets, observed, test.expected)
}
}
}
func TestSortedByScore(t *testing.T) {
for _, test := range testCases3 {
observed := test.actual
observed.SortedByScore()
if !reflect.DeepEqual(observed, test.expected) {
t.Fatalf("SortedByScore() = %+v, want %+v", observed, test.expected)
}
}
}
func BenchmarkCompare(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, test := range testCases1 {
Compare(test.a, test.b)
}
}
}
func BenchmarkFindBestMatch(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, test := range testCases2 {
FindBestMatch(test.s, test.targets)
}
}
}
func BenchmarkSortedByScore(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, test := range testCases3 {
observed := test.actual
observed.SortedByScore()
}
}
}