-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcases_test.go
118 lines (114 loc) · 3.32 KB
/
cases_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package strsim
import "fmt"
var testCases1 = []struct {
a string
b string
expected float64
}{
{"french", "quebec", 0},
{"france", "france", 1},
{"fRaNce", "france", 0.2},
{"healed", "sealed", 0.8},
{"web applications", "applications of the web", 0.7878787878787878},
{"this will have a typo somewhere", "this will huve a typo somewhere", 0.92},
{"Olive-green table for sale, in extremely good condition.", "For sale: table in very good condition, olive green in colour.", 0.6060606060606061},
{"Olive-green table for sale, in extremely good condition.", "For sale: green Subaru Impreza, 210,000 miles", 0.2558139534883721},
{"Olive-green table for sale, in extremely good condition.", "Wanted: mountain bike with at least 21 gears.", 0.1411764705882353},
{"this has one extra word", "this has one word", 0.7741935483870968},
{"a", "a", 1},
{"a", "b", 0},
{"", "", 1},
{"a", "", 0},
{"", "a", 0},
{"apple event", "apple event", 1},
{"iphone", "iphone x", 0.9090909090909091},
}
var testCases2 = []struct {
s string
targets []string
expected *MatchResult
err error
}{
{"", nil, nil, fmt.Errorf("targets parameter need at least one element")},
{"", []string{}, nil, fmt.Errorf("targets parameter need at least one element")},
{
"healed",
[]string{"mailed", "edward", "sealed", "theatre"},
&MatchResult{
[]*Match{
{"mailed", 0.4},
{"edward", 0.2},
{"sealed", 0.8},
{"theatre", 0.36363636363636365},
},
&Match{"sealed", 0.8},
2,
},
nil,
},
{
"Olive-green table for sale, in extremely good condition.",
[]string{
"For sale: green Subaru Impreza, 210,000 miles",
"For sale: table in very good condition, olive green in colour.",
"Wanted: mountain bike with at least 21 gears.",
},
&MatchResult{
[]*Match{
{"For sale: green Subaru Impreza, 210,000 miles", 0.2558139534883721},
{"For sale: table in very good condition, olive green in colour.", 0.6060606060606061},
{"Wanted: mountain bike with at least 21 gears.", 0.1411764705882353},
},
&Match{"For sale: table in very good condition, olive green in colour.", 0.6060606060606061},
1,
},
nil,
},
}
var testCases3 = []struct {
actual *MatchResult
expected *MatchResult
}{
{
&MatchResult{
[]*Match{
{"mailed", 0.4},
{"edward", 0.2},
{"sealed", 0.8},
{"theatre", 0.36363636363636365},
},
&Match{"sealed", 0.8},
2,
},
&MatchResult{
[]*Match{
{"sealed", 0.8},
{"mailed", 0.4},
{"theatre", 0.36363636363636365},
{"edward", 0.2},
},
&Match{"sealed", 0.8},
0,
},
},
{
&MatchResult{
[]*Match{
{"For sale: green Subaru Impreza, 210,000 miles", 0.2558139534883721},
{"For sale: table in very good condition, olive green in colour.", 0.6060606060606061},
{"Wanted: mountain bike with at least 21 gears.", 0.1411764705882353},
},
&Match{"For sale: table in very good condition, olive green in colour.", 0.6060606060606061},
1,
},
&MatchResult{
[]*Match{
{"For sale: table in very good condition, olive green in colour.", 0.6060606060606061},
{"For sale: green Subaru Impreza, 210,000 miles", 0.2558139534883721},
{"Wanted: mountain bike with at least 21 gears.", 0.1411764705882353},
},
&Match{"For sale: table in very good condition, olive green in colour.", 0.6060606060606061},
0,
},
},
}