This repository has been archived by the owner on Mar 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
damerauLevenshtein.test.ts
62 lines (51 loc) · 1.97 KB
/
damerauLevenshtein.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { describe, expect, it } from "vitest";
import damerauLevenshtein from "./damerauLevenshtein";
// https://github.com/aldebaran/libport/blob/master/tests/libport/damerau-levenshtein-distance.cc
describe("damerauLevenshtein", () => {
const emptyString = "";
it("should pass, empty strings", () => {
const distance = damerauLevenshtein(emptyString, emptyString);
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
expect(distance).toBe(0);
});
it("should pass, distance 0", () => {
const s = "cat";
const distance = damerauLevenshtein(s, s);
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
expect(distance).toBe(0);
});
it("should pass, 100% distance", () => {
const s2 = "test";
const expectedDistance = s2.length;
const distance = damerauLevenshtein(emptyString, s2);
expect(distance).toBe(expectedDistance);
});
it("should pass, cat and dog", () => {
const distance = damerauLevenshtein("cat", "dog");
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
expect(distance).toBe(3);
});
it("should pass, deletion", () => {
const distance = damerauLevenshtein("azertyuiop", "aeryuop");
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
expect(distance).toBe(3);
});
it("should pass, insertion", () => {
const distance = damerauLevenshtein("aeryuop", "azertyuiop");
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
expect(distance).toBe(3);
});
it("should pass, substitution", () => {
const distance = damerauLevenshtein(
"azertyuiopqsdfghjklmwxcvbn,",
"qwertyuiopasdfghjkl;zxcvbnm"
);
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
expect(distance).toBe(6);
});
it("should pass, transposition", () => {
const distance = damerauLevenshtein("1234567890", "1324576809");
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
expect(distance).toBe(3);
});
});