-
Notifications
You must be signed in to change notification settings - Fork 0
/
sorensendice_test.go
60 lines (57 loc) · 1.27 KB
/
sorensendice_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 stringmetric
import (
"testing"
)
// TODO all tests are bigrams, should test for other values as well
var sorensenDiceMetricTests = []struct {
title string
N int
s1 string
s2 string
expected float64
}{
{
title: "should return no similarity if s1 is empty",
N: 1,
s1: "",
s2: "hello",
expected: float64(0),
},
{
title: "should return no similarity if s2 is empty",
N: 1,
s1: "hello",
s2: "",
expected: float64(0),
},
{
title: "should return full similarity if s1 and s2 have the same elements",
N: 2,
s1: "hello",
s2: "hello",
expected: float64(1),
},
{
title: "should compute similarity with words with punctuation",
N: 2,
s1: "night!",
s2: "natch?",
expected: float64(0),
},
{
title: "should compute similarity for accented words",
N: 2,
s1: "résumé",
s2: "resumé",
expected: float64(0.6),
},
}
func TestSorensenDiceMetric(t *testing.T) {
for _, test := range sorensenDiceMetricTests {
t.Log(test.title)
result := SorensenDiceMetric(test.N, test.s1, test.s2)
if result != test.expected {
t.Errorf("result doesn't match, expected %v, got: %v", test.expected, result)
}
}
}