1
exercism fetch ecmascript run-length-encoding

run-length-encoding.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
import { encode, decode } from './run-length-encoding';

describe('run-length encode a string', () => {
  test('encode empty string', () => {
    expect(encode('')).toEqual('');
  });

  xtest('single characters only are encoded without count', () => {
    expect(encode('XYZ')).toEqual('XYZ');
  });

  xtest('encode string with no single characters', () => {
    expect(encode('AABBBCCCC')).toEqual('2A3B4C');
  });

  xtest('encode string with single characters mixed with repeated characters', () => {
    expect(encode('WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB')).toEqual('12WB12W3B24WB');
  });

  xtest('encode string with multiple whitespaces', () => {
    expect(encode('  hsqq qww  ')).toEqual('2 hs2q q2w2 ');
  });

  xtest('encode string with lowercase characters', () => {
    expect(encode('aabbbcccc')).toEqual('2a3b4c');
  });
});

describe('run-length decode a string', () => {
  xtest('decode empty string', () => {
    expect(decode('')).toEqual('');
  });

  xtest('decode string with single characters only', () => {
    expect(decode('XYZ')).toEqual('XYZ');
  });

  xtest('decode string with no single characters', () => {
    expect(decode('2A3B4C')).toEqual('AABBBCCCC');
  });

  xtest('decode string with single characters mixed with repeated characters', () => {
    expect(decode('12WB12W3B24WB')).toEqual('WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB');
  });

  xtest('decode string with multiple whitespaces', () => {
    expect(decode('2 hs2q q2w2 ')).toEqual('  hsqq qww  ');
  });

  xtest('decode string with lowercase characters', () => {
    expect(decode('2a3b4c')).toEqual('aabbbcccc');
  });
});

describe('run-length encode and then decode', () => {
  xtest('encode followed by decode gives original string', () => {
    expect(decode(encode('zzz ZZ  zZ'))).toEqual('zzz ZZ  zZ');
  });
});