omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / exercises / resistor-color / 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/resistor-color/canonical-data.json at |
| 47 | note commit 650bebeb39ad40439175288042aece982b0a90a9 (2026-10-19), MIT licence, |
| 48 | note https://github.com/exercism/problem-specifications |
| 49 | note 4 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 "black" |
| 62 | text c1 "colorCode: Color codes / Black" |
| 63 | text s2 "white" |
| 64 | text c3 "colorCode: Color codes / White" |
| 65 | text s4 "orange" |
| 66 | text c5 "colorCode: Color codes / Orange" |
| 67 | text e6 "black,brown,red,orange,yellow,green,blue,violet,grey,white" |
| 68 | text c7 "colors: Colors" |
| 69 | note canonical case 49eb31c5-10a8-4180-9f7f-fea632ab87ef |
| 70 | fn tc0 to bool |
| 71 | ret eq colorcode s0 0 |
| 72 | end |
| 73 | note canonical case 0a4df94b-92da-4579-a907-65040ce0b3fc |
| 74 | fn tc1 to bool |
| 75 | ret eq colorcode s2 9 |
| 76 | end |
| 77 | note canonical case 5f81608d-f36f-4190-8084-f45116b6f380 |
| 78 | fn tc2 to bool |
| 79 | ret eq colorcode s4 3 |
| 80 | end |
| 81 | note canonical case 581d68fa-f968-4be2-9f9d-880f2fb73cf7 |
| 82 | fn tc3 to bool |
| 83 | o = new uchar 1024 0 |
| 84 | n = colors o |
| 85 | ret tbeq part o 0 n e6 |
| 86 | end |
| 87 | fn main to int |
| 88 | tcheck tc0 c1 |
| 89 | tcheck tc1 c3 |
| 90 | tcheck tc2 c5 |
| 91 | tcheck tc3 c7 |
| 92 | ret int get tfails 0 |
| 93 | end |