forked from trekhleb/javascript-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrailFenceCipher.test.js
More file actions
43 lines (39 loc) · 1.33 KB
/
railFenceCipher.test.js
File metadata and controls
43 lines (39 loc) · 1.33 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
43
import { encodeRailFenceCipher, decodeRailFenceCipher } from '../railFenceCipher';
describe('railFenceCipher', () => {
it('encodes a string correctly for base=3', () => {
expect(encodeRailFenceCipher('', 3)).toBe('');
expect(encodeRailFenceCipher('12345', 3)).toBe(
'15243',
);
expect(encodeRailFenceCipher('WEAREDISCOVEREDFLEEATONCE', 3)).toBe(
'WECRLTEERDSOEEFEAOCAIVDEN',
);
expect(encodeRailFenceCipher('Hello, World!', 3)).toBe(
'Hoo!el,Wrdl l',
);
});
it('decodes a string correctly for base=3', () => {
expect(decodeRailFenceCipher('', 3)).toBe('');
expect(decodeRailFenceCipher('WECRLTEERDSOEEFEAOCAIVDEN', 3)).toBe(
'WEAREDISCOVEREDFLEEATONCE',
);
expect(decodeRailFenceCipher('Hoo!el,Wrdl l', 3)).toBe(
'Hello, World!',
);
expect(decodeRailFenceCipher('15243', 3)).toBe(
'12345',
);
});
it('encodes a string correctly for base=4', () => {
expect(encodeRailFenceCipher('', 4)).toBe('');
expect(encodeRailFenceCipher('THEYAREATTACKINGFROMTHENORTH', 4)).toBe(
'TEKOOHRACIRMNREATANFTETYTGHH',
);
});
it('decodes a string correctly for base=4', () => {
expect(decodeRailFenceCipher('', 4)).toBe('');
expect(decodeRailFenceCipher('TEKOOHRACIRMNREATANFTETYTGHH', 4)).toBe(
'THEYAREATTACKINGFROMTHENORTH',
);
});
});