Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/si/rosetta/exercises/knapsack/test.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / si / rosetta / exercises / knapsack / test.om` 184 lines ยท 3496 bytes Raw Blame History 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/knapsack/canonical-data.json at 47 note commit `650bebeb39ad40439175288042aece982b0a90a9` (2026-10-19), MIT licence, 48 note https://github.com/exercism/problem-specifications 49 note 7 cases kept, 0 skipped, 1 superseded (reimplemented) cases omitted 50 text c0 "maximumValue: no items" 51 text c1 "maximumValue: one item, too heavy" 52 text c2 "maximumValue: five items (cannot be greedy by weight)" 53 text c3 "maximumValue: five items (cannot be greedy by value)" 54 text c4 "maximumValue: example knapsack" 55 text c5 "maximumValue: 8 items" 56 text c6 "maximumValue: 15 items" 57 note canonical case `3993a824`-c20e-493d-b3c9-`ee8a7753ee59` 58 fn tc0 to bool 59 a0 = new ulong 1 0 60 a1 = new ulong 1 0 61 ret eq maximumvalue part a0 0 0 part a1 0 0 100 0 62 end 63 note canonical case `1d39e98c`-6249-4a8b-912f-`87cb12e506b0` 64 fn tc1 to bool 65 a0 = new ulong 1 0 66 put a0 0 100 67 a1 = new ulong 1 0 68 put a1 0 1 69 ret eq maximumvalue a0 a1 10 0 70 end 71 note canonical case `833ea310`-6323-44f2-9d27-`a278740ffbd8` 72 fn tc2 to bool 73 a0 = new ulong 5 0 74 put a0 0 2 75 put a0 1 2 76 put a0 2 2 77 put a0 3 2 78 put a0 4 10 79 a1 = new ulong 5 0 80 put a1 0 5 81 put a1 1 5 82 put a1 2 5 83 put a1 3 5 84 put a1 4 21 85 ret eq maximumvalue a0 a1 10 21 86 end 87 note canonical case `277cdc52`-f835-4c7d-872b-`bff17bab2456` 88 fn tc3 to bool 89 a0 = new ulong 5 0 90 put a0 0 2 91 put a0 1 2 92 put a0 2 2 93 put a0 3 2 94 put a0 4 10 95 a1 = new ulong 5 0 96 put a1 0 20 97 put a1 1 20 98 put a1 2 20 99 put a1 3 20 100 put a1 4 50 101 ret eq maximumvalue a0 a1 10 80 102 end 103 note canonical case `81d8e679`-442b-4f7a-8a59-`7278083916c9` 104 fn tc4 to bool 105 a0 = new ulong 4 0 106 put a0 0 5 107 put a0 1 4 108 put a0 2 6 109 put a0 3 4 110 a1 = new ulong 4 0 111 put a1 0 10 112 put a1 1 40 113 put a1 2 30 114 put a1 3 50 115 ret eq maximumvalue a0 a1 10 90 116 end 117 note canonical case `f23a2449`-d67c-4c26-bf3e-`cde020f27ecc` 118 fn tc5 to bool 119 a0 = new ulong 8 0 120 put a0 0 25 121 put a0 1 35 122 put a0 2 45 123 put a0 3 5 124 put a0 4 25 125 put a0 5 3 126 put a0 6 2 127 put a0 7 2 128 a1 = new ulong 8 0 129 put a1 0 350 130 put a1 1 400 131 put a1 2 450 132 put a1 3 20 133 put a1 4 70 134 put a1 5 8 135 put a1 6 5 136 put a1 7 5 137 ret eq maximumvalue a0 a1 104 900 138 end 139 note canonical case `7c682ae9`-c385-4241-a197-`d2fa02c81a11` 140 fn tc6 to bool 141 a0 = new ulong 15 0 142 put a0 0 70 143 put a0 1 73 144 put a0 2 77 145 put a0 3 80 146 put a0 4 82 147 put a0 5 87 148 put a0 6 90 149 put a0 7 94 150 put a0 8 98 151 put a0 9 106 152 put a0 10 110 153 put a0 11 113 154 put a0 12 115 155 put a0 13 118 156 put a0 14 120 157 a1 = new ulong 15 0 158 put a1 0 135 159 put a1 1 139 160 put a1 2 149 161 put a1 3 150 162 put a1 4 156 163 put a1 5 163 164 put a1 6 173 165 put a1 7 184 166 put a1 8 192 167 put a1 9 201 168 put a1 10 210 169 put a1 11 214 170 put a1 12 221 171 put a1 13 229 172 put a1 14 240 173 ret eq maximumvalue a0 a1 750 1458 174 end 175 fn main to int 176 tcheck tc0 c0 177 tcheck tc1 c1 178 tcheck tc2 c2 179 tcheck tc3 c3 180 tcheck tc4 c4 181 tcheck tc5 c5 182 tcheck tc6 c6 183 ret int get tfails 0 184 end