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
omega-mv / protocol / omnet / om / quantity / tests.om
| 1 | note Concatenate quantity.om then tests.om. Wider signed oracle has no quantity guard. |
| 2 | text tadd "FAIL Q1_ADD_GUARD\n" |
| 3 | text tmul "FAIL Q4_MUL_GUARD\n" |
| 4 | text tedge "FAIL Q3_Q5_Q6_Q9_EDGES\n" |
| 5 | text tslc "FAIL Q7_Q9_SLICE\n" |
| 6 | text texh "FAIL Q2_EXACT_ORACLE\n" |
| 7 | text tpass "PASS Q1-Q9 runtime; Q2 widths1..8 pairs87380 operations262140\n" |
| 8 | |
| 9 | fn qsent out edit qty to void |
| 10 | put out val ulong 17 |
| 11 | put out cap ulong 19 |
| 12 | end |
| 13 | |
| 14 | fn qcheck out view qty rc int want int value ulong cap ulong to bool |
| 15 | if ne rc want |
| 16 | ret bool 0 |
| 17 | end |
| 18 | if ne get out val value |
| 19 | ret bool 0 |
| 20 | end |
| 21 | ret eq get out cap cap |
| 22 | end |
| 23 | |
| 24 | fn testadd to bool |
| 25 | out = new qty ulong 17 ulong 19 |
| 26 | a = new qty ulong 18446744073709551608 ulong 18446744073709551615 |
| 27 | b = new qty ulong 16 ulong 18446744073709551615 |
| 28 | if ne add get a val get b val ulong 8 |
| 29 | ret bool 0 |
| 30 | end |
| 31 | rc = qadd out a b |
| 32 | ret qcheck out rc int 3 ulong 17 ulong 19 |
| 33 | end |
| 34 | |
| 35 | fn testmul to bool |
| 36 | out = new qty ulong 17 ulong 19 |
| 37 | a = new qty ulong 18446744073709551615 ulong 18446744073709551615 |
| 38 | b = new qty ulong 2 ulong 18446744073709551615 |
| 39 | rc = qmul out a b |
| 40 | if not qcheck out rc int 3 ulong 17 ulong 19 |
| 41 | ret bool 0 |
| 42 | end |
| 43 | put a val ulong 4294967296 |
| 44 | put b val ulong 4294967296 |
| 45 | rc = qmul out a b |
| 46 | if not qcheck out rc int 3 ulong 17 ulong 19 |
| 47 | ret bool 0 |
| 48 | end |
| 49 | put a val ulong 4294967297 |
| 50 | put b val ulong 4294967297 |
| 51 | rc = qmul out a b |
| 52 | if not qcheck out rc int 3 ulong 17 ulong 19 |
| 53 | ret bool 0 |
| 54 | end |
| 55 | put a val ulong 4294967295 |
| 56 | put b val ulong 4294967295 |
| 57 | rc = qmul out a b |
| 58 | if not qcheck out rc int 0 ulong 18446744065119617025 ulong 18446744073709551615 |
| 59 | ret bool 0 |
| 60 | end |
| 61 | qsent out |
| 62 | put a val ulong 0 |
| 63 | put b val ulong 18446744073709551615 |
| 64 | rc = qmul out a b |
| 65 | ret qcheck out rc int 0 ulong 0 ulong 18446744073709551615 |
| 66 | end |
| 67 | |
| 68 | fn edges to bool |
| 69 | out = new qty ulong 17 ulong 19 |
| 70 | a = new qty ulong 18446744073709551615 ulong 18446744073709551615 |
| 71 | b = new qty ulong 0 ulong 18446744073709551615 |
| 72 | rc = qnext out a |
| 73 | if not qcheck out rc int 3 ulong 17 ulong 19 |
| 74 | ret bool 0 |
| 75 | end |
| 76 | rc = qsigned out long -1 ulong 18446744073709551615 |
| 77 | if not qcheck out rc int 2 ulong 17 ulong 19 |
| 78 | ret bool 0 |
| 79 | end |
| 80 | rc = qword out ulong 1 ulong 0 |
| 81 | if not qcheck out rc int 3 ulong 17 ulong 19 |
| 82 | ret bool 0 |
| 83 | end |
| 84 | rc = qmul out a b |
| 85 | if not qcheck out rc int 0 ulong 0 ulong 18446744073709551615 |
| 86 | ret bool 0 |
| 87 | end |
| 88 | qsent out |
| 89 | rc = qadd out a b |
| 90 | if not qcheck out rc int 0 ulong 18446744073709551615 ulong 18446744073709551615 |
| 91 | ret bool 0 |
| 92 | end |
| 93 | qsent out |
| 94 | rc = qsub out b a |
| 95 | if not qcheck out rc int 3 ulong 17 ulong 19 |
| 96 | ret bool 0 |
| 97 | end |
| 98 | rc = qsigned out long 9223372036854775807 ulong 18446744073709551615 |
| 99 | if not qcheck out rc int 0 ulong 9223372036854775807 ulong 18446744073709551615 |
| 100 | ret bool 0 |
| 101 | end |
| 102 | qsent out |
| 103 | put a val ulong 256 |
| 104 | rc = qnarrow out a ulong 255 |
| 105 | if not qcheck out rc int 3 ulong 17 ulong 19 |
| 106 | ret bool 0 |
| 107 | end |
| 108 | put a val ulong 255 |
| 109 | rc = qnarrow out a ulong 255 |
| 110 | if not qcheck out rc int 0 ulong 255 ulong 255 |
| 111 | ret bool 0 |
| 112 | end |
| 113 | qsent out |
| 114 | put a cap ulong 255 |
| 115 | rc = qnarrow out a ulong 256 |
| 116 | if not qcheck out rc int 2 ulong 17 ulong 19 |
| 117 | ret bool 0 |
| 118 | end |
| 119 | rc = qadd out a b |
| 120 | if not qcheck out rc int 2 ulong 17 ulong 19 |
| 121 | ret bool 0 |
| 122 | end |
| 123 | rc = qsub out a b |
| 124 | if not qcheck out rc int 2 ulong 17 ulong 19 |
| 125 | ret bool 0 |
| 126 | end |
| 127 | rc = qmul out a b |
| 128 | if not qcheck out rc int 2 ulong 17 ulong 19 |
| 129 | ret bool 0 |
| 130 | end |
| 131 | put a val ulong 256 |
| 132 | rc = qadd out a b |
| 133 | if not qcheck out rc int 1 ulong 17 ulong 19 |
| 134 | ret bool 0 |
| 135 | end |
| 136 | rc = qsub out b a |
| 137 | if not qcheck out rc int 1 ulong 17 ulong 19 |
| 138 | ret bool 0 |
| 139 | end |
| 140 | rc = qmul out a b |
| 141 | if not qcheck out rc int 1 ulong 17 ulong 19 |
| 142 | ret bool 0 |
| 143 | end |
| 144 | rc = qnarrow out a ulong 0 |
| 145 | if not qcheck out rc int 1 ulong 17 ulong 19 |
| 146 | ret bool 0 |
| 147 | end |
| 148 | rc = qnext out a |
| 149 | ret qcheck out rc int 1 ulong 17 ulong 19 |
| 150 | end |
| 151 | |
| 152 | fn sexpect out view qslic rc int want int to bool |
| 153 | if ne rc want |
| 154 | ret bool 0 |
| 155 | end |
| 156 | if ne get out ident ulong 91 |
| 157 | ret bool 0 |
| 158 | end |
| 159 | if ne get out ver ulong 92 |
| 160 | ret bool 0 |
| 161 | end |
| 162 | if ne get out off ulong 93 |
| 163 | ret bool 0 |
| 164 | end |
| 165 | ret eq get out count ulong 94 |
| 166 | end |
| 167 | |
| 168 | fn slices to bool |
| 169 | out = new qslic ulong 91 ulong 92 ulong 93 ulong 94 |
| 170 | off = new qty ulong 6 ulong 8 |
| 171 | count = new qty ulong 3 ulong 8 |
| 172 | expect = new qobj ulong 5 ulong 7 ulong 8 |
| 173 | current = new qobj ulong 5 ulong 7 ulong 8 |
| 174 | rc = qtyslice out off count expect current |
| 175 | if not sexpect out rc int 3 |
| 176 | ret bool 0 |
| 177 | end |
| 178 | put expect ver ulong 6 |
| 179 | rc = qtyslice out off count expect current |
| 180 | if not sexpect out rc int 4 |
| 181 | ret bool 0 |
| 182 | end |
| 183 | put expect ver ulong 7 |
| 184 | put expect ident ulong 4 |
| 185 | rc = qtyslice out off count expect current |
| 186 | if not sexpect out rc int 4 |
| 187 | ret bool 0 |
| 188 | end |
| 189 | put expect ident ulong 5 |
| 190 | put expect extent ulong 7 |
| 191 | rc = qtyslice out off count expect current |
| 192 | if not sexpect out rc int 4 |
| 193 | ret bool 0 |
| 194 | end |
| 195 | put expect extent ulong 8 |
| 196 | put off cap ulong 9 |
| 197 | rc = qtyslice out off count expect current |
| 198 | if not sexpect out rc int 2 |
| 199 | ret bool 0 |
| 200 | end |
| 201 | put count cap ulong 9 |
| 202 | rc = qtyslice out off count expect current |
| 203 | if not sexpect out rc int 2 |
| 204 | ret bool 0 |
| 205 | end |
| 206 | put off val ulong 10 |
| 207 | rc = qtyslice out off count expect current |
| 208 | if not sexpect out rc int 1 |
| 209 | ret bool 0 |
| 210 | end |
| 211 | put off val ulong 6 |
| 212 | put off cap ulong 8 |
| 213 | put count cap ulong 8 |
| 214 | put count val ulong 2 |
| 215 | rc = qtyslice out off count expect current |
| 216 | if ne rc int 0 |
| 217 | ret bool 0 |
| 218 | end |
| 219 | if ne get out ident ulong 5 |
| 220 | ret bool 0 |
| 221 | end |
| 222 | if ne get out ver ulong 7 |
| 223 | ret bool 0 |
| 224 | end |
| 225 | if ne get out off ulong 6 |
| 226 | ret bool 0 |
| 227 | end |
| 228 | if ne get out count ulong 2 |
| 229 | ret bool 0 |
| 230 | end |
| 231 | put off val ulong 8 |
| 232 | put count val ulong 0 |
| 233 | rc = qtyslice out off count expect current |
| 234 | if ne rc int 0 |
| 235 | ret bool 0 |
| 236 | end |
| 237 | if ne get out off ulong 8 |
| 238 | ret bool 0 |
| 239 | end |
| 240 | if ne get out count ulong 0 |
| 241 | ret bool 0 |
| 242 | end |
| 243 | put off val ulong 0 |
| 244 | put off cap ulong 0 |
| 245 | put count cap ulong 0 |
| 246 | put current extent ulong 0 |
| 247 | put expect extent ulong 0 |
| 248 | rc = qtyslice out off count expect current |
| 249 | ret eq rc int 0 |
| 250 | end |
| 251 | |
| 252 | note Oracle uses signed 64-bit exact arithmetic only on operands0..255. |
| 253 | note Its results are at most65025; it neither uses nor repeats the guarded algorithms. |
| 254 | fn oracle out view qty rc int exact long cap ulong to bool |
| 255 | if or lt exact long 0 gt exact long cap |
| 256 | ret qcheck out rc int 3 ulong 17 ulong 19 |
| 257 | end |
| 258 | ret qcheck out rc int 0 ulong exact cap |
| 259 | end |
| 260 | |
| 261 | fn pairs cap ulong to bool |
| 262 | out = new qty ulong 17 ulong 19 |
| 263 | a = new qty ulong 0 cap |
| 264 | b = new qty ulong 0 cap |
| 265 | rc = int 0 |
| 266 | for x ulong add cap ulong 1 |
| 267 | put a val x |
| 268 | for y ulong add cap ulong 1 |
| 269 | put b val y |
| 270 | qsent out |
| 271 | rc = qadd out a b |
| 272 | if not oracle out rc add long x long y cap |
| 273 | ret bool 0 |
| 274 | end |
| 275 | qsent out |
| 276 | rc = qsub out a b |
| 277 | if not oracle out rc sub long x long y cap |
| 278 | ret bool 0 |
| 279 | end |
| 280 | qsent out |
| 281 | rc = qmul out a b |
| 282 | if not oracle out rc mul long x long y cap |
| 283 | ret bool 0 |
| 284 | end |
| 285 | end |
| 286 | end |
| 287 | ret bool 1 |
| 288 | end |
| 289 | |
| 290 | fn unary cap ulong to bool |
| 291 | out = new qty ulong 17 ulong 19 |
| 292 | a = new qty ulong 0 cap |
| 293 | rc = int 0 |
| 294 | for x ulong add cap ulong 1 |
| 295 | qsent out |
| 296 | rc = qword out x cap |
| 297 | if not qcheck out rc int 0 x cap |
| 298 | ret bool 0 |
| 299 | end |
| 300 | qsent out |
| 301 | rc = qsigned out long x cap |
| 302 | if not qcheck out rc int 0 x cap |
| 303 | ret bool 0 |
| 304 | end |
| 305 | qsent out |
| 306 | put a val x |
| 307 | rc = qnext out a |
| 308 | if not oracle out rc add long x long 1 cap |
| 309 | ret bool 0 |
| 310 | end |
| 311 | for y ulong add cap ulong 1 |
| 312 | qsent out |
| 313 | rc = qnarrow out a y |
| 314 | if not oracle out rc long x y |
| 315 | ret bool 0 |
| 316 | end |
| 317 | end |
| 318 | end |
| 319 | qsent out |
| 320 | rc = qword out add cap ulong 1 cap |
| 321 | ret qcheck out rc int 3 ulong 17 ulong 19 |
| 322 | end |
| 323 | |
| 324 | fn main to int |
| 325 | n = long 0 |
| 326 | if not testadd |
| 327 | n = write int 1 tadd ulong 0 len tadd |
| 328 | ret int sub n sub n long 1 |
| 329 | end |
| 330 | if not testmul |
| 331 | n = write int 1 tmul ulong 0 len tmul |
| 332 | ret int sub n sub n long 1 |
| 333 | end |
| 334 | if not edges |
| 335 | n = write int 1 tedge ulong 0 len tedge |
| 336 | ret int sub n sub n long 1 |
| 337 | end |
| 338 | if not slices |
| 339 | n = write int 1 tslc ulong 0 len tslc |
| 340 | ret int sub n sub n long 1 |
| 341 | end |
| 342 | if not unary ulong 0 |
| 343 | n = write int 1 texh ulong 0 len texh |
| 344 | ret int sub n sub n long 1 |
| 345 | end |
| 346 | for w ulong 8 |
| 347 | if not unary sub shl ulong 1 add w ulong 1 ulong 1 |
| 348 | n = write int 1 texh ulong 0 len texh |
| 349 | ret int sub n sub n long 1 |
| 350 | end |
| 351 | if not pairs sub shl ulong 1 add w ulong 1 ulong 1 |
| 352 | n = write int 1 texh ulong 0 len texh |
| 353 | ret int sub n sub n long 1 |
| 354 | end |
| 355 | end |
| 356 | n = write int 1 tpass ulong 0 len tpass |
| 357 | ret int sub n n |
| 358 | end |