2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2024-07-23 23:43:55 +00:00
|
|
|
import { assertEquals } from "@std/assert/equals";
|
|
|
|
import { levenshteinDistance } from "./levenshtein_distance.ts";
|
2023-11-05 12:49:00 +00:00
|
|
|
|
2024-07-23 23:43:55 +00:00
|
|
|
Deno.test("levenshteinDistance() handles basic cases", () => {
|
|
|
|
assertEquals(levenshteinDistance("levenshtein", "levenshtein"), 0);
|
|
|
|
assertEquals(levenshteinDistance("sitting", "kitten"), 3);
|
|
|
|
assertEquals(levenshteinDistance("gumbo", "gambol"), 2);
|
|
|
|
assertEquals(levenshteinDistance("saturday", "sunday"), 3);
|
|
|
|
assertEquals(levenshteinDistance("aarrgh", "aargh"), 1);
|
|
|
|
assertEquals(levenshteinDistance("aargh", "aarrgh"), 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test("levenshteinDistance() handles empty strings", () => {
|
|
|
|
assertEquals(levenshteinDistance("", "a"), 1);
|
|
|
|
assertEquals(levenshteinDistance("a", ""), 1);
|
|
|
|
assertEquals(levenshteinDistance("", ""), 0);
|
2023-11-05 12:49:00 +00:00
|
|
|
});
|
|
|
|
|
2024-07-23 23:43:55 +00:00
|
|
|
Deno.test("levenshteinDistance() handles long strings", () => {
|
2023-11-05 12:49:00 +00:00
|
|
|
assertEquals(
|
2024-07-23 23:43:55 +00:00
|
|
|
levenshteinDistance(
|
|
|
|
"the quick brown fox jumps over the lazy dog",
|
|
|
|
"the lazy dog is jumped over by the quick brown fox",
|
|
|
|
),
|
|
|
|
30,
|
2023-11-05 12:49:00 +00:00
|
|
|
);
|
|
|
|
});
|