uCBQN/test/cases/cells.bqn
2024-07-26 00:01:54 +03:00

118 lines
8.5 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 𝕩 !(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}}
%DEF k _k {𝔽•internal.Keep}
%DEF tcc %USE k %USE var _tcc { ! ´ (<𝕨 𝔽_k˘'e' 𝕩) ¨ (𝕨 𝔽˘'e'V𝕩)¨ "i"LV𝕩}
12 10 1 %% 11
1 10 12 %% 11
! 201200˘a20304024 ! 203040 a
! (2-1 {2-𝕩}1) 1010100
! (-21 {𝕩-2}1) 1010100
%USE k n1 {𝕊: (•Repr a) ! (n _kn)´ a((322'a'+26))¨ <˘ 2222•rand.Range 3}¨ 1000
%USE k n2 {𝕊: (•Repr a) ! (n _kn)´ a((322'a'+26))¨ <˘ 2222•rand.Range 3}¨ 1000
%USE k n3 {𝕊: (•Repr a) ! (n _kn)´ a((322'a'+26))¨ <˘ 2222•rand.Range 3}¨ 1000
{𝕊k: ! (3k {3𝕩}k) 222216}¨ ¯2+10
{𝕊k: ! (1k {1𝕩}k) 333381}¨ ¯2+10
!"˘: Result rank too large" % (02542)1˘ 021
!"⎉: Result rank too large" % (02542)1¯1 021
!"⎉: Result rank too large" % (1˜ 02042)50 1˜ 01002
!"⎉: Result rank too large (204 ≡ =𝕩, 200 ≡ =𝔽v)" % {𝕊:(2001)1}1 (2051)1
!"⎉: Argument frames don't agree (⟨3⟩ ≡ ≢𝕨, ⟨2⟩ ≡ ≢𝕩, common frame of 1 axes)" % "abc" 0 "ab"
!"˘: Argument frames don't agree (⟨3⟩ ≡ ≢𝕨, ⟨2⟩ ≡ ≢𝕩, common frame of 1 axes)" % "abc" ˘ "ab"
! ´{𝕊: ! ({𝕨𝕩}´) (<•rand.Range "ab",12,,0,"") ˜ (4•rand.Range) 1, {}, 'a', <'a', <{}, "ab", 0, ""}¨10000
# error cases that could be affected by special code
!"∧: Argument cannot have rank 0" % ˘2
!": Argument cannot have rank 0" % ˘"a"
!"Expected non-negative integer, got ¯3" % 2¯3/1 620
!"/: Lengths of components of 𝕨 must match 𝕩 (3 ≠ 4)" % 123/˘4567
!"/: Simple 𝕨 must have rank 0 or 1 (2≡=𝕨)" % (2314) /˘ 2
!"𝕨/𝕩: Length of compound 𝕨 must be at most rank of 𝕩" % (<0)/˘(5)<"ab"
!"⊏: Indexing out-of-bounds (24∊𝕨, 4≡≠𝕩)" % 124144
!"⊏: Indexing out-of-bounds (4∊𝕨, 4≡≠𝕩)" % 1˜6424
!"𝕨⊏𝕩: 𝕨 must be an array of numbers or list of such arrays" % 0@¯11 520.5
!"Expected integer, got ¯5.25" % ¯5.25˘424
!"⊏: Indexing out-of-bounds (1∊𝕨, 1≡≠𝕩)" % 001 ˘(˘) 10000×3
!"⊏: 𝕩 cannot be a unit" % 0˘5<"a"
!"⊏: 𝕩 cannot be a unit" % (30)˘3
!"Expected integer, got 0.1" % 0.1˘3515
!"⊑: 𝕩 must be a list when 𝕨 is a number (3‿4 ≡ ≢𝕩)" % 5˘234
!">: Result rank too large (80 ≡ =𝕩, 205 ≡ =⊑𝕩)" % >80 (2001)<(2051)1
!"⎉: Result rank too large (195 ≡ =𝕩, 210 ≡ =𝔽v)" % >5 (2001)<(2051)1
!"∾: Lengths not matchable (⟨6⟩ ≡ ≢𝕨, 1‿1 ≡ ≢𝕩)" % ("abc""def")˘(3/)"a"
!"∾: Argument ranks must differ by 1 or less (0≡=𝕨, 2≡=𝕩)" % 1˘333
!"∾: Lengths not matchable (4‿2 ≡ ≢𝕨, 3‿3 ≡ ≢𝕩)" % (3424)˘3335
!"≍: 𝕨 and 𝕩 must have equal shapes (3‿4 ≡ ≢𝕨, 3‿3 ≡ ≢𝕩)" % (34)2 23318
!"≍: Result rank too large (255≡=𝕩)" % 0˜2551
!"shift: Lengths not matchable (⟨6⟩ ≡ ≢𝕨, 1‿1 ≡ ≢𝕩)" % ("abc""def")«˘(3/)"a"
!"shift: =𝕨 must be =𝕩 or ¯1+=𝕩 (0≡=𝕨, 2≡=𝕩)" % 1«˘222
!"»: Argument cannot be a scalar" % »0 2316
!"⌽: Argument cannot be a unit" % ˘10
!"Expected integer, got 1.5" % 1.5˘232
!"↑: 𝕨 must have rank at most 1 (1‿2 ≡ ≢𝕨)" % (12)˘232
!"↓: 𝕨 must have rank at most 1 (4‿2 ≡ ≢𝕨)" % (428)˘@
!"Integer out of range: 1e20" % 1e20˘31010
!"Expected number" % 34@˘34
!"Expected integer, got 0.5" % 0.5˘4312
!"↑: Argument must have rank at least 1" % ˘2
!"↓: Argument must have rank at least 1" % 0 210
!"⊐: 𝕩 cannot have rank 0" % ˘"abcd"
!"⊒: Argument cannot have rank 0" % ˘"abcd"
!"∊: Argument cannot have rank 0" % ˘"abcd"
!"⍋: 𝕨 must be sorted" % 021˘ 3412
!"`: Shape of 𝕨 must match the cell of 𝕩 (⟨2⟩ ≡ ≢𝕨, 2‿3 ≡ ≢𝕩)" % (221)+`˘2230.4
!"`: Shape of 𝕨 must match the cell of 𝕩 (⟨⟩ ≡ ≢𝕨, 3‿3 ≡ ≢𝕩)" % 2+`˘333
!"´: Argument must be a list (3‿3 ≡ ≢𝕩)" % +´˘23318
!"´: 𝕩 must be a list (3‿3 ≡ ≢𝕩)" % 1+´˘23318
!"˝: 𝕩 must have rank at least 1" % +˝˘˘1010100
!"˝: 𝕩 must have rank at least 1" % ˝¯2 239
{˝˘ (×´) 2+𝕩}¨ 2345 %% (×´)¨ 23,212,2125,21256
{˝˘ (2+𝕩)<"hi"}¨ 2345 %% (<"hi")¨ 23,212,2125,21256
{˝¯2 (×´) 2+𝕩}¨ 345 %% (×´)¨ 234,2320,23206
%USE tcc 2, 20, ¯2, ¯20, 0 {𝕨 _tcc 𝕩 𝕨 _tcc 𝕩} <4, 5, 4520, 456120
%USE tcc <, , , {𝕎 _tcc 𝕩} <4, 5, 4520, 456120, 2345120
%USE tcc <, , {𝕎 _tcc 𝕩} <4, 5, 4520, 456120, 2345120
%USE tcc {𝕎 _tcc 𝕩} 4520, 456120, 2345120
%USE tcc _tcc 428 1_tcc 428 _tcc 42 1_tcc 42
%USE tcc _tcc 428 1_tcc 428 _tcc 42 1_tcc 42
%USE eqvar 0000 {𝕨˘𝕩}_eqvar ˘5 %% 544÷˜20
%USE eqvar 0¯10¯1 {𝕨˘𝕩}_eqvar ˘5 %% 544÷˜20
!"⊏: Indexing out-of-bounds (1∊𝕨, 1≡≠𝕩)" % %USE evar 0¯11¯1 {𝕨˘𝕩}_evar ˘5
!"⊏: Indexing out-of-bounds (¯2∊𝕨, 1≡≠𝕩)" % %USE evar 0¯1¯2¯1 {𝕨˘𝕩}_evar ˘5
(
%USE IS_HEAPVERIFY
# big ˝˘ & `˘ tester
_basicArgs { Test _𝕣 ranks:
{𝕊f: {{f Test 01˜ 𝕩024832}¨ 𝕩3 1}¨ ranks}¨ +=
}
# TODO replace ○⊢ with some pureness-preserving •internal.Keep
# w F _thing x tests F _thing⎉w x
_testFoldCells {´𝕗=? 0=×´(-𝕨)𝕩? 1; heapverify? 0=𝕩? 1 𝔽˝𝕨 𝕩; ! (𝔽˝𝕨 𝔽˝𝕨) 𝕩}
_testScanCells { heapverify? 0=𝕩? 1 𝔽`𝕨 𝕩; ! (𝔽`𝕨 𝔽`𝕨) 𝕩}
{1 𝕨 _testFoldCells 𝕩} _basicArgs 234
{1 𝕨 _testScanCells 𝕩} _basicArgs 234
{2 𝕨 _testScanCells 𝕩} _basicArgs 34
{2 𝕨 _testScanCells 𝕩} _basicArgs 34
0, 01, 10, 22, 1, 10, 101, 110, 30 {
𝕨𝕩 ¨
sh 𝕨𝕩
cr 𝕩
+= {
cr 𝕎 _testFoldCells 𝕩
cr 𝕎 _testScanCells 𝕩
} {0=×´sh? 𝕩; 𝕩, ¬¨ 𝕩, ¬(¯1)¨ 𝕩} sh¨ 01
} 0, 1, 2, 8, 32, 81, 48, 42, 59, 60, 63, 80, 81, 200, 640, 641
)