From 2e542ff4d8ffecd4509784fcf2fbad6a58804cb9 Mon Sep 17 00:00:00 2001 From: ud2 Date: Wed, 24 Jul 2024 07:43:55 +0800 Subject: [PATCH] test(text): add more testcases for `levenshteinDistance` (#5528) * test(text): add more testcases for `levenshteinDistance` * clean --------- Co-authored-by: Asher Gomez --- text/levenshtein_distance_test.ts | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/text/levenshtein_distance_test.ts b/text/levenshtein_distance_test.ts index d0ed6a9f8c88..c270c328b9c4 100644 --- a/text/levenshtein_distance_test.ts +++ b/text/levenshtein_distance_test.ts @@ -1,17 +1,28 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "@std/assert"; -import { levenshteinDistance } from "./mod.ts"; +import { assertEquals } from "@std/assert/equals"; +import { levenshteinDistance } from "./levenshtein_distance.ts"; -Deno.test("levenshteinDistance() handles basic cases", function () { - assertEquals( - levenshteinDistance("aa", "bb"), - 2, - ); +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 same strings", function () { +Deno.test("levenshteinDistance() handles long strings", () => { assertEquals( - levenshteinDistance("aa", "aa"), - 0, + levenshteinDistance( + "the quick brown fox jumps over the lazy dog", + "the lazy dog is jumped over by the quick brown fox", + ), + 30, ); });