-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmod_test.ts
53 lines (50 loc) · 1.97 KB
/
mod_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
import { assertEquals } from "std/testing/asserts.ts";
import { diffCharacters, longestCommonSubsequence } from "./mod.ts";
Deno.test("Longest Common Subsequence", () => {
assertEquals(longestCommonSubsequence("abc", "abc"), "abc");
assertEquals(longestCommonSubsequence("abgd", "adh"), "ad");
assertEquals(longestCommonSubsequence("xabcd", "xabcf"), "xabc");
assertEquals(longestCommonSubsequence("ABCBDAB", "BDCABA"), "BCBA");
assertEquals(
longestCommonSubsequence(
"BACDCABAAAADDACADDBBDAABDCDBBBCCDACCCDBDD",
"BDACCACCDCCBADACDDACABBDAAABCDBBAADBCCCCB",
),
"BACDCBAADDACABBDAABCDBBBCCCCB",
);
assertEquals(
longestCommonSubsequence(
"abCd",
"AbCD",
true,
),
"AbCD",
);
});
Deno.test("DiffCharacters", () => {
const result = [
{ character: "b", wasAdded: false, wasRemoved: false },
{ character: "o", wasAdded: false, wasRemoved: false },
{ character: "o", wasAdded: false, wasRemoved: false },
{ character: "p", wasAdded: false, wasRemoved: false },
{ character: "a", wasAdded: false, wasRemoved: true },
{ character: " ", wasAdded: true, wasRemoved: false },
{ character: "b", wasAdded: true, wasRemoved: false },
{ character: "e", wasAdded: true, wasRemoved: false },
{ character: "e", wasAdded: true, wasRemoved: false },
{ character: "p", wasAdded: true, wasRemoved: false },
{ character: " ", wasAdded: true, wasRemoved: false },
{ character: "b", wasAdded: true, wasRemoved: false },
{ character: "o", wasAdded: true, wasRemoved: false },
{ character: "p", wasAdded: true, wasRemoved: false },
{ character: "p", wasAdded: true, wasRemoved: false },
{ character: "y", wasAdded: true, wasRemoved: false },
];
assertEquals(diffCharacters("boopa", "boop beep boppy"), result);
});
Deno.test("DiffCharacters given empty string", () => {
const result = [
{ character: "?", wasAdded: true, wasRemoved: false },
];
assertEquals(diffCharacters("", "?"), result);
});