omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / exercises / resistor-color-trio / 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-trio/canonical-data.json at |
| 47 | note commit 650bebeb39ad40439175288042aece982b0a90a9 (2026-10-19), MIT licence, |
| 48 | note https://github.com/exercism/problem-specifications |
| 49 | note 10 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 "orange,orange,black" |
| 62 | text e1 "33 ohms" |
| 63 | text c2 "label: Orange and orange and black" |
| 64 | text s3 "blue,grey,brown" |
| 65 | text e4 "680 ohms" |
| 66 | text c5 "label: Blue and grey and brown" |
| 67 | text s6 "red,black,red" |
| 68 | text e7 "2 kiloohms" |
| 69 | text c8 "label: Red and black and red" |
| 70 | text s9 "green,brown,orange" |
| 71 | text e10 "51 kiloohms" |
| 72 | text c11 "label: Green and brown and orange" |
| 73 | text s12 "yellow,violet,yellow" |
| 74 | text e13 "470 kiloohms" |
| 75 | text c14 "label: Yellow and violet and yellow" |
| 76 | text s15 "blue,violet,blue" |
| 77 | text e16 "67 megaohms" |
| 78 | text c17 "label: Blue and violet and blue" |
| 79 | text s18 "black,black,black" |
| 80 | text e19 "0 ohms" |
| 81 | text c20 "label: Minimum possible value" |
| 82 | text s21 "white,white,white" |
| 83 | text e22 "99 gigaohms" |
| 84 | text c23 "label: Maximum possible value" |
| 85 | text s24 "black,grey,black" |
| 86 | text e25 "8 ohms" |
| 87 | text c26 "label: First two colors make an invalid octal number" |
| 88 | text s27 "blue,green,yellow,orange" |
| 89 | text e28 "650 kiloohms" |
| 90 | text c29 "label: Ignore extra colors" |
| 91 | note canonical case d6863355-15b7-40bb-abe0-bfb1a25512ed |
| 92 | fn tc0 to bool |
| 93 | o = new uchar 1024 0 |
| 94 | n = label s0 o |
| 95 | ret tbeq part o 0 n e1 |
| 96 | end |
| 97 | note canonical case 1224a3a9-8c8e-4032-843a-5224e04647d6 |
| 98 | fn tc1 to bool |
| 99 | o = new uchar 1024 0 |
| 100 | n = label s3 o |
| 101 | ret tbeq part o 0 n e4 |
| 102 | end |
| 103 | note canonical case b8bda7dc-6b95-4539-abb2-2ad51d66a207 |
| 104 | fn tc2 to bool |
| 105 | o = new uchar 1024 0 |
| 106 | n = label s6 o |
| 107 | ret tbeq part o 0 n e7 |
| 108 | end |
| 109 | note canonical case 5b1e74bc-d838-4eda-bbb3-eaba988e733b |
| 110 | fn tc3 to bool |
| 111 | o = new uchar 1024 0 |
| 112 | n = label s9 o |
| 113 | ret tbeq part o 0 n e10 |
| 114 | end |
| 115 | note canonical case f5d37ef9-1919-4719-a90d-a33c5a6934c9 |
| 116 | fn tc4 to bool |
| 117 | o = new uchar 1024 0 |
| 118 | n = label s12 o |
| 119 | ret tbeq part o 0 n e13 |
| 120 | end |
| 121 | note canonical case 5f6404a7-5bb3-4283-877d-3d39bcc33854 |
| 122 | fn tc5 to bool |
| 123 | o = new uchar 1024 0 |
| 124 | n = label s15 o |
| 125 | ret tbeq part o 0 n e16 |
| 126 | end |
| 127 | note canonical case 7d3a6ab8-e40e-46c3-98b1-91639fff2344 |
| 128 | fn tc6 to bool |
| 129 | o = new uchar 1024 0 |
| 130 | n = label s18 o |
| 131 | ret tbeq part o 0 n e19 |
| 132 | end |
| 133 | note canonical case ca0aa0ac-3825-42de-9f07-dac68cc580fd |
| 134 | fn tc7 to bool |
| 135 | o = new uchar 1024 0 |
| 136 | n = label s21 o |
| 137 | ret tbeq part o 0 n e22 |
| 138 | end |
| 139 | note canonical case 0061a76c-903a-4714-8ce2-f26ce23b0e09 |
| 140 | fn tc8 to bool |
| 141 | o = new uchar 1024 0 |
| 142 | n = label s24 o |
| 143 | ret tbeq part o 0 n e25 |
| 144 | end |
| 145 | note canonical case 30872c92-f567-4b69-a105-8455611c10c4 |
| 146 | fn tc9 to bool |
| 147 | o = new uchar 1024 0 |
| 148 | n = label s27 o |
| 149 | ret tbeq part o 0 n e28 |
| 150 | end |
| 151 | fn main to int |
| 152 | tcheck tc0 c2 |
| 153 | tcheck tc1 c5 |
| 154 | tcheck tc2 c8 |
| 155 | tcheck tc3 c11 |
| 156 | tcheck tc4 c14 |
| 157 | tcheck tc5 c17 |
| 158 | tcheck tc6 c20 |
| 159 | tcheck tc7 c23 |
| 160 | tcheck tc8 c26 |
| 161 | tcheck tc9 c29 |
| 162 | ret int get tfails 0 |
| 163 | end |