fix math32 tests

This commit is contained in:
~d6 2022-09-10 13:38:22 -04:00
parent 8d7a1675f8
commit bd6b2641dd
2 changed files with 35 additions and 32 deletions

View File

@ -5,6 +5,7 @@ from os import environ
from random import randint from random import randint
from subprocess import Popen, PIPE, run from subprocess import Popen, PIPE, run
u1 = {'sz': 1, 'fmt': b'%02x'}
u3 = {'sz': 1 << 3, 'fmt': b'%02x'} u3 = {'sz': 1 << 3, 'fmt': b'%02x'}
u5 = {'sz': 1 << 5, 'fmt': b'%02x'} u5 = {'sz': 1 << 5, 'fmt': b'%02x'}
u8 = {'sz': 1 << 8, '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) expected = fmt(out, z)
if got == expected: if got == expected:
return None return None
elif out == u1 and bool(got) == bool(expected):
return None
else: else:
res = {'got': got, 'expected': expected} res = {'got': got, 'expected': expected}
for name, _, x in vals: 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), ('y', u32)], u32, lambda x, y: x ^ y)
test(p, trials, b'~', [('x', u32)], u32, lambda x: ~x) 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'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)], u1, 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'0', [('x', u32)], u8, lambda x: int(x == 0)) test(p, trials, b'0', [('x', u32)], u1, lambda x: int(x == 0))
test(p, trials, b'Z', [('x', u32)], u8, 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)], 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)], 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)], 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)], u8, 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.stdin.close()
p.stdout.close() p.stdout.close()
p.kill() p.kill()

View File

@ -46,29 +46,29 @@ JMP2r
;pos LDA2k INC2 SWP2 STA2 BRK ;pos LDA2k INC2 SWP2 STA2 BRK
&exec &exec
POP ( ) POP ( )
;buf LDA LIT '+ EQU ;test-add32 JCN2 ;buf LDA LIT "+ EQU ;test-add32 JCN2
;buf LDA LIT '* EQU ;test-mul32 JCN2 ;buf LDA LIT "* EQU ;test-mul32 JCN2
;buf LDA LIT '- EQU ;test-sub32 JCN2 ;buf LDA LIT "- EQU ;test-sub32 JCN2
;buf LDA LIT '/ EQU ;test-div32 JCN2 ;buf LDA LIT "/ EQU ;test-div32 JCN2
;buf LDA LIT '% EQU ;test-mod32 JCN2 ;buf LDA LIT "% EQU ;test-mod32 JCN2
;buf LDA LIT 'G EQU ;test-gcd32 JCN2 ;buf LDA LIT "G EQU ;test-gcd32 JCN2
;buf LDA LIT 'L EQU ;test-lshift32 JCN2 ;buf LDA LIT "L EQU ;test-lshift32 JCN2
;buf LDA LIT 'R EQU ;test-rshift32 JCN2 ;buf LDA LIT "R EQU ;test-rshift32 JCN2
;buf LDA LIT 'B EQU ;test-bitcount32 JCN2 ;buf LDA LIT "B EQU ;test-bitcount32 JCN2
;buf LDA LIT '& EQU ;test-and32 JCN2 ;buf LDA LIT "& EQU ;test-and32 JCN2
;buf LDA LIT '| EQU ;test-or32 JCN2 ;buf LDA LIT "| EQU ;test-or32 JCN2
;buf LDA LIT '^ EQU ;test-xor32 JCN2 ;buf LDA LIT "^ EQU ;test-xor32 JCN2
;buf LDA LIT '~ EQU ;test-complement32 JCN2 ;buf LDA LIT "~ EQU ;test-complement32 JCN2
;buf LDA LIT 'N EQU ;test-negate32 JCN2 ;buf LDA LIT "N EQU ;test-negate32 JCN2
;buf LDA LIT '= EQU ;test-eq32 JCN2 ;buf LDA LIT "= EQU ;test-eq32 JCN2
;buf LDA LIT '! EQU ;test-ne32 JCN2 ;buf LDA LIT "! EQU ;test-ne32 JCN2
;buf LDA LIT '0 EQU ;test-is-zero32 JCN2 ;buf LDA LIT "0 EQU ;test-is-zero32 JCN2
;buf LDA LIT 'Z EQU ;test-non-zero32 JCN2 ;buf LDA LIT "Z EQU ;test-non-zero32 JCN2
;buf LDA LIT '< EQU ;test-lt32 JCN2 ;buf LDA LIT "< EQU ;test-lt32 JCN2
;buf LDA LIT '> EQU ;test-gt32 JCN2 ;buf LDA LIT "> EQU ;test-gt32 JCN2
;buf LDA LIT '{ EQU ;test-lteq32 JCN2 ;buf LDA LIT "{ EQU ;test-lteq32 JCN2
;buf LDA LIT '} EQU ;test-gteq32 JCN2 ;buf LDA LIT "} EQU ;test-gteq32 JCN2
LIT '? EMIT NEWLINE RESET-POS BRK LIT "? EMIT NEWLINE RESET-POS BRK
@read-byte ( addr* -> x^ ) @read-byte ( addr* -> x^ )
LDA2 ;parse-byte JSR2 LDA2 ;parse-byte JSR2
@ -107,7 +107,7 @@ JMP2r
;buf #0002 ADD2 ;read-long JSR2 ;buf #0002 ADD2 ;read-long JSR2
ROT2 ROT2
;buf #000b ADD2 ;read-byte JSR2 ;buf #000b ADD2 ;read-byte JSR2
TOR JSR2 ;emit/long JSR2 ROT ROT JSR2 ;emit/long JSR2
NEWLINE RESET-POS BRK NEWLINE RESET-POS BRK
( format: ". xxxxxxxx yyyyyyyy" -> "zz" ) ( format: ". xxxxxxxx yyyyyyyy" -> "zz" )