-
Notifications
You must be signed in to change notification settings - Fork 1
/
index_test.go
72 lines (67 loc) · 1.59 KB
/
index_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
65
66
67
68
69
70
71
72
package gnlp_test
import (
"fmt"
"math"
"testing"
"github.com/shota3506/gnlp"
)
func TestJaccardIndex(t *testing.T) {
for i, tc := range []struct {
a []rune
b []rune
expected float64
}{
{[]rune(""), []rune(""), 1},
{[]rune("a"), []rune(""), 0},
{[]rune("a"), []rune("a"), 1},
{[]rune("ab"), []rune("a"), 0.5},
{[]rune("abc"), []rune("aa"), 1.0 / 3.0},
} {
t.Run(fmt.Sprintf("test case %d", i), func(t *testing.T) {
d := gnlp.JaccardIndex(tc.a, tc.b)
if math.Abs(tc.expected-d) > 1e-9 {
t.Errorf("epected: %f, actual: %f", tc.expected, d)
}
})
}
}
func TestDiceIndex(t *testing.T) {
for i, tc := range []struct {
a []rune
b []rune
expected float64
}{
{[]rune(""), []rune(""), 1},
{[]rune("a"), []rune(""), 0},
{[]rune("a"), []rune("a"), 1},
{[]rune("ab"), []rune("a"), 2.0 / 3.0},
{[]rune("aba"), []rune("ac"), 0.5},
} {
t.Run(fmt.Sprintf("test case %d", i), func(t *testing.T) {
d := gnlp.DiceIndex(tc.a, tc.b)
if math.Abs(tc.expected-d) > 1e-9 {
t.Errorf("epected: %f, actual: %f", tc.expected, d)
}
})
}
}
func TestSimpsonIndex(t *testing.T) {
for i, tc := range []struct {
a []rune
b []rune
expected float64
}{
{[]rune(""), []rune(""), 1},
{[]rune("a"), []rune(""), 1},
{[]rune("a"), []rune("a"), 1},
{[]rune("ab"), []rune("a"), 1},
{[]rune("aba"), []rune("ac"), 0.5},
} {
t.Run(fmt.Sprintf("test case %d", i), func(t *testing.T) {
d := gnlp.SimpsonIndex(tc.a, tc.b)
if math.Abs(tc.expected-d) > 1e-9 {
t.Errorf("epected: %f, actual: %f", tc.expected, d)
}
})
}
}