uCBQN/test/cases/under.bqn

261 lines
20 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.

%DEF var V•internal.Variation LV•internal.ListVariations CLR•internal.ClearRefs
%DEF tvar %USE var _tvar {F _𝕣 x: (CLR@) {F 𝕩 V x}¨ LV 𝕩; w F _𝕣 x: (CLR@) (LV 𝕨) {(𝕨 V w) F 𝕩 V x} LV 𝕩}
%DEF eqvar %USE tvar _eqvar {r 𝕨 𝔽 _tvar 𝕩 !•internal.EEqual(r)¨ r r}
%DEF evar %USE tvar _evar {ok{} r𝕨 ok𝔽{𝕊: •CurrentError@} _tvar 𝕩 {okr? !"TEST FAIL: variation didn't error"; ("TEST FAIL: varying error messages" ! 1=)r !r}}
%DEF eqerr %USE eqvar _eqerr {ok{} r𝕨 ok𝔽{𝕊: •CurrentError@} 𝕩 {okr? !"TEST FAIL: case didn't error"; ("TEST FAIL: varying error messages" ! 1=)r !r}}
# ¨ & ˘
# !% ⊢⌾(⊢¨) 4 # TODO enable
# !% ⊢⌾(⊢˘) 4 # TODO enable
# ¯0¨⌾((⥊𝕨)⊸⊏) 𝕩
%DEF nz InsNZ { (¯641)˘((𝕨))(641•bit._cast) ˘ 𝕩} IsNZ {(¯641)˘ 641•bit._cast ˘ 𝕩}
%USE nz IsNZ 12 InsNZ 0.5010¯12 %% 011000, 0.5000¯12
%USE nz IsNZ 12 InsNZ 0010¯12 %% 011000, 0000¯12
# ⌾(F⊸Op)
10+((2÷˜)) 10 %% 01234156789
10+((2÷˜)) 10 %% 01234156789
10+((2÷˜)) 10 %% 101112131456789
10+((2÷˜)) 10 %% 101112131456789
10+((2÷˜)) 10 %% 101112131456789
10+((<2÷˜)/) 10 %% 101112131456789
10+((2÷˜)) 10 %% 012341516171819
(10)+((2÷˜)) 10×10 %% 5162738495061728394
((¯1+=)) 339 %% 33210543876
!"Expected integer, got function" % 1+((¯1+)˙)"ab"
!"𝕨⊑𝕩: 𝕨 must be a numeric array" % ((@,@,¯1+˙))"ab"
!"𝔽◶𝕘𝕩: 𝕘 must have rank 1 when index is a number" % (@,@,¯1+)"ab"
# ⊑
!"𝔽⌾(a⊸⊑): Incompatible result elements" % 1020(12,12) 459
!"Expected integer, got character" % 1+('a') "hello"
!"Expected integer, got 1.5" % 1+(1.5) "hello"
!"𝔽⌾(n⊸⊑)𝕩: reading out-of-bounds (n≡100, 5≡≠𝕩)" % 1+(100) "hello"
!"𝕨⊑𝕩: 𝕩 must be a list when 𝕨 is a number (4‿4 ≡ ≢𝕩)" % 1+(100) 4416
!"𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨2⟩, got ⟨3⟩)" % 102030(12,21) 4416
!"𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected unit array, got atom)" % 1((<2)) 10
!"𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected unit array, got atom)" % 1((<12)) 339
!"𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨1⟩, got atom)" % 1((12)) 339
!"𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨1⟩, got unit array)" % (<1)((12)) 339
!"⁼: Inverse not found" % 1((<2)) 10
!"⁼: Inverse not found" % 1((<12)) 339
!"⁼: Inverse not found" % (<1)((<12,21)) 339
!"⁼: Inverse not found" % 34((<12,21)) 339
!"𝕨⊑𝕩: Leaf arrays in 𝕨 must have rank 1 (element: (<2))" % 1((<2)) 10
!"𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨2⟩, got ⟨3⟩)" % 1(12,21) 4416
!"𝔽⌾(n⊸⊑)𝕩: reading out-of-bounds (n≡¯10, 3≡≠𝕩)" % 1+(¯10) 3
!"𝕨⊑𝕩: 𝕨 contained list with mixed-type elements" % 'a'(1'a') 459
!"𝕨⊑𝕩: Indexing out-of-bounds (index 1‿5 in array of shape 4‿5)" % 'a'(15) 459
10,2030(12,13,21) 459 %% 4501234561020013034567801
!"𝕨⊑𝕩: Picking item at wrong rank (index 1‿1‿1 in array of shape 10‿10)" % 1¨(111) 10101
!"𝕨⊑𝕩: Picking item at wrong rank (index ⟨1⟩ in array of shape 10‿10)" % 1¨(1) 10101
a1010101000 ! a a((a)) a
{𝕊: a(1+•rand.Range 200)•rand.Range 2 i•rand.Rangea ! a (ia)(i) 2(i) a}¨10000
100+(5) 44 %% (100×5=16) + 44
100+(¯5) 44 %% (100×11=16) + 44
100+ 44 %% (100×161) + 44
1+(¯2) 4 %% 0133
1+(¯2) 0.5+4 %% 0.51.53.53.5
# !% ⊢⌾⊑ 4 # TODO enable
# !% ⊢⌾(⊑⊑) 4 # TODO enable
# ⊏
n500 an i(-n)+2×n r(2×n)a ! (a) r(i) a
!"𝕨⊏𝕩: 𝕩 cannot be a unit" % 00(00) <0
!"Expected integer, got character" % 1+('a') "hello"
!"Expected integer, got 1.5" % 1+(1.5) "hello"
!"𝕨⊏𝕩: Indexing out-of-bounds (100∊𝕨, 5≡≠𝕩)" % 1+(100) "hello"
!"𝕨⊏𝕩: Indexing out-of-bounds (100∊𝕨, 4≡≠𝕩)" % 1+(100) 4416
!"𝕨⊏𝕩: 𝕩 cannot be a unit" % %USE evar (0) {(𝕨)𝕩}_evar <0
!"𝕨⊏𝕩: Indexing out-of-bounds (¯11∊𝕨, 10≡≠𝕩)" % %USE evar 5¯11 {01(𝕨)𝕩}_evar 10101
!"𝕨⊏𝕩: Indexing out-of-bounds (10∊𝕨, 10≡≠𝕩)" % %USE evar 910 {01(𝕨)𝕩}_evar 10101
!"𝕨⊏𝕩: Indexing out-of-bounds (10∊𝕨, 10≡≠𝕩)" % %USE evar "ab" {𝕨(910)𝕩}_evar 10"foo"
!"𝕨⊏𝕩: Indexing out-of-bounds (4.611686018427388e18∊𝕨, 3≡≠𝕩)" % %USE eqerr {𝕩((3262)) "abc"}_eqerr "abc", {𝕊: "abc"}
%USE eqerr ! (< {1𝕩((3263)) "abc"}{𝕊: •CurrentError@}¨ "abc", {𝕊: "abc"}) "Integer out of range: 9.223372036854776e18""𝕨⊏𝕩: Indexing out-of-bounds (9.223372036854776e18∊𝕨, 3≡≠𝕩)"
!"Expected integer, got 1.1" % %USE eqerr {𝕩((31.1)) 3}_eqerr 3, {1+𝕩}
!"𝕨⊏𝕩: Indexing out-of-bounds (10∊𝕨, 3≡≠𝕩)" % %USE eqerr {𝕩(101112) 3}_eqerr 3, {1+𝕩}
100+(124) <¨10 %% <¨ 0101102310456789
100+(124) <¨10 %% <¨ 0101102310456789
100+(124) 10 %% 0101102310456789
100+¨(124) 10 %% 0101102310456789
100+(12¯4) <¨10 %% <¨ 0101102345106789
100+(12¯4) 10 %% 0101102345106789
10+(12) 0a4, a %% 011123,0123
%USE eqvar 0011 {𝕨(1245) 𝕩} _eqvar 101010110 %% 100011110
!"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected unit array, got atom)" % 10(2) 10
!"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected unit array, got atom)" % 0((<4)) "hello"
!"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨2⟩, got ⟨3⟩)" % 102030(23) 10
!"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨2⟩, got ⟨3⟩)" % 1(23) 10
!"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected 3‿10, got 2‿10)" % %USE evar 1(234)_evar 10100
!"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨1⟩, got atom)" % %USE evar 0 {1(𝕨)𝕩}_evar 0
!"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected 1‿3‿4, got atom)" % %USE evar 0 {1(𝕨)𝕩}_evar 2343
!"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected 2‿3‿4‿5‿1, got ⟨2⟩)" % 12((2342)) 4516
!"𝔽⌾(a⊸⊏): Incompatible result elements" % 34(11) 10
!"𝔽⌾(a⊸⊏): Incompatible result elements" % 34(1¯9) 10
!"𝔽⌾(a⊸⊏): Incompatible result elements" % %USE evar 34 {𝕨(1¯9) 𝕩}_evar 10
!"𝔽⌾(a⊸⊏): Incompatible result elements" % %USE evar "ab" {𝕨(1¯9) 𝕩}_evar 'a'+10
!"𝔽⌾(a⊸⊏): Incompatible result elements" % 345(112) 10
!"𝔽⌾(a⊸⊏): Incompatible result elements" % 345(112) <¨10
!"𝔽⌾(a⊸⊏): Incompatible result elements" % 345(112) a<¨10 •internal.Keep a
!"𝔽⌾(a⊸⊏): Incompatible result elements" % 34(("Ah"•internal.Variation 11)) <¨10
!"𝔽⌾(a⊸⊏): Incompatible result elements" % %USE evar (2730) {𝕨((3010)) 𝕩} _evar 1001
!"𝔽⌾(a⊸⊏): Incompatible result elements" % %USE evar !¨ {{¬(314)𝕩}•internal.Keep((10<𝕩)) 𝕩} _evar 105110011
%USE eqvar {¬((10<𝕩)) 𝕩} _eqvar 105110011 %% 105001100
2020(11) 10 %% 0202+8
100+(12¯1) 5 %% 01011023104
100+(12¯1) <¨5 %% <¨ 01011023104
1+(((10010)10/10)) 10 %% 1+10
%USE eqvar 1+((2/5)) _eqvar 10 %% <5+ 10
%USE eqvar 1+((2/5)) _eqvar ˘ 10 %% ˘ <5+ 10
%USE eqvar •internal.Keep((2/5)) _eqvar 10040 %% 10040
%USE eqvar (<) {•internal.Keep(𝕨) 𝕩}_eqvar¨ 01, "ab""cd" %% 01, "ab""cd"
%USE eqvar 0÷0,0÷0 {𝕨(00) 𝕩}_eqvar 30 %% 0÷0,0,0
%USE eqvar %USE nz 00 {(0 InsNZ 20)(𝕨)𝕩}_eqvar 33 %% 033
# ⥊
!"𝔽⌾⥊: 𝔽 must return an array with the same shape as its input (16 ≡ ≢⥊𝕩, ⟨17⟩ ≡ shape of result of 𝔽)" % 1 4416
1+ 5 %% (<6)
1+ <5 %% (<6)
1+ 5 %% (6)
1+ 2 %% 12
1+ 236 %% (1+236)
236 %% (236)
!"𝔽⌾⥊: 𝔽 must return an array with the same shape as its input (1 ≡ ≢⥊𝕩, ⟨2⟩ ≡ shape of result of 𝔽)" % 1 4
!"𝔽⌾⥊: 𝔽 must return an array with the same shape as its input (1 ≡ ≢⥊𝕩, ⟨2⟩ ≡ shape of result of 𝔽)" % 1 <4
!"𝔽⌾⥊: 𝔽 must return an array with the same shape as its input (1 ≡ ≢⥊𝕩, ⟨2⟩ ≡ shape of result of 𝔽)" % 1 4
!"𝔽⌾⥊: 𝔽 must return an array with the same shape as its input (2 ≡ ≢⥊𝕩, ⟨3⟩ ≡ shape of result of 𝔽)" % 1 12
!"𝔽⌾⥊: 𝔽 must return an array with the same shape as its input (6 ≡ ≢⥊𝕩, ⟨7⟩ ≡ shape of result of 𝔽)" % 1 236
!"𝔽⌾⥊: 𝔽 must return an array with the same shape as its input (1 ≡ ≢⥊𝕩, ⟨⟩ ≡ shape of result of 𝔽)" % 4
!"𝔽⌾⥊: 𝔽 must return an array with the same shape as its input (1 ≡ ≢⥊𝕩, ⟨⟩ ≡ shape of result of 𝔽)" % <4
!"𝔽⌾⥊: 𝔽 must return an array with the same shape as its input (1 ≡ ≢⥊𝕩, ⟨⟩ ≡ shape of result of 𝔽)" % 4
!"𝔽⌾⥊: 𝔽 must return an array with the same shape as its input (2 ≡ ≢⥊𝕩, 2‿1 ≡ shape of result of 𝔽)" % 21 12
# !% ⊢⌾⥊ 4 # TODO enable
# !% ⊢⌾(3⥊⊢) 4 # TODO enable
(22) 10 %% 0213456789
1+(102) 7 %% 1234567
{!𝕩<0 <9}() 7 %% 9123456
(2) 10 %% 8967452301
!"𝔽⌾(a⊸⥊): 𝔽 must return an array with the same shape as its input (⟨⟩ ≡ ≢a⥊𝕩, ⟨⟩ ≡ shape of result of 𝔽)" % () 7
!"𝔽⌾(a⊸⥊): 𝔽 must return an array with the same shape as its input (⟨2⟩ ≡ ≢a⥊𝕩, ⟨⟩ ≡ shape of result of 𝔽)" % 0(2) 10
!"𝔽⌾(a⊸⥊): 𝔽 must return an array with the same shape as its input (⟨2⟩ ≡ ≢a⥊𝕩, ⟨1⟩ ≡ shape of result of 𝔽)" % 1(2) 10
!"𝔽⌾(a⊸⥊): 𝔽 must return an array with the same shape as its input (2‿2 ≡ ≢a⥊𝕩, 1‿2 ≡ shape of result of 𝔽)" % 1(22) 10
!"𝔽⌾(a⊸⥊): 𝔽 must return an array with the same shape as its input (2‿2 ≡ ≢a⥊𝕩, ⟨⟩ ≡ shape of result of 𝔽)" % (22) 10
!"𝔽⌾(a⊸⥊): 𝔽 must return an array with the same shape as its input (3‿2 ≡ ≢a⥊𝕩, 2‿3 ≡ shape of result of 𝔽)" % (32) 10
!"⁼: Inverse not found" % (220) 10
!"⁼: Inverse not found" % (320) 10
1+(22) 5 %% <6
!"⌾: Incompatible result elements in structural Under" % 12+(22) 5
102030+˘(43) 123 %% 112233
# /
!"𝕨/𝕩: Lengths of components of 𝕨 must match 𝕩 (3 ≠ 10)" % 1(101/) 10
10+(1,01/)22 %% 2200,1011,10,1111
!"𝔽⌾(a⊸/): Incompatible result elements" % 12(20/)2
1+((10)/) 10 %% ×+ 10
# ↓ & ↑
!"𝔽⌾(n⊸↑)𝕩: 𝔽 must return an array with the same shape as its input (2 ≡ n, ⟨1⟩ ≡ shape of result of 𝔽)" % 1(2) 4
!"𝔽⌾(n⊸↓)𝕩: 𝔽 must return an array with the same shape as its input (2 ≡ n, ⟨1⟩ ≡ shape of result of 𝔽)" % 1(2) 4
!"𝔽⌾(n⊸↑)𝕩: 𝔽 must return an array with the same shape as its input (¯2 ≡ n, ⟨3⟩ ≡ shape of result of 𝔽)" % 1(¯2) 4
!"𝔽⌾(n⊸↓)𝕩: 𝔽 must return an array with the same shape as its input (¯2 ≡ n, ⟨3⟩ ≡ shape of result of 𝔽)" % 1(¯2) 4
!"𝔽⌾(n⊸↓)𝕩: 𝔽 must return an array with the same shape as its input (5 ≡ n, ⟨1⟩ ≡ shape of result of 𝔽)" % 1(5) 4
!"𝔽⌾(n⊸↓)𝕩: 𝔽 must return an array with the same shape as its input (1 ≡ n, 4‿5‿2 ≡ shape of result of 𝔽)" % (1) 34560
!"𝔽⌾(n⊸↑)𝕩: 𝔽 must return an array with the same shape as its input (¯2 ≡ n, 4‿5‿2 ≡ shape of result of 𝔽)" % (¯2) 34560
!"𝔽⌾(n⊸↑)𝕩: Cannot modify fill with Under (5 ≡ n, ⟨4⟩ ≡ ≢𝕩)" % (5) 4
(4) 4 %% 4
(5) 4 %% 4
•internal.Keep(¯5) 4 %% 4
{!(a×1+9× 012𝕩+3) 10×(𝕩) a34560}¨ ¯5+10
{!(a×1+9׬012𝕩+3) 10×(𝕩) a34560}¨ ¯3+7
%USE eqvar 100011 { 1¨(𝕨/)𝕩}_eqvar 010101 %% 110111
%USE eqvar 100011 { 0¨(𝕨/)𝕩}_eqvar 010101 %% 010100
%USE eqvar 100011 {'!'¨(𝕨/)𝕩}_eqvar 010101 %% '!'101'!''!'
%USE eqvar 100011 { ˙¨(𝕨/)𝕩}_eqvar 010101 %% 101
%USE eqvar 100011 { 3¨(𝕨/)𝕩}_eqvar "hellow" %% 3'e''l''l'33
%USE eqvar 100011 { +˙¨(𝕨/)𝕩}_eqvar -÷×=<> %% +÷×=++
!"𝕨/𝕩: Lengths of components of 𝕨 must match 𝕩 (6 ≠ 7)" % 0¨(100011/) 0101010
4 (3)(010/) 3 %!PROPER_FILLS %% 0,3,2,0
4 (010/) 3 %!PROPER_FILLS %% 0,1,2,0
4 (000/) 3 %!PROPER_FILLS %% 0,1,2,0
!"No fill found" % 4 (3)(010/) 3 %PROPER_FILLS
!"No fill found" % 4 (010/) 3 %PROPER_FILLS
!"No fill found" % 4 (000/) 3 %PROPER_FILLS
# <
< 4 %% 4
(<5)< 4 %% 5
{<"cd"}< "ab" %% "cd"
!"<⁼𝕩: Argument wasn't a rank 0 array" % 4< "ab"
!"<⁼𝕩: Argument wasn't a rank 0 array" % {}< "ab"
!"<⁼𝕩: Argument wasn't a rank 0 array" % < 2
# ⋈
4 %% 4
(5) 4 %% 5
{"cd"} "ab" %% "cd"
!"⋈⁼𝕩: Argument wasn't a length-1 list" % 4 "ab"
!"⋈⁼𝕩: Argument wasn't a length-1 list" % {} "ab"
!"⋈⁼𝕩: Argument wasn't a length-1 list" % 2
!"⋈⁼𝕩: Argument wasn't a length-1 list" % (<4) 2
# k⊸⌽
!"𝕨⌽⁼𝕩: 𝕩 must have rank at least 1" % 1(2) 10
(2) 1010100 %% 28292021222324252627
(12) 5525 %% 1552223242021234017895612131410111718191516
# NaN things
(
%USE eqvar
_test { set Repl _𝕣 exp:
# •Show ⟨"test", set, Repl, exp⟩
bad {}
_mod {exp? 𝔽; {"Expected error!"!bad𝕩𝕩}(bad𝔽{𝕊: •CurrentError@})}
HasMsg {"mismatched result/error message", exp, 𝕨, 𝕩 ! (¬exp) 𝕨𝕩}
exp {
@𝕊·: @;
𝕨𝕊0:
(101160) {Repl(𝕨/) 𝕩}_eqvar 1001
"𝔽⌾(a⊸/): Incompatible result elements" HasMsg (10270) {Repl(𝕨/) 𝕩} _mod _eqvar 1001
125 {Repl(𝕨) 𝕩}_eqvar 1001
"𝔽⌾(a⊸⊏): Incompatible result elements" HasMsg 144 {Repl(𝕨) 𝕩} _mod _eqvar 1001
;
𝕨𝕊1:
"⌾: Incompatible result elements in structural Under" HasMsg 122 {Repl(𝕨¨) 𝕩} _mod 010
} set
}
Batch { expNativeexpRuntimeGet:
val Get@
{ 𝕊 rt:
# •Show ⟨"batch", get, val, rt⟩
expNewexpSame {rt? expRuntime; expNative}
rt (Get¨ ) _test expNew
rt (Get¨ 3) _test expNew
rt {𝕊: 3<val} _test expSame
rt ( 3<val) _test expSame
rt (val˙¨ ) _test expSame
}¨ 01
}
ShouldNotBeCalled { 𝕊:
! •Show "I should not be called!"
}
Batch¨
11, 11, 0÷0
11, 11, <0÷0
11, 11, 3,0÷0,4
11, 11, {𝕊: ShouldNotBeCalled}
11, 11, ShouldNotBeCalled˙
11, 01, {𝕊: ShouldNotBeCalled(0÷0)}
11, 11, ShouldNotBeCalled(0÷0)˙
11, 11,
)