Add •bit op fuzz tests
This commit is contained in:
parent
130653dbda
commit
e5a7dface4
38
test/bit.bqn
38
test/bit.bqn
@ -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 ← {_b‿F‿a:
|
||||
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‿¬‿1‿0
|
||||
•bit._and‿∧‿2‿0
|
||||
•bit._or ‿∨‿2‿0
|
||||
•bit._xor‿≠‿2‿0
|
||||
•bit._neg‿-‿1‿1
|
||||
•bit._add‿+‿2‿1
|
||||
•bit._sub‿-‿2‿1
|
||||
•bit._mul‿×‿2‿1
|
||||
⟩
|
||||
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 ← widths≤2⋆tz
|
||||
orc ← casts ⊏˜ or ← (2 r.Range ≠)⊸⊏ / cf∧cres
|
||||
wd ← (or∾⌽wx) ⊏ widths
|
||||
args ← (len÷⌽¯2↑wd) RandVals¨ wx
|
||||
_bc ← •bit._cast
|
||||
Test ← { c 𝕊 ops:
|
||||
cargs ← wxc {𝕨‿c _bc 𝕩}¨ args
|
||||
mod ← {1:⊢ ; m←2⋆𝕩 ⋄ m⊸|⌾((m÷2)⊸+)} ⊑c
|
||||
Test1 ← { _b‿Fn‿a: ! (((2+a)↑wd)_b args) ≡ ⟨c,1⊑orc⟩_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
|
||||
}
|
||||
(2⋆0‿3‿4‿5‿6) TestOps∘×⌜ ls
|
||||
|
||||
Loading…
Reference in New Issue
Block a user