Skip to content

Commit

Permalink
test(morse-code-decoder): HackerRank full input scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
jebarsoba committed Mar 30, 2022
1 parent 0d212a1 commit f481a8b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion hackerrank/morse-code-decoder.data.raw.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ TO
WHAT
WROTH
*
.--......-- .....--....
.--.....-- .....--....
--.----.. .--.-.----..
.--.....-- .--.
..-.-.-....--.-..-.--.-.
Expand Down
2 changes: 1 addition & 1 deletion hackerrank/morse-code-decoder.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ TO
WHAT
WROTH
*
.--......-- .....--....
.--.....-- .....--....
--.----.. .--.-.----..
.--.....-- .--.
..-.-.-....--.-..-.--.-.
Expand Down
51 changes: 51 additions & 0 deletions hackerrank/morse-code-decoder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ describe("morse code decoding", () => {
});

describe("HackerRank tests, based on provided input and expected output", () => {
it("test case 1", async () => {
const data = await readFileAsync(
"./morse-code-decoder.data.raw.txt",
"utf8"
);
const input = parseInput(data);

expect(decode(".--.....--", input.dictionary, input.context)).toBe("WHAT");
});

it("test case 2", async () => {
const data = await readFileAsync(
"./morse-code-decoder.data.raw.txt",
Expand Down Expand Up @@ -240,4 +250,45 @@ describe("HackerRank tests, based on provided input and expected output", () =>
"READY"
);
});

it("test case 10", async () => {
const data = await readFileAsync(
"./morse-code-decoder.data.raw.txt",
"utf8"
);
const input = parseInput(data);

expect(decode("----", input.dictionary, input.context)).toBe("TO");
});

it("test case 11", async () => {
const data = await readFileAsync(
"./morse-code-decoder.data.raw.txt",
"utf8"
);
const input = parseInput(data);

expect(decode("..--", input.dictionary, input.context)).toBe("IM!");
});

it("process full raw data alltogether", async () => {
const data = await readFileAsync(
"./morse-code-decoder.data.raw.txt",
"utf8"
);
processData(data);

const stdout = outputData.split("-NEWLINE-");
expect(stdout[0]).toBe("WHAT");
expect(stdout[1]).toBe("HATH");
expect(stdout[2]).toBe("GOD");
expect(stdout[3]).toBe("WROTH?");
expect(stdout[4]).toBe("WHAT");
expect(stdout[5]).toBe("AN");
expect(stdout[6]).toBe("EARTHQUAKE");
expect(stdout[7]).toBe("IM!");
expect(stdout[8]).toBe("READY");
expect(stdout[9]).toBe("TO");
expect(stdout[10]).toBe("IM!");
});
});

0 comments on commit f481a8b

Please sign in to comment.