omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / exercises / series / 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/series/canonical-data.json at |
| 47 | note commit 650bebeb39ad40439175288042aece982b0a90a9 (2026-10-19), MIT licence, |
| 48 | note https://github.com/exercism/problem-specifications |
| 49 | note 11 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 s0 "1" |
| 62 | text e1 "1" |
| 63 | text c2 "slices: slices of one from one" |
| 64 | text s3 "12" |
| 65 | text e4 "1,2" |
| 66 | text c5 "slices: slices of one from two" |
| 67 | text s6 "35" |
| 68 | text e7 "35" |
| 69 | text c8 "slices: slices of two" |
| 70 | text s9 "9142" |
| 71 | text e10 "91,14,42" |
| 72 | text c11 "slices: slices of two overlap" |
| 73 | text s12 "777777" |
| 74 | text e13 "777,777,777,777" |
| 75 | text c14 "slices: slices can include duplicates" |
| 76 | text s15 "918493904243" |
| 77 | text e16 "91849,18493,84939,49390,93904,39042,90424,04243" |
| 78 | text c17 "slices: slices of a long series" |
| 79 | text s18 "12345" |
| 80 | text c19 "slices: slice length is too large" |
| 81 | text s20 "12345" |
| 82 | text c21 "slices: slice length is way too large" |
| 83 | text s22 "12345" |
| 84 | text c23 "slices: slice length cannot be zero" |
| 85 | text s24 "123" |
| 86 | text c25 "slices: slice length cannot be negative" |
| 87 | text z26 "z" |
| 88 | text c27 "slices: empty series is invalid" |
| 89 | note canonical case 7ae7a46a-d992-4c2a-9c15-a112d125ebad |
| 90 | fn tc0 to bool |
| 91 | o = new uchar 1024 0 |
| 92 | n = slices s0 1 o |
| 93 | if lt n 0 |
| 94 | ret false |
| 95 | end |
| 96 | ret tbeq part o 0 ulong n e1 |
| 97 | end |
| 98 | note canonical case 3143b71d-f6a5-4221-aeae-619f906244d2 |
| 99 | fn tc1 to bool |
| 100 | o = new uchar 1024 0 |
| 101 | n = slices s3 1 o |
| 102 | if lt n 0 |
| 103 | ret false |
| 104 | end |
| 105 | ret tbeq part o 0 ulong n e4 |
| 106 | end |
| 107 | note canonical case dbb68ff5-76c5-4ccd-895a-93dbec6d5805 |
| 108 | fn tc2 to bool |
| 109 | o = new uchar 1024 0 |
| 110 | n = slices s6 2 o |
| 111 | if lt n 0 |
| 112 | ret false |
| 113 | end |
| 114 | ret tbeq part o 0 ulong n e7 |
| 115 | end |
| 116 | note canonical case 19bbea47-c987-4e11-a7d1-e103442adf86 |
| 117 | fn tc3 to bool |
| 118 | o = new uchar 1024 0 |
| 119 | n = slices s9 2 o |
| 120 | if lt n 0 |
| 121 | ret false |
| 122 | end |
| 123 | ret tbeq part o 0 ulong n e10 |
| 124 | end |
| 125 | note canonical case 8e17148d-ba0a-4007-a07f-d7f87015d84c |
| 126 | fn tc4 to bool |
| 127 | o = new uchar 1024 0 |
| 128 | n = slices s12 3 o |
| 129 | if lt n 0 |
| 130 | ret false |
| 131 | end |
| 132 | ret tbeq part o 0 ulong n e13 |
| 133 | end |
| 134 | note canonical case bd5b085e-f612-4f81-97a8-6314258278b0 |
| 135 | fn tc5 to bool |
| 136 | o = new uchar 1024 0 |
| 137 | n = slices s15 5 o |
| 138 | if lt n 0 |
| 139 | ret false |
| 140 | end |
| 141 | ret tbeq part o 0 ulong n e16 |
| 142 | end |
| 143 | note canonical case 6d235d85-46cf-4fae-9955-14b6efef27cd |
| 144 | fn tc6 to bool |
| 145 | o = new uchar 1024 0 |
| 146 | ret eq slices s18 6 o -4 |
| 147 | end |
| 148 | note canonical case d7957455-346d-4e47-8e4b-87ed1564c6d7 |
| 149 | fn tc7 to bool |
| 150 | o = new uchar 1024 0 |
| 151 | ret eq slices s20 42 o -4 |
| 152 | end |
| 153 | note canonical case d34004ad-8765-4c09-8ba1-ada8ce776806 |
| 154 | fn tc8 to bool |
| 155 | o = new uchar 1024 0 |
| 156 | ret eq slices s22 0 o -3 |
| 157 | end |
| 158 | note canonical case 10ab822d-8410-470a-a85d-23fbeb549e54 |
| 159 | fn tc9 to bool |
| 160 | o = new uchar 1024 0 |
| 161 | ret eq slices s24 -1 o -2 |
| 162 | end |
| 163 | note canonical case c7ed0812-0e4b-4bf3-99c4-28cbbfc246a2 |
| 164 | fn tc10 to bool |
| 165 | o = new uchar 1024 0 |
| 166 | ret eq slices part z26 0 0 1 o -1 |
| 167 | end |
| 168 | fn main to int |
| 169 | tcheck tc0 c2 |
| 170 | tcheck tc1 c5 |
| 171 | tcheck tc2 c8 |
| 172 | tcheck tc3 c11 |
| 173 | tcheck tc4 c14 |
| 174 | tcheck tc5 c17 |
| 175 | tcheck tc6 c19 |
| 176 | tcheck tc7 c21 |
| 177 | tcheck tc8 c23 |
| 178 | tcheck tc9 c25 |
| 179 | tcheck tc10 c27 |
| 180 | ret int get tfails 0 |
| 181 | end |