-
-
Notifications
You must be signed in to change notification settings - Fork 673
Expand file tree
/
Copy pathlevenshtein.test.js
More file actions
44 lines (35 loc) · 1.38 KB
/
levenshtein.test.js
File metadata and controls
44 lines (35 loc) · 1.38 KB
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
const { distance } = require("../../packages/webpack-cli/lib/levenshtein");
describe("distance", () => {
it("should return 0 for equal strings", () => {
expect(distance("", "")).toBe(0);
expect(distance("webpack", "webpack")).toBe(0);
});
it("should return the length of the other string when one is empty", () => {
expect(distance("", "abc")).toBe(3);
expect(distance("abc", "")).toBe(3);
});
it("should not depend on argument order", () => {
expect(distance("kitten", "sitting")).toBe(distance("sitting", "kitten"));
});
it("should count single edits", () => {
expect(distance("server", "serve")).toBe(1);
expect(distance("test", "tests")).toBe(1);
expect(distance("cat", "car")).toBe(1);
});
it("should compute classic distances", () => {
expect(distance("kitten", "sitting")).toBe(3);
expect(distance("flying", "sailing")).toBe(4);
});
it("should handle strings longer than 32 characters", () => {
const a = "a".repeat(40);
const b = `${"a".repeat(39)}b`;
expect(distance(a, b)).toBe(1);
expect(distance("a".repeat(40), "b".repeat(40))).toBe(40);
});
it("should handle a long string against a much shorter one", () => {
const long = "abcdefghijklmnopqrstuvwxyz0123456789ABCD";
expect(long).toHaveLength(40);
expect(distance(long, "abcde")).toBe(35);
expect(distance("abcde", long)).toBe(35);
});
});