-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlevenshtein_test.go
More file actions
50 lines (45 loc) · 1.17 KB
/
levenshtein_test.go
File metadata and controls
50 lines (45 loc) · 1.17 KB
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
package argparse
import (
"strings"
"testing"
)
func TestLevDistance(t *testing.T) {
for _, row := range [][]string{{"a", "a"}, {"well", "well"}, {"-linux", "-linux"}} {
if levDistance(row[0], row[1]) != 0 {
t.Error("should match")
return
}
}
for _, row := range [][]string{{"a", "b"}, {"well", "xell"}, {"linux", "-linux"}} {
if levDistance(row[0], row[1]) != 1 {
t.Error("should be only 1")
return
}
}
}
func TestLevDecide(t *testing.T) {
if len(decideMatch("xxx", []string{})) != 0 {
t.Error("failed to strip empty")
return
}
if decideMatch("linux", []string{"linux", "a", "b"})[0] != "linux" {
t.Error("failed to match same word")
return
}
if decideMatch("linux", []string{"linu", "a", "b"})[0] != "linu" {
t.Error("failed to match")
return
}
if decideMatch("linux", []string{"linuxa", "linua", "b"})[0] != "linua" {
t.Error("failed to choose shorter one")
return
}
if len(decideMatch("linux", []string{"bilibili", "ok", "z"})) != 0 {
t.Error("failed to stop match")
return
}
if strings.Join(decideMatch("linux", []string{"linua", "linub", "iinux"}), ",") != "linua,linub,iinux" {
t.Error("failed to match multi")
return
}
}