-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathjaccard_test.go
57 lines (52 loc) · 1.78 KB
/
jaccard_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
package edlib
import (
"testing"
)
func TestJaccardSimilarity(t *testing.T) {
type args struct {
str1 string
str2 string
}
tests := []struct {
name string
args args
want float32
}{
{"Jaccard sim 1", args{"Radiohead", "Carly Rae Jepsen"}, 0.0},
{"Jaccard sim 2", args{"I love horror movies", "Lights out is a horror movie"}, 1.0 / 9.0},
{"Jaccard sim 3", args{"love horror movies", "Lights out horror movie"}, 1.0 / 6.0},
{"Jaccard sim 4", args{"私の名前はジョンです", "私の名前はジョン・ドゥです"}, 0.0},
{"Jaccard sim 5", args{"🙂😄🙂😄 😄🙂😄", "🙂😄🙂😄 😄🙂😄 🙂😄🙂"}, 2.0 / 3.0},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := JaccardSimilarity(tt.args.str1, tt.args.str2, 0); got != tt.want {
t.Errorf("JaccardSimilarity() = %v, want %v", got, tt.want)
}
})
}
}
func TestJaccardShingleSimilarity(t *testing.T) {
type args struct {
str1 string
str2 string
}
tests := []struct {
name string
args args
want float32
}{
{"Jaccard shingle sim 1", args{"Radiohead", "Carly Rae Jepsen"}, 0.04761905},
{"Jaccard shingle sim 2", args{"I love horror movies", "Lights out is a horror movie"}, 0.3548387},
{"Jaccard shingle sim 3", args{"love horror movies", "Lights out horror movie"}, 0.44},
{"Jaccard shingle sim 4", args{"私の名前はジョンです", "私の名前はジョン・ドゥです"}, 0.61538464},
{"Jaccard shingle sim 5", args{"🙂😄🙂😄 😄🙂😄", "🙂😄🙂😄 😄🙂😄 🙂😄🙂"}, 0.8},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := JaccardSimilarity(tt.args.str1, tt.args.str2, 2); got != tt.want {
t.Errorf("JaccardSimilarity() with shingle 2 = %v, want %v", got, tt.want)
}
})
}
}