|
1 | | -local encode = require('atbash-cipher').encode |
| 1 | +local atbash_cipher = require('atbash-cipher') |
2 | 2 |
|
3 | 3 | describe('atbash-cipher', function() |
4 | | - it('should encode single letter plaintexts', function() |
5 | | - assert.are.equal('m', encode('n')) |
6 | | - end) |
| 4 | + describe('encode', function() |
| 5 | + it('encode yes', function() |
| 6 | + local phrase = 'yes' |
| 7 | + local expected = 'bvh' |
| 8 | + local result = atbash_cipher.encode(phrase) |
| 9 | + assert.are.same(expected, result) |
| 10 | + end) |
7 | 11 |
|
8 | | - it('should encode single-chunk plaintexts', function() |
9 | | - assert.are.equal('svool', encode('hello')) |
10 | | - end) |
| 12 | + it('encode no', function() |
| 13 | + local phrase = 'no' |
| 14 | + local expected = 'ml' |
| 15 | + local result = atbash_cipher.encode(phrase) |
| 16 | + assert.are.same(expected, result) |
| 17 | + end) |
11 | 18 |
|
12 | | - it('should encode multi-chunk plaintexts', function() |
13 | | - assert.are.equal('nrmwy oldrm tob', encode('mindblowingly')) |
14 | | - end) |
| 19 | + it('encode omg', function() |
| 20 | + local phrase = 'OMG' |
| 21 | + local expected = 'lnt' |
| 22 | + local result = atbash_cipher.encode(phrase) |
| 23 | + assert.are.same(expected, result) |
| 24 | + end) |
15 | 25 |
|
16 | | - it('should encode all letters as lower-case', function() |
17 | | - assert.are.equal('svool', encode('HeLLo')) |
18 | | - end) |
| 26 | + it('encode spaces', function() |
| 27 | + local phrase = 'O M G' |
| 28 | + local expected = 'lnt' |
| 29 | + local result = atbash_cipher.encode(phrase) |
| 30 | + assert.are.same(expected, result) |
| 31 | + end) |
19 | 32 |
|
20 | | - it('should not encode whitespace', function() |
21 | | - assert.are.equal('svool', encode('h e l l o')) |
22 | | - end) |
| 33 | + it('encode mindblowingly', function() |
| 34 | + local phrase = 'mindblowingly' |
| 35 | + local expected = 'nrmwy oldrm tob' |
| 36 | + local result = atbash_cipher.encode(phrase) |
| 37 | + assert.are.same(expected, result) |
| 38 | + end) |
23 | 39 |
|
24 | | - it('should not encode punctuation', function() |
25 | | - assert.are.equal('svool', encode('h,e,l,l,o')) |
26 | | - end) |
| 40 | + it('encode numbers', function() |
| 41 | + local phrase = 'Testing,1 2 3, testing.' |
| 42 | + local expected = 'gvhgr mt123 gvhgr mt' |
| 43 | + local result = atbash_cipher.encode(phrase) |
| 44 | + assert.are.same(expected, result) |
| 45 | + end) |
27 | 46 |
|
28 | | - it('should not encode numbers', function() |
29 | | - assert.are.equal('sv11l', encode('he11o')) |
| 47 | + it('encode deep thought', function() |
| 48 | + local phrase = 'Truth is fiction.' |
| 49 | + local expected = 'gifgs rhurx grlm' |
| 50 | + local result = atbash_cipher.encode(phrase) |
| 51 | + assert.are.same(expected, result) |
| 52 | + end) |
| 53 | + |
| 54 | + it('encode all the letters', function() |
| 55 | + local phrase = 'The quick brown fox jumps over the lazy dog.' |
| 56 | + local expected = 'gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt' |
| 57 | + local result = atbash_cipher.encode(phrase) |
| 58 | + assert.are.same(expected, result) |
| 59 | + end) |
30 | 60 | end) |
31 | 61 |
|
32 | | - it('should encode all letters', function() |
33 | | - assert.are |
34 | | - .equal('gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt', encode('The quick brown fox jumps over the lazy dog.')) |
| 62 | + describe('decode', function() |
| 63 | + it('decode exercism', function() |
| 64 | + local phrase = 'vcvix rhn' |
| 65 | + local expected = 'exercism' |
| 66 | + local result = atbash_cipher.decode(phrase) |
| 67 | + assert.are.same(expected, result) |
| 68 | + end) |
| 69 | + |
| 70 | + it('decode a sentence', function() |
| 71 | + local phrase = 'zmlyh gzxov rhlug vmzhg vkkrm thglm v' |
| 72 | + local expected = 'anobstacleisoftenasteppingstone' |
| 73 | + local result = atbash_cipher.decode(phrase) |
| 74 | + assert.are.same(expected, result) |
| 75 | + end) |
| 76 | + |
| 77 | + it('decode numbers', function() |
| 78 | + local phrase = 'gvhgr mt123 gvhgr mt' |
| 79 | + local expected = 'testing123testing' |
| 80 | + local result = atbash_cipher.decode(phrase) |
| 81 | + assert.are.same(expected, result) |
| 82 | + end) |
| 83 | + |
| 84 | + it('decode all the letters', function() |
| 85 | + local phrase = 'gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt' |
| 86 | + local expected = 'thequickbrownfoxjumpsoverthelazydog' |
| 87 | + local result = atbash_cipher.decode(phrase) |
| 88 | + assert.are.same(expected, result) |
| 89 | + end) |
| 90 | + |
| 91 | + it('decode with too many spaces', function() |
| 92 | + local phrase = 'vc vix r hn' |
| 93 | + local expected = 'exercism' |
| 94 | + local result = atbash_cipher.decode(phrase) |
| 95 | + assert.are.same(expected, result) |
| 96 | + end) |
| 97 | + |
| 98 | + it('decode with no spaces', function() |
| 99 | + local phrase = 'zmlyhgzxovrhlugvmzhgvkkrmthglmv' |
| 100 | + local expected = 'anobstacleisoftenasteppingstone' |
| 101 | + local result = atbash_cipher.decode(phrase) |
| 102 | + assert.are.same(expected, result) |
| 103 | + end) |
35 | 104 | end) |
36 | 105 | end) |
0 commit comments