Skip to content

Commit a88c683

Browse files
committed
fix levenshtein error for #17
1 parent 2aaf5e4 commit a88c683

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

levenshtein.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package argparse
22

33
func decideMatch(target string, candidates []string) []string {
4+
if len(candidates) <= 0 {
5+
return []string{} // no match at all
6+
}
47
ldArray := make([]int, len(candidates))
58
for i, c := range candidates {
69
ldArray[i] = levDistance(target, c)

levenshtein_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ func TestLevDistance(t *testing.T) {
2222
}
2323

2424
func TestLevDecide(t *testing.T) {
25+
if len(decideMatch("xxx", []string{})) != 0 {
26+
t.Error("failed to strip empty")
27+
return
28+
}
2529
if decideMatch("linux", []string{"linux", "a", "b"})[0] != "linux" {
2630
t.Error("failed to match same word")
2731
return

0 commit comments

Comments
 (0)