Add •bit op fuzz tests

This commit is contained in:
Marshall Lochbaum 2022-10-15 17:59:20 -04:00
parent 130653dbda
commit e5a7dface4

View File

@ -1,6 +1,7 @@
u 100×(•UnixTime+1|100וMonoTime)@
r •MakeRand •Show u
RandVals, casts r •Import "utils.bqn"
widths ¨casts
# Test •bit._cast first
# Convert unsigned width 𝕗 to 𝕘
@ -21,7 +22,42 @@ TestCast ← { f‿t 𝕊 len:
len + (1÷˜´¨c) | -len # Round up to exact conversion
(c _bitcast c •bit._cast) len RandVals f
}
cs / 64>¨casts # TODO floats
cs / 64>widths # TODO floats
cx (32'c'¨casts)/ cs # TODO 32-bit char output
ls (100) r.Range¨+ 100 × (1.5) 100
{cs ( !TestCast 𝕩˙) cx}¨ ls
# Now other •bit operations
OpArgs {_bFa:
m(1<a) {𝔽1}{𝔽´} # Adjust to act on argument list 𝕨‿𝕩
{𝕗 _b _m}(F _m)a
}
ops ¯1 (¨ OpArgs¨) # Group by args then int-ness
# op fn args int
•bit._not¬10
•bit._and20
•bit._or 20
•bit._xor20
•bit._neg-11
•bit._add+21
•bit._sub-21
•bit._mul×21
cres (widths 32) 'c' 1¨casts # Possible results; TODO floats
TestOps { 𝕊 len: # Length in bits
tz +´¬`2|÷2(7) len # Trailing zeros
wxc casts ˜ wx (2 r.Range ) / cf widths2tz
orc casts ˜ or (2 r.Range ) / cfcres
wd (orwx) widths
args (len÷¯2wd) RandVals¨ wx
_bc •bit._cast
Test { c 𝕊 ops:
cargs wxc {𝕨c _bc 𝕩}¨ args
mod {1: ; m2𝕩 m|((m÷2)+)} c
Test1 { _bFna: ! (((2+a)wd)_b args) c,1orc_bc Mod Fn cargs }
Test1¨ ops
}
DropMul ¯1(32=wd) # Multiplication test may need 64 bits
1'u',orc Test¨ 0(1=wd)DropMul(1) ops
}
(203456) TestOps× ls