summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-11-16 00:23:29 +0100
committerDimitri Sokolyuk <demon@dim13.org>2017-11-16 00:23:29 +0100
commitc8968c3ac2fa5d4e787cf1bc60d2c58a04873b59 (patch)
tree478fa7a67b3c2df6d75b99d4dbf567a80356e835
parent20d845cba2858a306fbf8193f510d6da6d2d6fc2 (diff)
more testcases
-rw-r--r--distance_test.go47
1 files changed, 39 insertions, 8 deletions
diff --git a/distance_test.go b/distance_test.go
index 50810fa..6fdd6d8 100644
--- a/distance_test.go
+++ b/distance_test.go
@@ -7,18 +7,49 @@ func TestDistance(t *testing.T) {
a, b string
dist int
}{
+ // empty strings
{"", "", 0},
- {"aa", "aa", 0},
- {"aa", "ab", 1},
- {"aa", "ba", 1},
- {"aa", "bb", 2},
- {"aa", "", 2},
- {"", "bb", 2},
- {"test", "Test", 1},
+ {"a", "", 1},
+ {"", "a", 1},
+ {"abc", "", 3},
+ {"", "abc", 3},
+
+ // equal strings
+ {"a", "a", 0},
+ {"abc", "abc", 0},
+
+ // only inserts
+ {"a", "ab", 1},
+ {"b", "ab", 1},
+ {"ac", "abc", 1},
+ {"abcdefg", "xabxcdxxefxgx", 6},
+
+ // only deletes
+ {"ab", "a", 1},
+ {"ab", "b", 1},
+ {"abc", "ac", 1},
+ {"xabxcdxxefxgx", "abcdefg", 6},
+
+ // only substitions
+ {"a", "b", 1},
+ {"ab", "ac", 1},
+ {"abc", "axc", 1},
+ {"xabxcdxxefxgx", "1ab2cd34ef5g6", 6},
+
+ // many oprations
+ {"example", "samples", 3},
+ {"sturgeon", "urgently", 6},
+ {"levenshtein", "frankenstein", 6},
+ {"distance", "difference", 5},
+ {"java was neat", "scala is great", 7},
+
+ // utf-8
{"тест", "Тест", 1},
+ {"gross", "groß", 2},
}
+
for _, tc := range testCases {
- t.Run(tc.a+" "+tc.b, func(t *testing.T) {
+ t.Run(tc.a+"·"+tc.b, func(t *testing.T) {
dist := Distance(tc.a, tc.b)
if dist != tc.dist {
t.Errorf("got %v, want %v", dist, tc.dist)