-
Notifications
You must be signed in to change notification settings - Fork 0
/
overlap_test.go
60 lines (53 loc) · 997 Bytes
/
overlap_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
package textdistance
import (
"fmt"
"math"
"testing"
)
func TestOverlap_Similarity(t *testing.T) {
t.Parallel()
tests := []struct {
in [2]string
want float64
}{
{
in: [2]string{"a b", "a b c d"},
want: 1,
},
{
in: [2]string{"a b c d", "a b"},
want: 1,
},
{
in: [2]string{"a b c d", "e f"},
want: 0,
},
{
in: [2]string{"a b e g", "e f"},
want: 0.5,
},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("%s & %s", tt.in[0], tt.in[1]), func(t *testing.T) {
o := NewOverlap()
got, err := o.Similarity(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 BenchmarkOverlap_Similarity(b *testing.B) {
const in1, in2 = "a b e g", "e f"
o := NewOverlap()
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, err := o.Similarity(in1, in2)
if err != nil {
b.Fatal(err)
}
}
}