-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.test.js
70 lines (67 loc) · 2.42 KB
/
script.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { convertToEng, convertToMorse } from './conversionFunctions.js';
////////////////////////////////////////////////////////////////
describe('Converts to Morse', () => {
const testA = [
['hello world', '.... . .-.. .-.. --- | .-- --- .-. .-.. -..'],
['HELLO WORLD', '.... . .-.. .-.. --- | .-- --- .-. .-.. -..'],
[
'The number is 12345',
'- .... . | -. ..- -- -... . .-. | .. ... | .---- ..--- ...-- ....- .....',
],
];
it('handles lower case', () => {
expect(convertToMorse(testA[0][0])).toBe(testA[0][1]);
});
it('handles upper case', () => {
expect(convertToMorse(testA[1][0])).toBe(testA[1][1]);
});
it('Accounts for numbers', () => {
expect(convertToMorse(testA[2][0])).toBe(testA[2][1]);
});
});
////////////////////////////////////////////////////////////////
describe('Converts to English', () => {
const testB = [
['.... . .-.. .-.. --- | .-- --- .-. .-.. -..', 'hello world'],
['.... . .-.. .-.. --- / .-- --- .-. .-.. -..', 'hello world'],
[
'- .... . | -. ..- -- -... . .-. | .. ... | .---- ..--- ...-- ....- .....',
'the number is 12345',
],
];
it('converts hello world', () => {
expect(convertToEng(testB[0][0])).toBe(testB[0][1]);
});
it('handles slash notation', () => {
expect(convertToEng(testB[1][0])).toBe(testB[1][1]);
});
it('Accounts for numbers', () => {
expect(convertToEng(testB[2][0])).toBe(testB[2][1]);
});
});
////////////////////////////////////////////////////////////////
describe('Handles unexpected chars', () => {
const testC = [
['hello `world', '(hello is not defined in this morse library)'],
['*', '(* is not defined in this library)'],
];
it("returns the first component that's not in the library to eng", () => {
expect(convertToEng(testC[0][0])).toBe(testC[0][1]);
});
it("returns the first component that's not in the library", () => {
expect(convertToMorse(testC[1][0])).toBe(testC[1][1]);
});
});
////////////////////////////////////////////////////////////////
describe('Handles new lines', () => {
const testD = [
['.... . .-.. .-.. ---\n.-- --- .-. .-.. -..', 'hello world'],
['.... . .-.. .-.. ---\n\n\n\n.-- --- .-. .-.. -..', 'hello world'],
];
it('handles a new line', () => {
expect(convertToEng(testD[0][0])).toBe(testD[0][1]);
});
it('converts multiple new lines to spaces', () => {
expect(convertToEng(testD[1][0])).toBe(testD[1][1]);
});
});