From bd6b2641ddbcc2b80ea5ded646754a614e7a4205 Mon Sep 17 00:00:00 2001 From: d_m Date: Sat, 10 Sep 2022 13:38:22 -0400 Subject: [PATCH] fix math32 tests --- test-math32.py | 19 +++++++++++-------- test-math32.tal | 48 ++++++++++++++++++++++++------------------------ 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/test-math32.py b/test-math32.py index c3bb331..160bd68 100644 --- a/test-math32.py +++ b/test-math32.py @@ -5,6 +5,7 @@ from os import environ from random import randint from subprocess import Popen, PIPE, run +u1 = {'sz': 1, 'fmt': b'%02x'} u3 = {'sz': 1 << 3, 'fmt': b'%02x'} u5 = {'sz': 1 << 5, 'fmt': b'%02x'} u8 = {'sz': 1 << 8, 'fmt': b'%02x'} @@ -28,6 +29,8 @@ def testcase(p, sym, args, out, f): expected = fmt(out, z) if got == expected: return None + elif out == u1 and bool(got) == bool(expected): + return None else: res = {'got': got, 'expected': expected} for name, _, x in vals: @@ -76,14 +79,14 @@ def main(): test(p, trials, b'^', [('x', u32), ('y', u32)], u32, lambda x, y: x ^ y) test(p, trials, b'~', [('x', u32)], u32, lambda x: ~x) test(p, trials, b'N', [('x', u32)], u32, lambda x: -x) - test(p, trials, b'=', [('x', u32), ('y', u32)], u8, lambda x, y: int(x == y)) - test(p, trials, b'!', [('x', u32), ('y', u32)], u8, lambda x, y: int(x != y)) - test(p, trials, b'0', [('x', u32)], u8, lambda x: int(x == 0)) - test(p, trials, b'Z', [('x', u32)], u8, lambda x: int(x != 0)) - test(p, trials, b'<', [('x', u32), ('y', u32)], u8, lambda x, y: int(x < y)) - test(p, trials, b'>', [('x', u32), ('y', u32)], u8, lambda x, y: int(x > y)) - test(p, trials, b'{', [('x', u32), ('y', u32)], u8, lambda x, y: int(x <= y)) - test(p, trials, b'}', [('x', u32), ('y', u32)], u8, lambda x, y: int(x >= y)) + test(p, trials, b'=', [('x', u32), ('y', u32)], u1, lambda x, y: int(x == y)) + test(p, trials, b'!', [('x', u32), ('y', u32)], u1, lambda x, y: int(x != y)) + test(p, trials, b'0', [('x', u32)], u1, lambda x: int(x == 0)) + test(p, trials, b'Z', [('x', u32)], u1, lambda x: int(x != 0)) + test(p, trials, b'<', [('x', u32), ('y', u32)], u1, lambda x, y: int(x < y)) + test(p, trials, b'>', [('x', u32), ('y', u32)], u1, lambda x, y: int(x > y)) + test(p, trials, b'{', [('x', u32), ('y', u32)], u1, lambda x, y: int(x <= y)) + test(p, trials, b'}', [('x', u32), ('y', u32)], u1, lambda x, y: int(x >= y)) p.stdin.close() p.stdout.close() p.kill() diff --git a/test-math32.tal b/test-math32.tal index 284d658..6fc498b 100644 --- a/test-math32.tal +++ b/test-math32.tal @@ -46,29 +46,29 @@ JMP2r ;pos LDA2k INC2 SWP2 STA2 BRK &exec POP ( ) - ;buf LDA LIT '+ EQU ;test-add32 JCN2 - ;buf LDA LIT '* EQU ;test-mul32 JCN2 - ;buf LDA LIT '- EQU ;test-sub32 JCN2 - ;buf LDA LIT '/ EQU ;test-div32 JCN2 - ;buf LDA LIT '% EQU ;test-mod32 JCN2 - ;buf LDA LIT 'G EQU ;test-gcd32 JCN2 - ;buf LDA LIT 'L EQU ;test-lshift32 JCN2 - ;buf LDA LIT 'R EQU ;test-rshift32 JCN2 - ;buf LDA LIT 'B EQU ;test-bitcount32 JCN2 - ;buf LDA LIT '& EQU ;test-and32 JCN2 - ;buf LDA LIT '| EQU ;test-or32 JCN2 - ;buf LDA LIT '^ EQU ;test-xor32 JCN2 - ;buf LDA LIT '~ EQU ;test-complement32 JCN2 - ;buf LDA LIT 'N EQU ;test-negate32 JCN2 - ;buf LDA LIT '= EQU ;test-eq32 JCN2 - ;buf LDA LIT '! EQU ;test-ne32 JCN2 - ;buf LDA LIT '0 EQU ;test-is-zero32 JCN2 - ;buf LDA LIT 'Z EQU ;test-non-zero32 JCN2 - ;buf LDA LIT '< EQU ;test-lt32 JCN2 - ;buf LDA LIT '> EQU ;test-gt32 JCN2 - ;buf LDA LIT '{ EQU ;test-lteq32 JCN2 - ;buf LDA LIT '} EQU ;test-gteq32 JCN2 - LIT '? EMIT NEWLINE RESET-POS BRK + ;buf LDA LIT "+ EQU ;test-add32 JCN2 + ;buf LDA LIT "* EQU ;test-mul32 JCN2 + ;buf LDA LIT "- EQU ;test-sub32 JCN2 + ;buf LDA LIT "/ EQU ;test-div32 JCN2 + ;buf LDA LIT "% EQU ;test-mod32 JCN2 + ;buf LDA LIT "G EQU ;test-gcd32 JCN2 + ;buf LDA LIT "L EQU ;test-lshift32 JCN2 + ;buf LDA LIT "R EQU ;test-rshift32 JCN2 + ;buf LDA LIT "B EQU ;test-bitcount32 JCN2 + ;buf LDA LIT "& EQU ;test-and32 JCN2 + ;buf LDA LIT "| EQU ;test-or32 JCN2 + ;buf LDA LIT "^ EQU ;test-xor32 JCN2 + ;buf LDA LIT "~ EQU ;test-complement32 JCN2 + ;buf LDA LIT "N EQU ;test-negate32 JCN2 + ;buf LDA LIT "= EQU ;test-eq32 JCN2 + ;buf LDA LIT "! EQU ;test-ne32 JCN2 + ;buf LDA LIT "0 EQU ;test-is-zero32 JCN2 + ;buf LDA LIT "Z EQU ;test-non-zero32 JCN2 + ;buf LDA LIT "< EQU ;test-lt32 JCN2 + ;buf LDA LIT "> EQU ;test-gt32 JCN2 + ;buf LDA LIT "{ EQU ;test-lteq32 JCN2 + ;buf LDA LIT "} EQU ;test-gteq32 JCN2 + LIT "? EMIT NEWLINE RESET-POS BRK @read-byte ( addr* -> x^ ) LDA2 ;parse-byte JSR2 @@ -107,7 +107,7 @@ JMP2r ;buf #0002 ADD2 ;read-long JSR2 ROT2 ;buf #000b ADD2 ;read-byte JSR2 - TOR JSR2 ;emit/long JSR2 + ROT ROT JSR2 ;emit/long JSR2 NEWLINE RESET-POS BRK ( format: ". xxxxxxxx yyyyyyyy" -> "zz" )