uCBQN/test/cases/fuzz/squeezeExact.bqn

76 lines
2.1 KiB
BQN
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### WHOLE-FILE-TEST
# tests if squeeze produces the optimal result
helpers •args
r helpers.GetRand@
EEqual, ClearRefs, Variation, Unshare, Squeeze, Type •internal
ntn "bit""i8""i16""i32""f64"
ntv "Ab""Ai8""Ai16""Ai32""Af64"
nmin 0 -2¯1+8×23
nmax 1¯1+2¯1+8×23
int 11110
ctn "c8""c16""c32"
ctv "Ac8""Ac16""Ac32"
cmax 111411228×23
specF64 r helpers.Import "utils.bqn"
spec specF64{}"a⍉𝕨"(@+1114111-5)<"foo"
RandEl r.Range3
{𝕊: r.Range spec} # some special values
{𝕊: -(r.Range 2) (¯5+r.Range 10) + 2r.Range 64} # random near-power-of-two number
{𝕊: @+01114111(¯5+r.Range 10) + 22+r.Range 20} # random near-power-of-two character
Do { 𝕊:
val RandEl@
base RandEl@
len 1+r.Range 23+r.Range 7
pos r.Range len
arr "Ah" Variation val(pos) len<base
vals base(len>1) val
expg (´=)3 {
1=𝕩? 1;
2=𝕩? 2;
3
}•type¨ vals
tOuttIn {
expg=1?
msk ´ {((¬int) 𝕩𝕩) 1˜ (nminnmax)𝕩}¨ vals
1msk/ntn "Ah""Af"msk/ntv;
expg=2?
msk ´ {cmax>𝕩-@}¨ vals
1msk/ctn "Ah""Af"msk/ctv;
expg=3?
"h""fill" "Ah""Af"
}
tIn {'S'1𝕩}¨ "Inc"¨ tIn
{
arrv 𝕩 Variation arr
arrv0 Unshare arrv
sq Squeeze arrv
sqt Type sq
sqt{
"arr"¯3sqt? ¯3sqt;
!"slice"¯5sqt ¯5sqt
}
¬ (arrv0 EEqual arr) (arrv0 EEqual sq) ((<sqt) tOut)?
•Out "Fail:"
•Out "Array: "•Repr arr
•Out "Squeezed: "•Repr sq
•Out "Testing variation "•Repr 𝕩
•Out "Got: "(Type sq)" / "sqt
•Out "Expected one of: "•Repr tOut
!0
;@
}¨ tIn
ClearRefs@
}
Do¨ 100000