-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
42 lines (35 loc) · 1.43 KB
/
test.js
File metadata and controls
42 lines (35 loc) · 1.43 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
const assert = require('assert');
const { textToMorse, morseToText } = require('./index.js');
describe('Morse Code Converter', () => {
describe('textToMorse', () => {
it('should convert single letters to morse code', () => {
assert.equal(textToMorse('A'), '.-');
assert.equal(textToMorse('B'), '-...');
assert.equal(textToMorse('E'), '.');
});
it('should convert words to morse code', () => {
assert.equal(textToMorse('HELLO'), '.... . .-.. .-.. ---');
assert.equal(textToMorse('SOS'), '... --- ...');
});
it('should handle spaces between words', () => {
assert.equal(textToMorse('HELLO WORLD'), '.... . .-.. .-.. --- .-- --- .-. .-.. -..');
});
it('should be case insensitive', () => {
assert.equal(textToMorse('hello'), '.... . .-.. .-.. ---');
});
});
describe('morseToText', () => {
it('should convert morse code to single letters', () => {
assert.equal(morseToText('.-'), 'A');
assert.equal(morseToText('-...'), 'B');
assert.equal(morseToText('.'), 'E');
});
it('should convert morse code to words', () => {
assert.equal(morseToText('.... . .-.. .-.. ---'), 'HELLO');
assert.equal(morseToText('... --- ...'), 'SOS');
});
it('should handle spaces between words', () => {
assert.equal(morseToText('.... . .-.. .-.. --- .-- --- .-. .-.. -..'), 'HELLO WORLD');
});
});
});