std/text/levenshtein_distance_test.ts
ud2 2e542ff4d8
test(text): add more testcases for levenshteinDistance (#5528)
* test(text): add more testcases for `levenshteinDistance`

* clean

---------

Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
2024-07-23 23:43:55 +00:00

29 lines
1.1 KiB
TypeScript

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "@std/assert/equals";
import { levenshteinDistance } from "./levenshtein_distance.ts";
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);
});
Deno.test("levenshteinDistance() handles long strings", () => {
assertEquals(
levenshteinDistance(
"the quick brown fox jumps over the lazy dog",
"the lazy dog is jumped over by the quick brown fox",
),
30,
);
});