-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.spec.js
84 lines (74 loc) · 2.94 KB
/
index.spec.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const rot13 = require('./index');
describe('rot13', () => {
describe('when using defaults', () => {
it('should encode a string using rot13 by default', () => {
const secretMessage = 'Secret Message';
const expected = 'Frperg Zrffntr';
const actual = rot13(secretMessage);
expect(expected).toBe(actual);
});
it('should decode a string using rot13 by default', () => {
const secretMessage = 'Secret Message';
const encodedMessage = rot13(secretMessage);
const decodedMessage = rot13(encodedMessage);
expect(decodedMessage).toBe(secretMessage);
});
});
describe('when using an assymetric key', () => {
it('should encode a string using caesar cipher when using a key', () => {
const secretMessage = 'Secret Message';
const expected = 'Eqodqf Yqeemsq';
const actual = rot13(secretMessage, 12);
expect(expected).toBe(actual);
});
it('should decode a string using caesar cipher when using a key', () => {
const secretMessage = 'Secret Message';
const encodedMessage = rot13(secretMessage, 12);
const decodedMessage = rot13(encodedMessage, 14);
expect(decodedMessage).toBe(secretMessage);
});
});
describe('when using non alphabetic chars', () => {
describe('when message is not a string', () => {
it('should return an empty string', () => {
expect(rot13(null)).toBe('');
expect(rot13()).toBe('');
expect(rot13(undefined)).toBe('');
expect(rot13({})).toBe('');
expect(rot13([])).toBe('');
expect(rot13(true)).toBe('');
expect(rot13(123)).toBe('');
});
});
describe('when message contains numbers', () => {
it('should not encode the numbers in the message', () => {
const secretMessage = 'Secret Message 123';
const expectedEncoded = 'Frperg Zrffntr 123';
const encodedMessage = rot13(secretMessage);
const decodedMessage = rot13(encodedMessage);
expect(encodedMessage).toBe(expectedEncoded);
expect(decodedMessage).toBe(secretMessage);
});
});
describe('when message contains symbols', () => {
it('should not encode the symbols in the message', () => {
const secretMessage = 'Secret Message %^&*(';
const expectedEncoded = 'Frperg Zrffntr %^&*(';
const encodedMessage = rot13(secretMessage);
const decodedMessage = rot13(encodedMessage);
expect(encodedMessage).toBe(expectedEncoded);
expect(decodedMessage).toBe(secretMessage);
});
});
describe('when message is empty string', () => {
it('should not change the string at all', () => {
const secretMessage = '';
const expectedEncoded = '';
const encodedMessage = rot13(secretMessage);
const decodedMessage = rot13(encodedMessage);
expect(encodedMessage).toBe(expectedEncoded);
expect(decodedMessage).toBe(secretMessage);
});
});
});
});