|
| 1 | +#!/usr/bin/env raku |
| 2 | +use Test; |
| 3 | +use lib $?FILE.IO.parent(2).add('lib'); |
| 4 | +use RunLengthEncoding; |
| 5 | + |
| 6 | +cmp-ok( # begin: ad53b61b-6ffc-422f-81a6-61f7df92a231 |
| 7 | + rle-encode(""), |
| 8 | + "eq", |
| 9 | + "", |
| 10 | + "run-length encode a string: empty string", |
| 11 | +); # end: ad53b61b-6ffc-422f-81a6-61f7df92a231 |
| 12 | + |
| 13 | +cmp-ok( # begin: 52012823-b7e6-4277-893c-5b96d42f82de |
| 14 | + rle-encode("XYZ"), |
| 15 | + "eq", |
| 16 | + "XYZ", |
| 17 | + "run-length encode a string: single characters only are encoded without count", |
| 18 | +); # end: 52012823-b7e6-4277-893c-5b96d42f82de |
| 19 | + |
| 20 | +cmp-ok( # begin: b7868492-7e3a-415f-8da3-d88f51f80409 |
| 21 | + rle-encode("AABBBCCCC"), |
| 22 | + "eq", |
| 23 | + "2A3B4C", |
| 24 | + "run-length encode a string: string with no single characters", |
| 25 | +); # end: b7868492-7e3a-415f-8da3-d88f51f80409 |
| 26 | + |
| 27 | +cmp-ok( # begin: 859b822b-6e9f-44d6-9c46-6091ee6ae358 |
| 28 | + rle-encode("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB"), |
| 29 | + "eq", |
| 30 | + "12WB12W3B24WB", |
| 31 | + "run-length encode a string: single characters mixed with repeated characters", |
| 32 | +); # end: 859b822b-6e9f-44d6-9c46-6091ee6ae358 |
| 33 | + |
| 34 | +cmp-ok( # begin: 1b34de62-e152-47be-bc88-469746df63b3 |
| 35 | + rle-encode(" hsqq qww "), |
| 36 | + "eq", |
| 37 | + "2 hs2q q2w2 ", |
| 38 | + "run-length encode a string: multiple whitespace mixed in string", |
| 39 | +); # end: 1b34de62-e152-47be-bc88-469746df63b3 |
| 40 | + |
| 41 | +cmp-ok( # begin: abf176e2-3fbd-40ad-bb2f-2dd6d4df721a |
| 42 | + rle-encode("aabbbcccc"), |
| 43 | + "eq", |
| 44 | + "2a3b4c", |
| 45 | + "run-length encode a string: lowercase characters", |
| 46 | +); # end: abf176e2-3fbd-40ad-bb2f-2dd6d4df721a |
| 47 | + |
| 48 | +cmp-ok( # begin: 7ec5c390-f03c-4acf-ac29-5f65861cdeb5 |
| 49 | + rle-decode(""), |
| 50 | + "eq", |
| 51 | + "", |
| 52 | + "run-length decode a string: empty string", |
| 53 | +); # end: 7ec5c390-f03c-4acf-ac29-5f65861cdeb5 |
| 54 | + |
| 55 | +cmp-ok( # begin: ad23f455-1ac2-4b0e-87d0-b85b10696098 |
| 56 | + rle-decode("XYZ"), |
| 57 | + "eq", |
| 58 | + "XYZ", |
| 59 | + "run-length decode a string: single characters only", |
| 60 | +); # end: ad23f455-1ac2-4b0e-87d0-b85b10696098 |
| 61 | + |
| 62 | +cmp-ok( # begin: 21e37583-5a20-4a0e-826c-3dee2c375f54 |
| 63 | + rle-decode("2A3B4C"), |
| 64 | + "eq", |
| 65 | + "AABBBCCCC", |
| 66 | + "run-length decode a string: string with no single characters", |
| 67 | +); # end: 21e37583-5a20-4a0e-826c-3dee2c375f54 |
| 68 | + |
| 69 | +cmp-ok( # begin: 1389ad09-c3a8-4813-9324-99363fba429c |
| 70 | + rle-decode("12WB12W3B24WB"), |
| 71 | + "eq", |
| 72 | + "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB", |
| 73 | + "run-length decode a string: single characters with repeated characters", |
| 74 | +); # end: 1389ad09-c3a8-4813-9324-99363fba429c |
| 75 | + |
| 76 | +cmp-ok( # begin: 3f8e3c51-6aca-4670-b86c-a213bf4706b0 |
| 77 | + rle-decode("2 hs2q q2w2 "), |
| 78 | + "eq", |
| 79 | + " hsqq qww ", |
| 80 | + "run-length decode a string: multiple whitespace mixed in string", |
| 81 | +); # end: 3f8e3c51-6aca-4670-b86c-a213bf4706b0 |
| 82 | + |
| 83 | +cmp-ok( # begin: 29f721de-9aad-435f-ba37-7662df4fb551 |
| 84 | + rle-decode("2a3b4c"), |
| 85 | + "eq", |
| 86 | + "aabbbcccc", |
| 87 | + "run-length decode a string: lowercase string", |
| 88 | +); # end: 29f721de-9aad-435f-ba37-7662df4fb551 |
| 89 | + |
| 90 | +cmp-ok( # begin: 2a762efd-8695-4e04-b0d6-9736899fbc16 |
| 91 | + rle-decode(rle-encode("zzz ZZ zZ")), |
| 92 | + "eq", |
| 93 | + "zzz ZZ zZ", |
| 94 | + "encode and then decode: encode followed by decode gives original string", |
| 95 | +); # end: 2a762efd-8695-4e04-b0d6-9736899fbc16 |
| 96 | + |
| 97 | +done-testing; |
0 commit comments