-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompositionword.test.js
44 lines (29 loc) · 1.36 KB
/
compositionword.test.js
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 fs = require("fs");
const { isCompoundWord , processWordList } = require("./index");
describe("isCompoundWord", () => {
test("should return true for compounded words", () => {
const wordSet = new Set(["apple", "pie", "applepie", "banana", "bananapie"]);
expect(isCompoundWord("applepie", wordSet)).toBe(true);
expect(isCompoundWord("bananapie", wordSet)).toBe(true);
});
test("should return false for non-compounded words", () => {
const wordSet = new Set(["apple", "pie", "banana"]);
expect(isCompoundWord("apple", wordSet)).toBe(false);
expect(isCompoundWord("pie", wordSet)).toBe(false);
expect(isCompoundWord("banana", wordSet)).toBe(false);
});
test("should return false for an empty string", () => {
const wordSet = new Set(["apple", "pie", "banana"]);
expect(isCompoundWord("", wordSet)).toBe(false);
});
});
describe("processWordList", () => {
test("should correctly identify the longest and second longest compounded words", () => {
const filePath = "./Input_01.txt";
const consoleLogSpy = jest.spyOn(console, "log");
processWordList(filePath);
expect(consoleLogSpy).toHaveBeenCalledWith("Longest Compound Word:", "ratcatdogcat");
expect(consoleLogSpy).toHaveBeenCalledWith("Second Longest Compound Word:", "catsdogcats");
consoleLogSpy.mockRestore();
});
});