omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / exercises / secret-handshake / 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/secret-handshake/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 e0 "wink" |
| 62 | text c1 "commands: wink for 1" |
| 63 | text e2 "double blink" |
| 64 | text c3 "commands: double blink for 10" |
| 65 | text e4 "close your eyes" |
| 66 | text c5 "commands: close your eyes for 100" |
| 67 | text e6 "jump" |
| 68 | text c7 "commands: jump for 1000" |
| 69 | text e8 "wink,double blink" |
| 70 | text c9 "commands: combine two actions" |
| 71 | text e10 "double blink,wink" |
| 72 | text c11 "commands: reverse two actions" |
| 73 | text e12 "jump" |
| 74 | text c13 "commands: reversing one action gives the same action" |
| 75 | text c14 "commands: reversing no actions still gives no actions" |
| 76 | text e15 "wink,double blink,close your eyes,jump" |
| 77 | text c16 "commands: all possible actions" |
| 78 | text e17 "jump,close your eyes,double blink,wink" |
| 79 | text c18 "commands: reverse all possible actions" |
| 80 | text c19 "commands: do nothing for zero" |
| 81 | note canonical case b8496fbd-6778-468c-8054-648d03c4bb23 |
| 82 | fn tc0 to bool |
| 83 | o = new uchar 1024 0 |
| 84 | n = commands 1 o |
| 85 | ret tbeq part o 0 n e0 |
| 86 | end |
| 87 | note canonical case 83ec6c58-81a9-4fd1-bfaf-0160514fc0e3 |
| 88 | fn tc1 to bool |
| 89 | o = new uchar 1024 0 |
| 90 | n = commands 2 o |
| 91 | ret tbeq part o 0 n e2 |
| 92 | end |
| 93 | note canonical case 0e20e466-3519-4134-8082-5639d85fef71 |
| 94 | fn tc2 to bool |
| 95 | o = new uchar 1024 0 |
| 96 | n = commands 4 o |
| 97 | ret tbeq part o 0 n e4 |
| 98 | end |
| 99 | note canonical case b339ddbb-88b7-4b7d-9b19-4134030d9ac0 |
| 100 | fn tc3 to bool |
| 101 | o = new uchar 1024 0 |
| 102 | n = commands 8 o |
| 103 | ret tbeq part o 0 n e6 |
| 104 | end |
| 105 | note canonical case 40499fb4-e60c-43d7-8b98-0de3ca44e0eb |
| 106 | fn tc4 to bool |
| 107 | o = new uchar 1024 0 |
| 108 | n = commands 3 o |
| 109 | ret tbeq part o 0 n e8 |
| 110 | end |
| 111 | note canonical case 9730cdd5-ef27-494b-afd3-5c91ad6c3d9d |
| 112 | fn tc5 to bool |
| 113 | o = new uchar 1024 0 |
| 114 | n = commands 19 o |
| 115 | ret tbeq part o 0 n e10 |
| 116 | end |
| 117 | note canonical case 0b828205-51ca-45cd-90d5-f2506013f25f |
| 118 | fn tc6 to bool |
| 119 | o = new uchar 1024 0 |
| 120 | n = commands 24 o |
| 121 | ret tbeq part o 0 n e12 |
| 122 | end |
| 123 | note canonical case 9949e2ac-6c9c-4330-b685-2089ab28b05f |
| 124 | fn tc7 to bool |
| 125 | o = new uchar 1024 0 |
| 126 | n = commands 16 o |
| 127 | ret eq n 0 |
| 128 | end |
| 129 | note canonical case 23fdca98-676b-4848-970d-cfed7be39f81 |
| 130 | fn tc8 to bool |
| 131 | o = new uchar 1024 0 |
| 132 | n = commands 15 o |
| 133 | ret tbeq part o 0 n e15 |
| 134 | end |
| 135 | note canonical case ae8fe006-d910-4d6f-be00-54b7c3799e79 |
| 136 | fn tc9 to bool |
| 137 | o = new uchar 1024 0 |
| 138 | n = commands 31 o |
| 139 | ret tbeq part o 0 n e17 |
| 140 | end |
| 141 | note canonical case 3d36da37-b31f-4cdb-a396-d93a2ee1c4a5 |
| 142 | fn tc10 to bool |
| 143 | o = new uchar 1024 0 |
| 144 | n = commands 0 o |
| 145 | ret eq n 0 |
| 146 | end |
| 147 | fn main to int |
| 148 | tcheck tc0 c1 |
| 149 | tcheck tc1 c3 |
| 150 | tcheck tc2 c5 |
| 151 | tcheck tc3 c7 |
| 152 | tcheck tc4 c9 |
| 153 | tcheck tc5 c11 |
| 154 | tcheck tc6 c13 |
| 155 | tcheck tc7 c14 |
| 156 | tcheck tc8 c16 |
| 157 | tcheck tc9 c18 |
| 158 | tcheck tc10 c19 |
| 159 | ret int get tfails 0 |
| 160 | end |