This repository has been archived by the owner on Dec 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
46 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package fuzzy | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestFuzzyScore(t *testing.T) { | ||
scoreA := Score("Marc", "Marcel#4759") | ||
scoreB := Score("Marc", "Maurice") | ||
if scoreA <= scoreB { | ||
t.Errorf("Incorrect score rating") | ||
} | ||
|
||
scoreC := Score("Marc", "Marchesi#4377") | ||
if scoreC <= scoreB { | ||
t.Errorf("Incorrect score rating") | ||
} | ||
|
||
arr := []string{"tests", "test", "testosterone", "atesta", "bob"} | ||
sorted := SortSearchResults(ScoreSearch("te", arr)) | ||
expected := [4]string{"test", "testosterone", "tests", "atesta"} | ||
|
||
if len(sorted) != len(expected) { | ||
t.Errorf("Expected length of %d, but received %d.\n", len(expected), len(sorted)) | ||
} | ||
|
||
var results [4]string | ||
for i, result := range sorted { | ||
results[i] = result.Key | ||
} | ||
|
||
if results != expected { | ||
t.Errorf("Expected\n%v\nbut received\n%v\n", expected, results) | ||
} | ||
|
||
} |