2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2024-04-29 02:57:30 +00:00
|
|
|
import { assertEquals } from "@std/assert";
|
2023-11-05 12:49:00 +00:00
|
|
|
import { wordSimilaritySort } from "./word_similarity_sort.ts";
|
|
|
|
|
2024-06-11 07:34:14 +00:00
|
|
|
Deno.test("wordSimilaritySort() handles basic example", () => {
|
|
|
|
const possibleWords = ["length", "size", "blah", "help"];
|
|
|
|
const givenWord = "hep";
|
2023-11-05 12:49:00 +00:00
|
|
|
assertEquals(
|
2024-06-11 07:34:14 +00:00
|
|
|
wordSimilaritySort(givenWord, possibleWords),
|
|
|
|
["help", "size", "blah", "length"],
|
2023-11-05 12:49:00 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2024-06-11 07:34:14 +00:00
|
|
|
Deno.test("wordSimilaritySort() with case-sensitive sorting", () => {
|
|
|
|
const possibleWords = ["length", "Size", "blah", "HELP"];
|
|
|
|
const givenWord = "hep";
|
|
|
|
assertEquals(
|
|
|
|
wordSimilaritySort(givenWord, possibleWords, { caseSensitive: true }),
|
|
|
|
["Size", "blah", "HELP", "length"],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test("wordSimilaritySort() handles empty string", () => {
|
|
|
|
const possibleWords = ["length", "size", "blah", "help", ""];
|
|
|
|
const givenWord = "";
|
2023-11-05 12:49:00 +00:00
|
|
|
|
|
|
|
assertEquals(
|
2024-06-11 07:34:14 +00:00
|
|
|
wordSimilaritySort(givenWord, possibleWords),
|
|
|
|
["", "size", "blah", "help", "length"],
|
2023-11-05 12:49:00 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-12-20 09:58:55 +00:00
|
|
|
Deno.test("wordSimilaritySort() handles empty array", function () {
|
2023-11-05 12:49:00 +00:00
|
|
|
const possibleWords: string[] = [];
|
2024-06-11 07:34:14 +00:00
|
|
|
const givenWord = "";
|
2023-11-05 12:49:00 +00:00
|
|
|
|
|
|
|
assertEquals(
|
2024-06-11 07:34:14 +00:00
|
|
|
wordSimilaritySort(givenWord, possibleWords),
|
|
|
|
[],
|
2023-11-05 12:49:00 +00:00
|
|
|
);
|
|
|
|
});
|