-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjaccard_test.go
More file actions
48 lines (40 loc) · 801 Bytes
/
jaccard_test.go
File metadata and controls
48 lines (40 loc) · 801 Bytes
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
package textdistance
import (
"fmt"
"testing"
)
func TestJaccard_Similarity(t *testing.T) {
t.Parallel()
tts := []struct {
ins [2]string
want float64
}{
{
ins: [2]string{"c h", "a b c d e f g h"},
want: 0.25,
},
}
for _, tt := range tts {
t.Run(fmt.Sprintf("%s, %s", tt.ins[0], tt.ins[1]), func(t *testing.T) {
j := NewJaccard()
got, err := j.Similarity(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 BenchmarkJaccard_Similarity(b *testing.B) {
const s1, s2 = "c h", "a b c d e f g h"
j := NewJaccard()
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, err := j.Similarity(s1, s2)
if err != nil {
b.Fatal(err)
}
}
}