|
| 1 | +import encode, decode from require 'run_length_encoding' |
| 2 | + |
| 3 | +describe 'run-length-encoding', -> |
| 4 | + describe 'run-length encode a string', -> |
| 5 | + it 'empty string', -> |
| 6 | + result = encode '' |
| 7 | + assert.are.equal '', result |
| 8 | + |
| 9 | + pending 'single characters only are encoded without count', -> |
| 10 | + result = encode 'XYZ' |
| 11 | + assert.are.equal 'XYZ', result |
| 12 | + |
| 13 | + pending 'string with no single characters', -> |
| 14 | + result = encode 'AABBBCCCC' |
| 15 | + assert.are.equal '2A3B4C', result |
| 16 | + |
| 17 | + pending 'single characters mixed with repeated characters', -> |
| 18 | + result = encode 'WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB' |
| 19 | + assert.are.equal '12WB12W3B24WB', result |
| 20 | + |
| 21 | + pending 'multiple whitespace mixed in string', -> |
| 22 | + result = encode ' hsqq qww ' |
| 23 | + assert.are.equal '2 hs2q q2w2 ', result |
| 24 | + |
| 25 | + pending 'lowercase characters', -> |
| 26 | + result = encode 'aabbbcccc' |
| 27 | + assert.are.equal '2a3b4c', result |
| 28 | + |
| 29 | + describe 'run-length decode a string', -> |
| 30 | + pending 'empty string', -> |
| 31 | + result = decode '' |
| 32 | + assert.are.equal '', result |
| 33 | + |
| 34 | + pending 'single characters only', -> |
| 35 | + result = decode 'XYZ' |
| 36 | + assert.are.equal 'XYZ', result |
| 37 | + |
| 38 | + pending 'string with no single characters', -> |
| 39 | + result = decode '2A3B4C' |
| 40 | + assert.are.equal 'AABBBCCCC', result |
| 41 | + |
| 42 | + pending 'single characters with repeated characters', -> |
| 43 | + result = decode '12WB12W3B24WB' |
| 44 | + assert.are.equal 'WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB', result |
| 45 | + |
| 46 | + pending 'multiple whitespace mixed in string', -> |
| 47 | + result = decode '2 hs2q q2w2 ' |
| 48 | + assert.are.equal ' hsqq qww ', result |
| 49 | + |
| 50 | + pending 'lowercase string', -> |
| 51 | + result = decode '2a3b4c' |
| 52 | + assert.are.equal 'aabbbcccc', result |
| 53 | + |
| 54 | + describe 'encode and then decode', -> |
| 55 | + pending 'encode followed by decode gives original string', -> |
| 56 | + encoded = encode 'zzz ZZ zZ' |
| 57 | + decoded = decode encoded |
| 58 | + assert.are.equal 'zzz ZZ zZ', decoded |
0 commit comments