-
Notifications
You must be signed in to change notification settings - Fork 0
/
dicesorensenmetric_test.go
50 lines (44 loc) · 1.09 KB
/
dicesorensenmetric_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
/*
* Copyright (c) 2020 Engin Yöyen.
* Use of this source code is governed by an MIT
* license that can be found in the LICENSE file.
*/
package strmetric
import (
"math"
"testing"
)
func TestDiceSorensonMetric(t *testing.T) {
var testCases = []struct {
a string
b string
similarity float64
}{
{"identical strings", "identical strings", 1.00},
{"ACCESSARY", "ACCESSORY", 0.75},
{"world", "arlon", 0.25},
{"night", "nacht", 0.25},
}
for _, test := range testCases {
similarity, _ := DiceSorensonMetric(test.a, test.b)
if similarity != test.similarity {
t.Errorf("Expected %f, got %f, for inputs: %s & %s", test.similarity, similarity, test.a, test.b)
}
}
}
func TestDiceSorensonMetricError(t *testing.T) {
var testCases = []struct {
a string
b string
similarity float64
}{
{"", "", math.NaN()},
{"", "ac", math.NaN()},
}
for _, test := range testCases {
similarity, err := DiceSorensonMetric(test.a, test.b)
if err == nil {
t.Errorf("Expected error on empty strings but got similatiry result as %f", similarity)
}
}
}