omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / exercises / run-length-encoding / test.om
| 1 | note ---- test harness (appended after the solution by exercise.sh) ---- |
| 2 | text tok "ok " |
| 3 | text tnok "not ok " |
| 4 | text tsep " - " |
| 5 | text tnl "\n" |
| 6 | global tfails ulong 1 |
| 7 | global tnum ulong 1 |
| 8 | fn temit a view uchar * to void |
| 9 | o = ulong 0 |
| 10 | while lt o len a bound 4096 |
| 11 | k = write 1 a o sub len a o |
| 12 | if le k 0 |
| 13 | exit 2 |
| 14 | end |
| 15 | o = add o ulong k |
| 16 | end |
| 17 | end |
| 18 | fn temitu n ulong to void |
| 19 | d = new uchar 20 0 |
| 20 | i = ulong 20 |
| 21 | v = n |
| 22 | while true bound 20 |
| 23 | i = sub i 1 |
| 24 | put d i uchar add rem v 10 48 |
| 25 | v = div v 10 |
| 26 | if eq v 0 |
| 27 | break |
| 28 | end |
| 29 | end |
| 30 | temit part d i sub 20 i |
| 31 | end |
| 32 | note one TAP-style line per case; main returns the number of failed cases |
| 33 | fn tcheck c bool what view uchar * to void |
| 34 | put tnum 0 add get tnum 0 1 |
| 35 | if c |
| 36 | temit tok |
| 37 | else |
| 38 | temit tnok |
| 39 | put tfails 0 add get tfails 0 1 |
| 40 | end |
| 41 | temitu get tnum 0 |
| 42 | temit tsep |
| 43 | temit what |
| 44 | temit tnl |
| 45 | end |
| 46 | note cases: exercism/problem-specifications exercises/run-length-encoding/canonical-data.json at |
| 47 | note commit 650bebeb39ad40439175288042aece982b0a90a9 (2026-10-19), MIT licence, |
| 48 | note https://github.com/exercism/problem-specifications |
| 49 | note 13 cases kept, 0 skipped |
| 50 | fn tbeq a view uchar * b view uchar * to bool |
| 51 | if ne len a len b |
| 52 | ret false |
| 53 | end |
| 54 | for i ulong len a |
| 55 | if ne get a i get b i |
| 56 | ret false |
| 57 | end |
| 58 | end |
| 59 | ret true |
| 60 | end |
| 61 | text z0 "z" |
| 62 | text c1 "encode: run-length encode a string / empty string" |
| 63 | text s2 "XYZ" |
| 64 | text e3 "XYZ" |
| 65 | text c4 "encode: run-length encode a string / single characters only are encoded without count" |
| 66 | text s5 "AABBBCCCC" |
| 67 | text e6 "2A3B4C" |
| 68 | text c7 "encode: run-length encode a string / string with no single characters" |
| 69 | text s8 "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB" |
| 70 | text e9 "12WB12W3B24WB" |
| 71 | text c10 "encode: run-length encode a string / single characters mixed with repeated characters" |
| 72 | text s11 " hsqq qww " |
| 73 | text e12 "2 hs2q q2w2 " |
| 74 | text c13 "encode: run-length encode a string / multiple whitespace mixed in string" |
| 75 | text s14 "aabbbcccc" |
| 76 | text e15 "2a3b4c" |
| 77 | text c16 "encode: run-length encode a string / lowercase characters" |
| 78 | text z17 "z" |
| 79 | text c18 "decode: run-length decode a string / empty string" |
| 80 | text s19 "XYZ" |
| 81 | text e20 "XYZ" |
| 82 | text c21 "decode: run-length decode a string / single characters only" |
| 83 | text s22 "2A3B4C" |
| 84 | text e23 "AABBBCCCC" |
| 85 | text c24 "decode: run-length decode a string / string with no single characters" |
| 86 | text s25 "12WB12W3B24WB" |
| 87 | text e26 "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB" |
| 88 | text c27 "decode: run-length decode a string / single characters with repeated characters" |
| 89 | text s28 "2 hs2q q2w2 " |
| 90 | text e29 " hsqq qww " |
| 91 | text c30 "decode: run-length decode a string / multiple whitespace mixed in string" |
| 92 | text s31 "2a3b4c" |
| 93 | text e32 "aabbbcccc" |
| 94 | text c33 "decode: run-length decode a string / lowercase string" |
| 95 | text s34 "zzz ZZ zZ" |
| 96 | text e35 "zzz ZZ zZ" |
| 97 | text c36 "consistency: encode and then decode / encode followed by decode gives original string" |
| 98 | note canonical case ad53b61b-6ffc-422f-81a6-61f7df92a231 |
| 99 | fn tc0 to bool |
| 100 | o = new uchar 1024 0 |
| 101 | n = encode part z0 0 0 o |
| 102 | ret eq n 0 |
| 103 | end |
| 104 | note canonical case 52012823-b7e6-4277-893c-5b96d42f82de |
| 105 | fn tc1 to bool |
| 106 | o = new uchar 1024 0 |
| 107 | n = encode s2 o |
| 108 | ret tbeq part o 0 n e3 |
| 109 | end |
| 110 | note canonical case b7868492-7e3a-415f-8da3-d88f51f80409 |
| 111 | fn tc2 to bool |
| 112 | o = new uchar 1024 0 |
| 113 | n = encode s5 o |
| 114 | ret tbeq part o 0 n e6 |
| 115 | end |
| 116 | note canonical case 859b822b-6e9f-44d6-9c46-6091ee6ae358 |
| 117 | fn tc3 to bool |
| 118 | o = new uchar 1024 0 |
| 119 | n = encode s8 o |
| 120 | ret tbeq part o 0 n e9 |
| 121 | end |
| 122 | note canonical case 1b34de62-e152-47be-bc88-469746df63b3 |
| 123 | fn tc4 to bool |
| 124 | o = new uchar 1024 0 |
| 125 | n = encode s11 o |
| 126 | ret tbeq part o 0 n e12 |
| 127 | end |
| 128 | note canonical case abf176e2-3fbd-40ad-bb2f-2dd6d4df721a |
| 129 | fn tc5 to bool |
| 130 | o = new uchar 1024 0 |
| 131 | n = encode s14 o |
| 132 | ret tbeq part o 0 n e15 |
| 133 | end |
| 134 | note canonical case 7ec5c390-f03c-4acf-ac29-5f65861cdeb5 |
| 135 | fn tc6 to bool |
| 136 | o = new uchar 1024 0 |
| 137 | n = decode part z17 0 0 o |
| 138 | ret eq n 0 |
| 139 | end |
| 140 | note canonical case ad23f455-1ac2-4b0e-87d0-b85b10696098 |
| 141 | fn tc7 to bool |
| 142 | o = new uchar 1024 0 |
| 143 | n = decode s19 o |
| 144 | ret tbeq part o 0 n e20 |
| 145 | end |
| 146 | note canonical case 21e37583-5a20-4a0e-826c-3dee2c375f54 |
| 147 | fn tc8 to bool |
| 148 | o = new uchar 1024 0 |
| 149 | n = decode s22 o |
| 150 | ret tbeq part o 0 n e23 |
| 151 | end |
| 152 | note canonical case 1389ad09-c3a8-4813-9324-99363fba429c |
| 153 | fn tc9 to bool |
| 154 | o = new uchar 1024 0 |
| 155 | n = decode s25 o |
| 156 | ret tbeq part o 0 n e26 |
| 157 | end |
| 158 | note canonical case 3f8e3c51-6aca-4670-b86c-a213bf4706b0 |
| 159 | fn tc10 to bool |
| 160 | o = new uchar 1024 0 |
| 161 | n = decode s28 o |
| 162 | ret tbeq part o 0 n e29 |
| 163 | end |
| 164 | note canonical case 29f721de-9aad-435f-ba37-7662df4fb551 |
| 165 | fn tc11 to bool |
| 166 | o = new uchar 1024 0 |
| 167 | n = decode s31 o |
| 168 | ret tbeq part o 0 n e32 |
| 169 | end |
| 170 | note canonical case 2a762efd-8695-4e04-b0d6-9736899fbc16 |
| 171 | fn tc12 to bool |
| 172 | o = new uchar 1024 0 |
| 173 | o2 = new uchar 1024 0 |
| 174 | n = encode s34 o |
| 175 | m = decode part o 0 n o2 |
| 176 | ret tbeq part o2 0 m e35 |
| 177 | end |
| 178 | fn main to int |
| 179 | tcheck tc0 c1 |
| 180 | tcheck tc1 c4 |
| 181 | tcheck tc2 c7 |
| 182 | tcheck tc3 c10 |
| 183 | tcheck tc4 c13 |
| 184 | tcheck tc5 c16 |
| 185 | tcheck tc6 c18 |
| 186 | tcheck tc7 c21 |
| 187 | tcheck tc8 c24 |
| 188 | tcheck tc9 c27 |
| 189 | tcheck tc10 c30 |
| 190 | tcheck tc11 c33 |
| 191 | tcheck tc12 c36 |
| 192 | ret int get tfails 0 |
| 193 | end |