forked from kevinlawler/kona
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.c
1912 lines (1761 loc) · 75.2 KB
/
tests.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "incs.h"
#include "tests.h"
#include "k.h"
// Note:
//
// To test out-of-memory handling on determininistic calls, execute the string
// and record the number of allocations n. Then simulate out of memory,
// running the string each time for each i < n. Allocating functions such as
// malloc, mmap, newK(), etc. will need to be overridden with debug versions.
// This will be significantly slower.
//
Z I testsIO();
Z I tests02();
Z I tests01();
Z I testsBook();
#define TC_(x, y ) {S s=ts(tp(tc(x, y))); if(test_print) fprintf(stderr, "%s:%u: TC( %s , %s ) ... %s\n", __FILE__, __LINE__, x, y, s); test_print=0; }
#define TC(x,...) TC_(#x,#__VA_ARGS__)
I passed=0, skipped=0, failed=0;
I tests=0;
I test_print=0;
F testtime;
S ts(I x){ switch(x){CS(0,R "fail";) CS(1,R "OK") CS(2,R "skipped")}; R 0;}
I tp(I x){ switch(x){CS(0,failed++) CS(1,passed++)CS(2,skipped++)} tests++; R x;} //process the test
I tc(S a, S b) //test comparison . R 0,1,2
{
if(!(tests % 50)) O("t:%lld\n",tests); //commenting this causes an error. no idea why. fflush? macro stuff? >2 args bc of "skip" ?
if(!SC("skip",a)) R 2;
kreci=0;
KTREE=Kd();
K x = X(a); fer=fer1=fom=fbr=fll=fdc=feci=0; if(cls){cd(cls);cls=0;} I i=0; for(i=0;i<10;i++)cdp[i]='a';
// fprintf(stderr,"testing: %s\n",b);
K y = X(b); fer=fer1=fom=fbr=fll=fdc=feci=0; if(cls){cd(cls);cls=0;} for(i=0;i<10;i++)cdp[i]='a';
I m=matchI(x,y);
if(!m)
{
fprintf(stderr,"\nFailed. These are not equal:\n");
fprintf(stderr,"%s , %s\n", a,b);
fprintf(stderr,"********************************\n");
show(x); fflush(stdout);
fprintf(stderr,"--------------------------------\n");
show(y); fflush(stdout);
fprintf(stderr,"\n");
}
cd(x); cd(y);
cd(KTREE);
I c=0; DO(kreci, if(krec[i]) c++)
if(!c) R m;
fprintf(stderr,"Failed: Memory Leak - %s, %s \nAllocated K: %lld\nUnfreed K : %lld\nLeak %% : %f\n", a,b,kreci, c, c/(F)kreci);
I j=-1;
DO(c, do j++; while(!krec[j] && j < kreci); if(j>=kreci) break; K k=krec[j]; if(k){O("c:%lld t:%lld n:%lld | k:%p\n",rc(k),k->t,k->n,k); show(k);} )
R 0;
}
I test()
{ testtime=clock();
testsBook();
tests01();
tests02();
testsIO(); //could become slow - in the future may not want to test by default
K x; x=_(567);if(!tp(x && *kI(x)==567))fprintf(stderr,"\n\nK string execution broken\n\n"); cd(x);
//done:
testtime=(clock()-testtime)/CLOCKS_PER_SEC;
F rate=passed/((F)tests-skipped);
O("Test pass rate: %.4f, Total: %lld, Passed: %lld, Skipped: %lld, Failed: %lld, Time: %fs\n", rate,tests,passed,skipped,failed,testtime);
I r=1==rate;
O("%s\n", ts(r));
testtime=0; lineB=0; kerr("(nil)");
R r;
}
Z I testsIO()
{
R 0;
//binary - 1: 2:
TC(1,t:`testfile00; a:(1;1.0;"c";`d;1 2;3.0 4.0;"ef";`g`h;();(1;`z)); t 1: a; &/ a ~/: (1:t;2:t)) //leaves a file
TC(1, (40000<#x) & &/ "</html>" = -7 # x: `"google.com"`http 4:"GET /") // issue 523 (partial fetch from network connection)
}
Z I tests02()
{
TC(`b,(`a`b)[1])
TC(2, {1+1} 0)
TC(2, {a:1;a+a} _n )
TC(_n, {a:1;a+a}0;a)
TC_("99#1", "{1}'!99")
TC(1 2, 2#(1;2;3.0))
TC(1 2, -1_(1;2;3.0))
TC({x^2}, f:{x^2};.`f)
TC(1, (1+)~(1+))
TC(0, (1+)~(2+))
TC(1, {x} ~ {x})
TC(0, {x} ~ {x })
TC(1+2+3, {b:1;c:2;d:3;b+c+d} 0)
TC(_n, {1;;;} 0 )
TC({_f}, {_f} 0)
TC_("2 6 24", "{:[x<2;1;_f[x-1]*x]}' 2 3 4") //paired with below
TC_("2 6 24", "{:[x<2;1;x* _f[x-1]]}' 2 3 4") //regression
TC(60.0, {:[(x<2)&(y<2);2;(x^2)+(y^2)+_f[x-1;y-1]]}[4;4]) //tests _f cache handled correctly
TC(skip, (1;"stack") , .[{_f _f};0;:] ) //this test works but it takes 3x the other 600 tests
TC(_n , _f) //nice not necessary
TC(7, {[a;b;cc]q:0;z:1; a+b*cc}[1;2;3])
TC(1, {x} 1)
TC(2, {x+y}[1;1])
TC(3, {z+y+x}[1;1;1])
TC(12, f:{x+y}; f[1;2];f[8;4])
TC(4, {4} 0)
TC(5, {[] 2+3} 0)
TC(1 2, a: 1 2;{a} 0) //Context is visible
TC(1 2, a: 1 2;{a:3} 0;a)//Local changes are not applied to context
TC(3 4, a: 1 2;{a+:2} 0; a)
TC(_n, b:9;{b:b} 0)
TC((2 4) , ((1+)[1]; (1+|+)[1;2]) )
TC((),=!0) // =: Group had a bug with one element lists
TC((,,0),=,1)
TC((,0;,1),=1 2)
TC((,0;,1),=2 1)
//TC((2#,(,0;,1)), =:/:(1 2;2 1)) //Nice extension to K3.2, which errs on both =/: and =:/: (issue #553)
//Projections
TC((1;"valence"),@[.:;"{x}[1;]";:])
TC((1;"valence"),@[.:;"+[1;2;;;]";:])
TC(skip, (1;"valence"), .[+[1;2;;;]; 5;:] ) //fill in error trap //this has a problem? +[1;2;;;;] causing valence when shouldn't?
TC((1;"type"), .[+;(1;`b);:])
TC(0 43, b:.[+;(1;42);:]; b)
TC({x+y}[1;],{x+y}[1;])
TC({x+y}[;1],{x+y}[;1])
TC(!3, {x,y,z}[;;2][;1][0])
TC(1 2 3 4, {x[z;y]}[,][3 4;1 2])
TC(!3, f:{[a;b;c]a,b,c}; g:f 0; h:g 1; h 2)
TC(skip, {[a;b;c;d;e]a+b+c+d+e}[;;1;1;1]'[;1] , {[a;b;c;d;e]a+b+c+d+e}[;;1;1;1]'[;1])
TC((1 0;1 3) , a:(1 0;3 2); f:{a[x;y]}; (a[]0;f[]0)) //Cross-sectional indexing inconsistent with simple composition/projection
TC(2 1, f:![1;]; f 1 2)
TC(3, f:+[;]; g:f 1; g 2)
TC(8.0, f:^[;]; g:f[;3]; g 2)
TC_("4 5", "+[3;]'1 2")
TC_("7 8", "+[3;]\'[4 5]")
//Global Assignment
TC(7, {a::7} 0; a)
TC(7, a::[1;7];a) //Mix with conditionals
TC(7, {a:::[1;7]}0;a)
TC(7, {a::[1;7];a} 0)
//Subfunctions
TC( 3, {b:3; g:{b}; b:4; g[]}0) // inheritance: same var in prnt&child child res
TC( 4, {b:3; g:{b}; b:4; b}0) // inheritance: same var in prnt&child prnt res
TC(_n, {b:3; g:{a}; b:4; g[]}0) // inheritance: diff var in prnt/child, child res
TC( 4, {b:3; g:{a}; b:4; b}0) // inheritance: diff var in prnt/child, prnt res
TC( 1, {g:{b:1}; g[]}0) // :: subf-asgn, no prnt-asgn
TC(12, {g:{b:1}; b::12; g[]}0;b) // :: gl-asgn, gl-res (no prnt-asgn)
TC( 1, {g:{b:1}; b::12; g[]}0) // :: gl-asgn, child-res (no prnt-asgn)
TC( 1, {g:{b:1}; c::12; g[]}0) // :: gl-asgn, child-res (diff gl variable)
TC( 4, {g:{b:1}; b::12; b:4; b}0) // :: gl-asgn, prnt-res (prnt-asgn after gl-asgn)
TC(_n, {g:{b:1}; b::12; b:4; b}0;b) // :: gl-asgn, glbl-res (prnt-asgn after gl-asgn)
TC(12, {g:{b:1}; b::12; b}0) // :: gl-asgn, prnt-res (no prnt-asgn)
TC(12, {g:{b:1}; b:4; b::12; b}0) // :: gl-asgn, prnt-res (prnt-asgn before gl-asgn)
TC(_n, {g:{b:1}; b:4; b::12; b}0;b) // :: gl-asgn, glbl-res (prnt-asgn before gl-asgn)
TC(12, b:3;{g:{b:1};b::12;g[]} 0;b) // :: gl-asgn, pre-existing gl
TC( 1, {g:{b:1;b}; b:12; g[]}0) // : prnt-asgn, child res
TC( 3, {b:3; {b:4; b}0; b}0) // : prnt-asgn, prnt res
TC( 3, {[a;b]{[c;d]c+d}[a;b]}[1;2]) // 2 explicit bracket args
TC( 2, {[a;a]a+a}[1;9]) // oddly enough (no subfunction)
TC( 1 10, {a:10; {x,a}x}1) // 1 implicit arg: x
TC( 1 2 10, {a:10;{x,y,a}[x;y]}[1;2]) // 2 implicit args x,y
TC( 7, {{x+y+z}[x;y;z]+1}[1;2;3]) // 3 implict args: x,y,z
TC( 8, {x+{b:3;g:{b};b:4;g[]}0}5) // Depth-2 and inheritance
TC( 4, {x-{x+{b:3;g:{b};b:4;g[]}0}5}12) // Depth-3 and inheritance
TC(3 5, {x+y,{x-{x+{b:3;g:{b};b:4;g[]}0}5}12}[1;2]) // Depth-4
TC( 9, {+/x,{x+y,4}[1;2]}1) // 2-level implicit args
TC( 9, {+/x,{x+y,{x-{x+{b:3; g:{b}; b:4; g[]}0}5}12}[1;2]}1) // Depth-5
TC( 5, {+/x,{x+y,{x-{x+{b:3; g:{b}; b:4; :7; g[]}0}5}12}[1;2]}1) // early-return in level-5
TC( 7, {+/x,{x+y,{x-{x+{b:3; g:{b}; b:4; g[]}0}5}12}[1;2]; :7}1) // early-return in level-1
TC( 3, {{b:3; g:{b}; b:4; g[]}0}0) // unbuffered double braces
TC( 4, {1+{b:3; g:{b}; b:4; g[]}0}0) // buffered double braces
TC( 8, {({b:3;g:{b};b:4;g[]}0) + {b:5;g:{b};b:6;g[]}0}0) //double independent subfuncs
TC( 3, b:9; {b:3;g:{b};b:4;g[]}0) // pre-existing K-Tree entry
TC(25, {{+/x,{x+y,{x-{x+{b:3;g:{b};b:4;g[]}0}5}12}[1;2]}1 + {x+{b:3;g:{b};b:4;g[]}0}5 + {x-{x+{b:3;g:{b};b:4;g[]}0}5}12 + x}4)
// 4 stacks: depth-5, depth-2, depth-3, and implicit
TC(1 3 10 3 10, g:1; do[2;{a:10; g::g,{x,a}x}3]; g) // do[2;] loop with subfunction (implicit arg)
TC( 7, f:{x+y+z}; g:f[1;;3]; {b:3; h:{b}; b:4; g[h[ ] ] }0) // projection and subfunction
TC_( "3", "{:[x<2;1;_f[x-1]*x]}'2 3 4; {b:3; g:{b}; b:4; g[]}0") // muti-statement combo test
TC(120, {b:3; g:{b}; a::{:[x<2; 1; _f[x-1]*x]}5; g[ ]}0; a) // embedded _f with atom-arg
TC_("2 6 24", "{b:3; g:{b}; a::{:[x<2; 1; _f[x-1]*x]}'2 3 4; g[ ]}0; a") // embedded _f with list-arg
TC( 5, {x + {[a] a+a} y}[1;2]) // Leon Baum test
TC( 5, {[a;b] a + {x+x} b}[1;2]) // Leon Baum test-2
TC_("(7 0;7 1;7 2)", "f:{(7;x)};{[n]a:n;f'[!a]}[3]") // Variable scope
TC_("(7 0;7 1;7 2)", "{a:5;{(7;x)}'[!3]}[]") // More complicated variable scope
TC(1 3, a:{x/y}; b:{a[{(x;#y)};x]}; b[(1;1 2 3)]) // Subfunctions and juxtaposition
TC_("2 2#!4" , "a:{[f;c]f/'c}; c:2 2#!4; {d:a[{(x;y)};x];d}c") // Subfunction args & local variables
TC(1 2, {a:x;{a,x}y}[1;2]) // Outer scope shadowed depending on argument passing syntax: issue #221
TC(1 2, {a:x;{[b]a,b}y}[1;2]) // Outer scope shadowed depending on argument passing syntax: issue #221
TC_("(1 0;3 2)", "g:{[x;f]l:x[;0];r:x[;1];l f' r}; d:2 2#!4; g[d;{y,x}]") // issue #221
TC_("(1 0;3 2)", "g:{[x;f]l:x[;0];r:x[;1];l f' r}; a:{y,x}; d:2 2#!4; g[d;a]") // issue #221
TC_("(0 3;1 3;2 3;3 3;4 3;5 3)","{{[x;t](t,x)}[x]'!y+x}[3;3]") // s0 from issue #221 comments
TC_("(0 3;1 3;2 3;3 3;4 3;5 3)","{{[t](t,x)}'!y+x}[3;3]") // s1 from issue #221 comments
TC_("(0 3;1 3;2 3;3 3;4 3;5 3)","{a:x;{[t](t,x)}'!y+x}[3;3]") // s2 from issue #221 comments
TC_("0 0 0 1 0 0 0 0 0 0", "f:{a:!x;{3=x!10}'a};f 10") // issue #232
TC(15 20 25, f:{a:x; 1 2 3{a+x*y}\\:5} ;f 10) // issue #234 (extra escape needed for C)
TC(99, f:{a:x; 2{a+x+y}/42}; f 55) // issue #234
TC(29, g:{a:x; 2{a+x+y}/!6}; g 1; g 2) // issue #235 case 1
TC_("1 2", "{a:x;{a}()}'1 2") // issue #235 case 2
TC(123, f:{a:x; {a+x}}; g:f 123; h:f 456; g 0) // issue #235 case 3a
TC(456, f:{a:x; {a+x}}; g:f 123; h:f 456; h 0) // issue #235 case 3b
TC(10, f:{a:x; g::{a+x}; a+:a; h::{a+x}}; f 10; g 0) // issue #235 case 4a
TC(20, f:{a:x; g::{a+x}; a+:a; h::{a+x}}; f 10; g 0; h 0) // issue #235 case 4b
TC(_n, f:{a}; {a:x; f()}1) // issue #236
TC(1, f: {x {x}/ 1}; f 1; f 1) // issue #237
TC(1, f:{x}; g:{x f/1}; g 1; g 1) // issue #238 case 1
TC(1, f:{x}; g:{x f/1}; g 2) // issue #238 case 2
TC(1, f:{x}; g:{x f/1}; g 1; g 2) // issue #238 case 3
TC(22, {[e]{[x]e}1}@22) // issue #239
TC_( "(7 0;7 1;7 2)", "f:{(7;x)}; {[n]a:n;f'[!a]}[3]; {[n]a:n;f'[!a]}[3]") // issue #243
TC(456 123, f:{{[a]a,x}}123; f 456) // issue #220
TC(456 123, x:999; f:{{[a]a,x}}123; f 456) // issue #220
TC(3, {{[a]a+x}}[1][2]) // issue #220
TC(3, {{[a]a+x}}[1]2) // issue #220 and #432
TC(1 2, {a:x;{[b](a;b)}y}[1;2]) // issue #220
//TC(3 1 2, f:{{[a]a,x,y}}[1]2; f 3) // issue #244
//TC(3 1 2, {{[a]a,x,y}}[1][2]3) // issue #244
//TC(4 1 2 3, f:{{[a]a,x,y,z}}[1][2]3; f 4) // issue #247
//TC(4 1 2 3, {{[a]a,x,y,z}}[1][2][3]4) // issue #247
TC(2 1, a:1;{a:2;{a}[]}[],a) // issue #287
TC(2 1, a:1;{a:2;{a+x}[0]}[],a) // issue #287
TC( (0;"s"), {@[b;"s";:]}[] ) // issue #313
TC(5 3, {m:{x,y}[5]; {m[x]}[3]}[]) // issue #309
TC_("5 5", "{[m] {}[]; {x;m}\'1 2}5") // issue #341
TC(.[ :[1;>:;<:];(1;2);:], (1;"valence")) // issue #352
TC_("15 19", "10+/\'(2 3;4 5)") // issue #376
TC_("(10 12 15;10 14 19)","10+\\\'(2 3;4 5)") // issue #376
TC_("60 200","10*/\'(2 3;4 5)") // issue #376
TC_("(10 20 60;10 40 200)","10*\\\'(2 3;4 5)") // issue #376
TC_("(\"ab\";\"ba\")", "p:{[n]:[1=#n;,n;{x,\',/p[n _dv x]}\'n]}; perm:{,/p[x]}; perm \"ab\"") //issue #377
TC(.[3 3#0;(1 2;0 1);{x;y};1], 3 3#0 0 0 1 1 0 1 1 0) // issue #378
TC_( "(2 0;2 1)", "for:{[n;f]f\'!n}; {[i]for[i]{[j]i,j}}2" ) //issue #388
TC_( "(();,1 0;(2 0;2 1))", "for:{[n;f]f\'!n}; for[3]{[i]for[i]{[j]i,j}}" ) //issue #388
TC(21.8, c: 1 4 3 0.5 -2; mdev:{x-(+/x)%#x}; fo:{+/ _sqr mdev x}; fo c) //issue #390
TC(2, mi:{:[x!2;(x-1)%2; _ ((x-1),x)%2.0]}; {mi x}5; {mi x}5) //issue #391
TC(1, m:{:[x!2; 1; 2]}; {m x}5; {m x}5) //issue #391
TC(1, m:{:[x; 1; 2]}; {m x}5; {m x}5) //issue #391
TC(1, m:{:[x; 1; 2]}; {m 3}5; {m 3}5) //issue #391
//TC(6, mi:{:[x!2;(x-1)%2; _ ((x-1),x)%2.0]}; am:{(+/x)%#x}; p: 1 4 6 7 8; km:{am x[mi(#x)]}; km p; km p) //#391 (type error in k2.8)
TC(2 2#16.434 9.6192 7.2 12.114, e:2 2 # 2.1 4.008 3 0.3; e _mul e) //issue #392
TC_("2 2#0 1 1 0", "p:{:[1<x;,/(>:\'(x,x)#1,x#0)[;0,\'1+_f x-1];,!x]}; p 2; p 2") //issue #393
TC_("1.5", "i:{(2#x)#1.,x#0.};f:{(+%\':+x)[;!-1+#x]};*{+/(f(+\\x))[!-1+#x;]*|i -1+#x}2 2#2. 3 1 2") //issue #396
TC(9, {c:{. x};c "9"}0) // issue 397
TC(3, :(3;4)@0) // issue 397
TC((), ,/()) // issue 399
TC(1 2, {a:x; {a,x}@2}1) // issue 405
TC(1 2, {a:x; {a,x}. 2}1) // issue 405
TC(1 2, {a:x; {a,x}.,2}1) // issue 405
TC(1 1, a:@[!2;0;:;1]; a) // issue 411
//TC_("\\\\", "(\\\\)") // issue 413 \\ is "exit"
TC_(";\\\\", "(\\\\)") // issue 413
TC_("_n", "if[1;\\\\]") // issue 413
TC_("_n", "do[5;\\\\]") // issue 413
TC((,2), l:,0; (.[`l;0;:;])2; l) // issue 414
TC((.,(`a;2;)), d:.(); (.[`d;`a;:;])2; d) // issue 414
TC_("(1 2;3 4)", "({x,y}.)\'(1 2;3 4)") // issue 415
TC_(",0 1 2", "= 0 0 0") // issue 416
TC_(",1", "#:\',0") // issue 417
TC_(",1", "#:\',,0") // issue 417
TC_("(1 3;2 4)", "f:{x,y};(f\').(1 2;3 4)") // issue 420
TC(1, a:1; .k~...k) // issue 429
TC_("0 1 0 1", "?[\"+-<>[].\";]'\"+-+-\"") // issue 443
TC_("0 1 0 1", "(\"+-<>[].\"?)'\"+-+-\"") // issue 443
TC(9, f:{x*x}; g:{x+1}; (f;g)[0;3]) // issue 419
TC(3, g:{x+1}; (0 1 2 3;g)[0;3]) // issue 419
TC_("_n","{c:y}[];" ) // issue 451
TC("foo ", foo:{[] "foo "}; foo[]) // issue 454
TC({(y)+x}, {(y)+x}) // issue 458
TC((0 1;2 3;4 5), t:.+(`f`g`h;3 2#!6); t`f`g`h) // issue 460
TC((0 1;2 3), t:.+(`f`g`h;3 2#!6); t`f`g) // issue 460
TC(0=/!0, 0) // issue 468
TC(=/!0, 1) // issue 475
TC(=/1 2 3, 0) // issue 475
TC(120, fac:{[n] :[n=0;1;n*fac n-1]}; fac 5) // issue 487
TC(120, fac:{[n] :[n=0;1;n*fac[n-1]]}; fac 5) // issue 487
TC(120, fac:{[n] :[n=0;1;n*_f n-1]}; fac 5) // issue 487
TC(120, fac:{[n] :[n=0;1;n*_f[n-1]]}; fac 5) // issue 487
TC(3, a:3;a) // issue 502
TC("abcdefghij"2 3, "cd") // issue 508
TC_(",1 1", "0(+\\)\\1 1") // issue 515
TC(+[a+2;a:3],8) // issue 538
TC((a;a:2), 2 2) // issue 538
TC("F",tk:("F";"G");call:{nm:*tk; tk::1 _ tk;if[nm~"G"; :0];call();nm};call()) // issue 521
TC(1, (a)=a:12 ) // issue 551
TC( _n, {a}0 ) // issue 540
TC( 0, {a x}0 ) // issue 540
TC( 0, f:{:[x>0;2*f[x-1];1]}; g:f; f:{0}; g 4 ) // issue 537
TC( {p[`a]:1;do[1;p[`b]:2];p}[], .((`a;1;);(`b;2;)) ) // issue 555
TC_( "1 1", "ds:{-':x}; a: 1 2 3; ds a; ds a" ) // issue 554
TC( 2, g:{a:x; {:[x=0; a:x; g(0)]}a; a}; g 2 ) // issue 549
TC( 9, c:0; f:{c+:1;:[x;:[y;f[x-1;f[x;y-1]];f[x-1;1]];y+1]}; f[2;3] ) // Ackerman's function
TC( 1, (.((`a;1);(`b;2)))(`a) ) // issue 560
TC((,1), (.((`a;1);(`b;2)))(,`a) ) // issue 560
TC( 5, :+[2]3 ) // issue 558
TC( 2, :+2 ) // issue 558
TC( 5, f:{ if[x;:+[x]y]; y }; f[2;3] ) // issue 558
TC( -1, 4: (.((`a;1);(`b;2)))(,`a) ) // issue 561
TC_( "1 2", "(1 2 1)\\1" ) // issue 572
TC_( "12 6 3", "0 1 1 3 2 5 3 7 4 9 5 11 6\\ 12" ) // issue 572
TC( 1, d:.((`a;0);(`b;1)); `d .`b ) // issue 571
TC( .[;;;;], .[;;;;] ) // issue 543 testing for leaks
TC( .[], .[] ) // issue 543 testing for leaks
TC_( "(1 3;2 4)", "1 2 ,\'\' 3 4" ) // issue 594
TC_( "(1 3;2 4)", "{x,\'\'y} . (1 2;3 4)" ) // issue 594
TC_( "((1 3;1 4);(2 3;2 4))", "(,/:\\:) . (1 2;3 4)" ) // issue 588
TC( (1 2;4 3;5 4), ."1 2 ,': 3 4 5" ) // issue 595
TC( (1 2;4 3;5 4), ."{x,':y} . (1 2;3 4 5)" ) // issue 595
TC( (1 2;4 3;5 4), ."(,':) . (1 2;3 4 5)" ) // issue 595
//Error trap: {[a;b][c;d] a+b} -> parse error ; { {[a][b] }} -> parse error
TC(.[*; (3;4); :], (0;12) )
TC(.[*;3 4 5;:], (1;"valence"))
TC((.[-1 -2 _; ,!9; :]) , (1;"domain"))
TC((.[0 10 100 _; ,!9; :]) , (1;"length"))
//TC(.[=; 0; :] , (1;"valence") ) // ignore: better to return =[0;] than valence error
TC((.[.:;,"{_foo[x]}";:]),(1;"reserved"))
TC((.[.:;,"{_vs.a[x]}";:]),(1;"parse"))
TC((.[.:;,"{_vs.abc[x]}";:]),(1;"parse"))
TC((.[.:;,"{_vs_a[x]}";:]),(1;"parse"))
TC((@[.:;"{_foo[x]} 0";:]),(1;"reserved"))//.[NULL;...] errors inside bracket should not be interpreted as projections
TC(a:1+`d, )
TC(-9131, _jd 20100101)
//Degenerate uses of : colon verb
TC(1, (::)[1]) //monadic
TC(2, (:)[0;2]) //dyadic
//Conditionals
TC(_n,:[1;])
TC(_n,:[0;])
TC(_n,:[0;1])
TC(1,:[1;1])
TC(2,:[0;1;2])
TC(2,:[1;2;3])
TC(2,:[1+1;2;3])
TC(3,:[0;2;3])
TC(2,:[1;2;3;4;5;6])
TC(7,:[0;1;0;3;0;5;1;7;0;9;10])
TC(3,:[0+0;1;1-1;2;1;3])
TC(4,:[0+0;1;1-1;2;-1+1;3;4])
TC(2,:[0;;0;;0;;1;2;0;])
TC(_n,:[0;;0;;0;;0;2;0;])
TC(_n,:[0;;0;;0;;0;2;0;;])
TC(1,:[0;;0;;0;;0;2;0;; 1 ])
TC(_n,:[,0;1])
TC(1,:[,1;1;2])
TC(2,:[,,0;1;2])
TC(1,:[,,1;1;2])
TC((1;"type"),@[.:;":[,!0;1;2]";:])
TC(2 3, f:{[a] :[a;2;3]}; (f 1;f 0))
TC(skip,(1;"parse"),:[1])
TC(_n,if[3<4;a:20])
TC(40,a:10;if[5<6;a:40];a)
TC(30,a:30;if[5>6;a:20];a)
TC(30,a:10;if[1;a:20;a:30;];a)
TC(20,a:10;if[2>,1;a:20];a)
TC(20,a:10;if[2>,,,1;a:20];a)
TC((1;"type"),@[.:;"a:10;if[,!0;a:20];a";:])
TC(_n,i:0;while[7>i;0+0;i+:1])
TC(7,i:0;while[7>i;0+0;i+:1];i)
TC(5,i:0;while[5>i+:1];i)
TC_(",5","i:,0;while[5>i+:1];i")
TC(_n,do[5;0])
TC(7,i:0;do[7;0+0;i+:1;];i)
TC(5,i:0;do[,5;i+:1];i)
//Commands
TC((1;"parse"), @[.:;"\b";:]) //trap parse errors (\b backspace)
TC(51, a:101#"1+"; . a) //In debug mode repeating . a;. a; causes execution time to build
TC(6, (+/)[1 2 3])
TC(7, (+/)[1; 1 2 3])
TC(1,~0.0)
TC(1,~ -0.0)
TC((1;"valence"), @[.:;",\\: 1 2 3";:])
TC(((0 2;0 3);(1 2;1 3)), 0 1 ,/:\\:2 3 )
TC(((0 2;0 3);(1 2;1 3)), 0 1 ,/:\\:\\:2 3 )
TC(((0 2;1 2);(0 3;1 3)), 0 1 ,\\:/: 2 3 )
TC( ((0;1;2 3;4 5);(0;1;6 7;8 9)) , 0 1 ,/: ((2 3;4 5);(6 7;8 9)))
TC( ((0 1 2 3;0 1 4 5);(0 1 6 7; 0 1 8 9)) , 0 1 ,/:/: ((2 3;4 5);(6 7;8 9)))
TC( (((0 1 2;0 1 3);(0 1 4; 0 1 5));((0 1 6; 0 1 7);(0 1 8; 0 1 9))) , 0 1 ,/:/:/: ((2 3;4 5);(6 7;8 9)))
//_bd _db
TC_("1" , "a:(1;1.0;\"c\";`d;1 2;3.0 4.0;\"ef\";`g`h;();(1;`z)); &/{x~_db _bd x}'a,,a")
TC_("1" , "a:(!11)#\\:`a`b; &/{x~_db _bd x}'a")
TC_("1" , "a:(!11)#\\:\"cd\"; &/{x~_db _bd x}'a")
TC_("1" , "a:(!11)#\\:(`a;\"c\";1); &/{x~_db _bd x}'a")
TC_("1" , "a:(!11)#\\:,(`a;\"c\";1); &/{x~_db _bd x}'a")
//TC((1;"parse"), .[.:;,"_db_bd 1";:] ) //we handle this case now instead of error
TC(2, _db_bd_db_bd 2) //should be able to handle this case
TC(skip, 1,&/{x~_db _bd x}/: (+;+:;-;-:)) // handle unreserved monadic,dyadic verbs
TC(0 2, @[.:;"1+1";:])
TC(32, (+/ *)[1 2 3;4 5 6])
TC(32, 1 2 3 _dot 4 5 6)
TC((0.5 0 0;0 0.5 0;0 0 0.5), _inv (2 0 0;0 2 0; 0 0 2) )
TC((0.1 0 0;0 0.1 0;0 0 0.1), _inv (10 0 0;0 10 0; 0 0 10) )
TC(400 400, 10 10 _mul 20 20)
//_sv _vsx and _vs
TC(13, 11(_+)\\2)
TC(11 13 16, 11(_+)\\2 3)
TC( 2010, 10 _sv 2 0 1 0)
TC( 11, 2 _sv 1 0 1 1 )
TC(1 2 3 4 _bin/: 1 2 3 4 5 0 0.5 1.5 2.5 3.5 4.5, 0 1 2 3 4 0 0 1 2 3 4)
// \p
TC( 4:."\\p", 1) //return the result,can be used in scripts
TC(3999, #5:2000#1) //5:monadic should not be subject to "..." display eliding (before displaying it anyway)
//TC(33599997, #5:16799999#1) // Forces r>KP_MAX in kexpander for 32-bit-Linux or OSX
//TC(33999997, #5:16999999#1) // Forces r>KP_MAX in kexpander for Cygwin
TC(5:(+), (,"+"))
TC(5:(|/), "|/")
TC(5:(_acos;_tanh;_abs;_size;_bin;_vsx;_ssr;_vs), "(_acos;_tanh;_abs;_size;_bin;_vsx;_ssr;_vs)")
//TC_("a:.'(+;-);a@\\:1 2", "3 -1") //issue #553
TC(3 3#!0, (0 0 0;0 0 0; 0 0 0))
TC(3 3#0#0.0, (0 0 0.0;0 0 0.0; 0 0 0.0))
TC(2 2#0#"", (" ";" ") )
TC(1 1#0#`, ,,` )
TC(2 2#(), ((;);(;)))
TC({x+y}/1 2 3 4, 10)
//Radix _vsx and _vs (unbounded)
TC(!0, 2 _vs 0) //an artifact of writing K in K (K3.2),
//but sensible if you intend 30000 and 30 to have the same length _vsx[2;] (leading zeroes)
TC((,0), 2 _vsx 0)
TC((,1), 2 _vs 1)
TC((,1), 2 _vsx 1)
TC(1 0, 2 _vs 2)
TC(1 0, 2 _vsx 2)
TC(1 0 1 1, 2 _vs 11)
TC(1 0 1 1, 2 _vsx 11)
TC(1 1 0 0, 2 _vs 12)
TC(1 1 0 0, 2 _vsx 12)
TC(2 0 1 0, 10 _vs 2010)
TC(2 0 1 0, 10 _vsx 2010)
TC(1 2 3 4 5, 10 _vs 12345)
TC(1 2 3 4 5, 10 _vsx 12345)
//TC(((2;2 2);(0;0 0);(1; 1 1);(0;1 2)), 10 _vsx (2010;2011 2012)) //Unclear to me whether this level of generalization makes sense
//TC(skip, 2 _vsx (2; 4 8;(16 32;64 128))) //see above
//Clock arithmetic _vsx (bounded)
TC(1 6 40, 24 60 60 _vs 4000)
TC(1 6 40, 24 60 60 _vsx 4000)
TC(0 0 0, 1 2 3 _vs 0)
TC(0 0 0, 1 2 3 _vsx 0)
TC(23 59 0, 24 60 60 _vs -60)
TC(23 59 0, 24 60 60 _vsx -60)
TC(13 20 0, 24 60 60 _vs -6000000)
TC(13 20 0, 24 60 60 _vsx -6000000)
TC((0 0 10;0 16 40;13 46 40) , 24 60 60 _vs/: 10 1000 1000000)
TC((0 0 10;0 16 40;13 46 40) , 24 60 60 _vsx/: 10 1000 1000000) // /: is redundant for us
TC(0 0, 1 1 _vs 0)
TC(0 0, 1 1 _vsx 0)
TC(skip, 0, (_+[2;]) 11) //segfault
TC((1;"parse"), @[.:;"if[1; `0:“bad unicode quotes”]";:])
TC(1, 25<#0:"README.md")
//f'[x;y;z;...]
TC_("6", "f:{x+y+z}; f'[1;2;3]")
TC_("6", "f:{x+y+z}; f''[1;2;3]")
TC_("()", "f:{x+y+z}; f'[();2;3]")
TC_("_n","{x}'[]");
TC_("12 15 18", "f:{x+y+z}; f'[1 2 3;4 5 6;7 8 9]")
TC_("22 25 28", "f:{[a;b;c;d] a+b+c+d}; f'[1 2 3;4 5 6;7 8 9;10]")
TC_("22 26 30", "f:{[a;b;c;d] a+b+c+d}; f'[1 2 3;4 5 6;7 8 9;10 11 12]")
TC_("12 14 16", "f:{x+y+z}; f'[1;4 5 6;7 8 9]")
TC_("12 14 16", "{x+y+z}'[1;4 5 6;7 8 9]")
TC_("(9 12;9 12)", "{x+y+z}'[(1 2;1 2);(3 4;3 4);(5 6;5 6)]")
TC_("9 12", "{x+y+z}'[1 2;3 4;5 6]")
TC_("9 12", "{x+y+z}''''''[1 2;3 4;5 6]")
TC_("12 15 18", "f:{x+y+z}; f''[1 2 3;4 5 6;7 8 9]")
//f/[x;y;z;...]
TC(16 17 18, {x+y}/[1 2 3;4 5 6] )
TC(16 17 18, (+)/[1 2 3;4 5 6] )
TC((), {x+y+z}/[();1 2 3;4 5 6])
TC(1 4 2 5 3 6, {x,y,z}/[();1 2 3;4 5 6])
TC((,7), @/[,1;0 0 0;+;1 2 3])
TC((,5), @/[,1;4#0;+;1])
TC(3 1, ./[1 1;0 0;+; 1 1])
TC(2,+/[1 1])
TC(3 3,+/[1 1;1 1])
TC(_n, +/[])
//f\[x;y;z;...]
TC((1 2 3;5 6 7;10 11 12;16 17 18), (+)\\[1 2 3;4 5 6] )
TC((1 2 3;5 6 7;10 11 12;16 17 18), +\\[1 2 3;4 5 6] )
TC((1 2;1 2 3 5;1 2 3 5 4 6) , {x,y,z}\\[1 2;3 4;5 6])
TC(3 , {x+y+z}\\[1;1;1])
TC((1 1;3 3;5 5) , {x+y+z}\\[1 1;1 1;1 1])
TC((,1), {x,y,z}\[1;();()])
TC(1 3 6, +\\[1 2 3])
TC(1 3 6, (+\\)[1 2 3])
TC((1 1;2 2;3 3), +\\[1 1;1 1])
TC((1 1;2 2;3 3), (+\\)[1 1;1 1])
TC((1 1;10 10;19 19) ,{[a;b;c;d]a+b+c+d}\\[1 1;2 2;3 3;4 4])
//f'/\...[x;y;z;...]
TC_("(33 34;39 40)", "{x+y+z}'/[(1 2;3 4);(5 6;7 8);(9 10;11 12)]")
TC_("(31 32;41 42)", "{x+y+z}/'[(1 2;3 4);(5 6;7 8);(9 10;11 12)]")
TC( (@[0$;0 1;:]) , (1;"type"))
TC( (@[0$;0 1.0;:]) , (1;"type"))
TC( (@[0$;`a`a;:]) , (1;"type"))
TC( (@[.:;"a:(1 2)[0]:3";:] ), (1;"parse") )
TC( (@[.:;"a:(0 1;2 3); a[0][1]:9";:] ), (1;"parse") )
TC( (@[.:;"(1):2";:] ), (0;2) ) //optional, differs from K3.2
TC( (@[.:;"a: 1 1 1; a/[0] +: 10";:] ), (1;"valence") ) //not clear here. think ... +:10 is ... index flip 10. Should be parse err?
TC( (@[.:;"5 (a:5)/1";:] ), (1;"rank") )
TC(13, ({x(|+\\)\\1 1} 5)[5;0])
TC( (.[.:;,"@[a-b]";:]) , (1;"parse") )
TC( 5, _ceiling 4.6)
TC(-4, _ceiling -4.6)
TC( 5, _ceiling 5.0)
TC( 2, _ceiling 1.001)
TC( 2, _ceiling 1.0000001)
TC( 1, _ceiling 1.00000000000000000001)
TC( 1, _ceiling 0.00000000000000000001) //per defn. as -_-
TC(1 2, @[1 2;0;0])
TC(1 2, .[1 2;0;0])
TC(6 2, @[1 2;0;5 6 7])
TC(6 2, .[1 2;0;5 6 7])
TC_("(1;\"index\")", "f:4 4#!16;i:(0;1 2;3 4 5;6 7 8 9); @[f;i;:]")
TC_("(1;\"index\")", "f:4 4#!16;i:(0;1 2;3 4 5;6 7 8 9); @[.:;\"f@'i\";:]")
TC_("(1;\"valence\")", "@[.:;\"1 2(+\\:)'1 2\";:]")
TC_("(1;\"valence\")", "@[.:;\"1 2(+\\\\:)'1 2\";:]")
TC_("(1;\"type\")", "@[.:;\"(2=\\\"2\\\") 2\";:]")
TC_("(0;6 7 8)", "a:{x+y};@[.:;\"a'[5;1 2 3]\";:]")
TC_("(0;6 7 8)", "a:{x+y};@[.:;\"a\\\\:[5 6 7;1]\";:]")
TC_("(\"ab\"\n \"ac\")", "{x,y}'[\"a\";\"bc\"]")
TC(-1 0 1, flip:{[f;x;y]f[y;x]};flip[-\\:][2;1 2 3])
TC_("10#2", "{x+1}'10#1")
TC_("c:{&:'y(?,/(1!)\\'1,')/,&x-y}; {x@<x}@c[4;2]","(0 1;0 2;0 3;1 2;1 3;2 3)")
TC(:,:)
TC(::,::)
TC(::::,::::)
TC(5:(:), ,":")
TC(5:(::), "::")
TC(5:(::::), "::::")
TC_("(1;\"parse\")", "@[.:;\":::\";:]") //:::, :::::, and so on return parse error (monadic colons ending in dyadic) with
TC_("(1;\"parse\")", "@[.:;\":::::\";:]")//more elborate code you could handle these cases, but that seems pointless
TC_("(1;\"parse\")", "@[.:;\":::5::::\";:]")
TC_("(1;\"parse\")", "@[.:;\"a _abs: \";:]") //more generally PE for anything not assignment ending in dyadic colon (except a solitary dyadic colon)
TC_("(1;\"parse\")", "@[.:;\"4:::\";:]")
TC(2,a:2 3;a@*:0)
TC(0=#:,a:0;a=#:)
TC(skip, _n, do[3;."\" \"_sv 1"]) //bv_ex error mishandling caused crash //k2.8 and Kona yield "type error" not _n
TC(skip, _n, do[3;."1_sv \" \""]) //^^ //k2.8 yields _n Kona yields "type error" (Kona seems correct. See ref p.221)
TC(6 7 8, (21>+/)(2+)/!3)
TC((1;"wsfull"),@[.:;"0I#0";:])
TC((1;"int"),@[.:;"&0I";:])
#if defined(__MACH__) && defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
TC((1;"limit"),@[.:;"!0I";:])
#else
TC((1;"wsfull"),@[.:;"!0I";:])
#endif
TC(1 3 , +\\ 1 2)
TC(1 3.0 , +\\ 1.0 2.0)
TC(1 2 4.0, 1.0 +\\ 1 2)
TC(1 2 4.0, 1.0 +\\ 1.0 2.0)
TC(1 2 4 , 1 +\\ 1 2) //These change in K4
TC(1 2 4.0, 1 +\\ 1.0 2.0) //We break with K3's (1;2.0;4.0). K3 bug?
TC(10 1, ."10 -'': 2 3")
TC(10 1, ."10 -': 2 3")
TC(10, ."10 -': 2")
TC(10, ."10 +': 2")
TC(10 5, ."10 +': 2 3")
TC(4, ."+':2") // issue 601
TC(5.0, ."+':2.5")
TC_(",5", "+':2 3") // issue 601
TC(0 12345 1406932606 654583808 1358247936, 4{((1103515245*x)+12345)!(_2^31)}\\0 )
TC(0, (_2^31)-2147483648)
TC(6, -8!7)
//bv_ex subtriadic
//bv_ex 1. doesn't seem to handle projectons correcly
// 2. doesn't let / \ etc handle themselves correctly in the dyadic (monadic, niladic?) case
TC(+/[1;],+/[1;]) // valid as test for memory leak (not for correct result)
TC(10 , +/[1;]2 3 4)
TC(10 , (+/)[1;]2 3 4)
TC(1 3 6 10 , +\\[1;]2 3 4)
TC(+\\[1;],+\\[1;]) // valid as test for memory leak leak (not for correct result)
TC(+/[;1],+/[;1]) // valid as test for memory leak leak (not for correct result)
TC_("+'[;1]","+'[;1]") // valid as test for memory leak leak (not for correct result)
TC_("3 4 5","+'[1;]2 3 4")
TC({x+y}/[1;], {x+y}/[1;]) // valid as test for memory leak leak (not for correct result)
TC(10 , {x+y}/[1;]2 3 4)
TC(10 , ({x+y}/)[1;]2 3 4)
TC(1 3 6 10 , {x+y}\\[1;]2 3 4) //k4 deviates from k3 and gives 3 6 10
TC({x+y}\\[1;],{x+y}\\[1;]) // valid as test for memory leak leak (not for correct result)
TC({x+y}/[;1], {x+y}/[;1]) // valid as test for memory leak leak (not for correct result)
TC_("{x+y}'[1;]","{x+y}'[1;]") // valid as test for memory leak leak (not for correct result)
TC_("3 4 5","{x+y}'[1;]2 3 4")
TC_("skip","(,':)[1 2;3 4] ~ (1 2;4 3)")
TC(("ab";,"ab";("ab";"cd")), (2 2 # "abcd")[(0;,0;0 1)]) // indexing scalars & singletons
TC(("a";),"a",:[1;;"b"]) // concatenating with "nothing"
//COW: Copy On Write
TC(0 1 2 3, a:b:!4; a[1]:9; b) // update integer vector w integer atom
TC(0 1 2 3, a:b:!4; a[1 2]:8 9; b) // update integer vector w integer vector
TC((.1;.2;.3;.4), a:b:(.1;.2;.3;.4); a[1]:.9; b) // update float vector w float atom
TC((.1;.2;.3;.4), a:b:(.1;.2;.3;.4); a[1 2]:(.8;.9); b) // update float vector w float vector
TC(d:.((`a;1;);(`b;2;));d[!d]:d, (.((`a;1;);(`b;2;));.((`a;1;);(`b;2;))) ) //update dictionaries
TC(x:2 2#!4;x[0]:x;x, ((0 1;2 3);2 3)) //update list
TC(x:!10;y:x;y[1]:100;x, !10) //cross-variable assignment
TC(x:(1;1.0;"1");y:x;z:x;z[0]:2;y, (1;1.0;"1")) //demonstrate need for recursive ci/cd
TC(1, x:.+(`a`b;1 2); y:x; ."y.a:11; x.a") //dict references
TC(x:.+(`a`b;1 2); y:x; y.a:11;x, .+(`a`b;1 2) ) // Bakul comments #205, case 1
TC(d:.+(`a`b;1 2);d[`a]:d, .+(`a`b;1 2) ) // Bakul comments #205, case 2a
TC(d:.+(`a`b;1 2);d.a:d, .+(`a`b;1 2) ) // Bakul comments #205, case 2b
TC(d:.+(`a`b;1 2); d[!d]:d, (.((`a;1;);(`b;2;));.((`a;1;);(`b;2;))) ) // #188
TC(.((`a;(9 9 9;9 9 9;9 9 9););(`b;2;)), d:.+(`a`b;(3 3#9;2));e:d;d.a[1;2]:e) //case 3
TC( (.((`a;(9 9;9 9););(`b;2;));.((`a;(9 9;9 9););(`b;2;))), d:.+(`a`b;(2 2#9;2));d[]:d) // case 4
TC((2;(9 9 9;9 9 9;9 9 9)), d:.+(`a`b;(3 3#9;2));d[]:|d[]) //case 5
TC(x:.((`a;(0 1 2;3 4 5;6 7 8););(`b;10;));(x;x;x), d:.+(`a`b;(3 3#!9; 10));d.a[2]:(d;d;d)) // #43 case 3
TC_(".,(`d;;)", "d:.k") // #43 cases 1 & 2
TC_(".,(`d;.,(`d;;);)", "d:.k;d:.k;d") // #43 case 4
TC_(".((`a;;);(`b;;))", "a:b:.k;a") // #43 case 5a
TC_(".((`a;;);(`b;;))", "a:b:.k;b") // #43 case 5b
TC_(".((`a;.,(`c;;););(`b;.,(`c;;);))", "c:.+(`a`b;(.k;.k));c") // #43 case 6
TC_("(.((`a;;);(`b;;);(`c;;));.((`a;;);(`b;;);(`c;;));.((`a;;);(`b;;);(`c;;)))", "a:b:c:(.k;.k;.k);a") // #43 case 7a
TC_("(.((`a;;);(`b;;);(`c;;));.((`a;;);(`b;;);(`c;;));.((`a;;);(`b;;);(`c;;)))", "a:b:c:(.k;.k;.k);b") // #43 case 7b
TC_("(.((`a;;);(`b;;);(`c;;));.((`a;;);(`b;;);(`c;;));.((`a;;);(`b;;);(`c;;)))", "a:b:c:(.k;.k;.k);c") // #43 case 7c
TC_("(.((`x;;);(`y;;));.((`x;;);(`y;;)))", "x:y:(.k;.k);x") // #43 case 8x
TC_("(.((`x;;);(`y;;));.((`x;;);(`y;;)))", "x:y:(.k;.k);y") // #43 case 8y
TC(3 4 5, x:2 3#!6; y:x; z:y[1]; y[1;1]:99; z)
TC(3.1 4.1 5.1, x:.1+2 3#!6; y:x; z:y[1]; y[1;1]:99.1; z)
TC(1 0, ("a.c";"bc") _sm "*.[ch]")
TC_("0 1", "($`one;$`two) _sm $`two")
TC_("0 1", "`one `two _sm $`two")
#ifndef WIN32
TC_("$`xxx", "`hostname _setenv $`xxx; _getenv `hostname")
#endif
TC(".k", ."\\d a"; ."\\d .k"; $_d) // check for memory leaks
TC(1 2, a:.((`b;1);(`c;2)); `a[`b`c])
TC(3, a:1; \\b:2; c:3) // check: \b n
TC(skip, 5, a[5]) // value error
TC(skip, 5 6, a[5 6]) // value error
TC(skip, 5, a 5) // value error
TC(skip, 5 6, a 5 6) // value error
TC(skip, a:{a[x]}; a 5, ) // stack error
TC(4 3 2 1 0, r:{:[x;x,_f[x-1];0]}; r[4])
TC(4 3 2 1 0, r:{:[x;x,r[x-1];0]}; r[4])
TC(1, `a.1) //issue #290
TC(1, `a@1) //issue #291
TC(1 2 3, `a@1 2 3) //issue #291
TC(9, a:8 9 4; `a . 1) //issue #292
TC(9, a:8 9 4; `a @ 1) //issue #293
TC(9 4, a:8 9 4; `a @ 1 2) //issue #293
TC(6, m:3 4#!12; m\[1;2]) //issue #297
TC(2, m:3 4#!12; m\\2) //issue #298
TC(2 2#0, 2<2 2#1) //issue #299
TC(6, m:3 4#!12; 1 m\\2) //issue #296
TC(2 3 7 43 1807 3263443, {x, 1+*/x}/[5;2]) //issue #277
TC(,/$!2 2, (,"0";,"0";,"0";,"1";,"1";,"0";,"1";,"1")) //issue #307 (check for leaks)
TC(13, f:{x+1}; 2 f/11) //issue #325a
TC(13, f:{x+1}; f/[2;11]) //issue #325b
TC(13, f:{x+1}; f/[;11] 2) //issue #325c
TC(1968 880, _mul[(3 5;1 3)]/[;1 0] 5) //issue #325d
TC(3, #" ") //issue #336
TC( .[{x};1;:], 0 1) //issue #337
TC( .[{x};1 2;:], (1;"valence")) //issue #337
TC( .[{x};"2";:], (0;"2")) //issue #337
TC( .[{x};"2+2";:], (0;"2+2")) //issue #337
TC( .[{. x};"2+2";:], 0 4) //issue #337
TC( 4 5 6>5, 0 0 1) //issue #339
TC( 4 5 6<5, 1 0 0) //issue #339
TC( 5<4 5 6, 0 0 1) //issue #339
TC( 5>4 5 6, 1 0 0) //issue #339
TC( b:.[+;(1;"b");:]; b[1], "type") //issue #343
TC_("'\"abc\"", "\"abc\"") //issue #367
TC(6, fac:{:[x>1;x*fac[x-1];1]}; fac 3) //issue #373 (valgrind leaks)
TC(6, fac:{:[x>1;x*fac x-1;1]}; fac 3) //issue #373 (valgrind leaks)
TC(6, fac:{:[x>1;x*_f[x-1];1]}; fac 3) //issue #373 (valgrind leaks)
TC(6, fac:{:[x>1;x*_f x-1;1]}; fac 3) //issue #373 (valgrind leaks)
TC(2, 1 2 3 . (,1))
TC(1, (-0i) = -0I) // nan and inf handling
TC(1, 0n = 0N)
TC(1, 0n < 0)
TC(0, 0n > 0)
TC(1, 0n < 0i)
TC(1, 0n < -0i)
TC(1, 0n < 0I)
TC(1, 0n < -0I)
TC(1, 0N < 0)
TC(0, 0N > 0)
TC(1, 0N < 0i)
TC(1, 0N < -0i)
TC(1, 0N < 0I)
TC(1, 0N < -0I)
TC(0, 2=1.999999999999) // comparison tolerance
TC(1, 2=1.9999999999999)
TC(1, _1.999999999999)
TC(2, _1.9999999999999)
TC(1.0, _floor 1.999999999999)
TC(1.0, _floor 1.9999999999999)
TC(0, 4.9406564584124654e-324=-4.9406564584124654e-324)
TC( 0N, _ 0n)
TC( 0I, _ 0i)
TC(-0I, _ -0i)
TC(-0I, _ -5+1.0*1+-0I)
TC(1.618033988749908447, ?[{(x^2)+(-x)+(-1)};0;1])
TC(-0.6180339887194686854, ?[{(x^2)+(-x)+(-1)};0;.25])
TC(0n -0i 0 0i, v@<v:0. 0i -0i 0n)
TC(0 1 2 3,<("aaa";"bb";,"c";"d"))
TC(0 1 3 2,<("aaa";"bb";"c";,"d"))
TC(0 1,<("abd";"ad"))
TC(1 0,<("ad";"abd"))
TC(3 2 0 1,>("ab";,"a";"aba";"a"))
TC(0 1,<("";,"\000"))
TC(1 0,>("";,"\000"))
TC(0 1 2,<("";,"\000";" "))
TC(2 1 0,>("";,"\000";" "))
TC(1 2 0,<(" ";"";,"\000"))
TC(0 2 1,>(" ";"";,"\000"))
TC(0 1 2,<(,"\000";"\000\000";"\000\000\000"))
TC(2 1 0,>(,"\000";"\000\000";"\000\000\000"))
TC((,0;1 5;,2;,3;,4), ="arthur")
TC((0 4 5;1 6;,2;,3), =``a`b`c```a)
TC((,0), (?,0))
TC((,"\000";"\000\000";"\000\000\000"), ?(,"\000";"\000\000";"\000\000\000"))
TC(("\000a";"\000b";"\000c"), ?("\000a";"\000b";"\000c"))
TC(1 0 1 0, x:1 0 1 0; +\\x; x)
TC(3, c:2; .k["c+1"])
TC(43, c:2; d.c:42; d["c+1"])
TC(`a`b`c, a:1;b:2;c:3; ."\\v")
TC(2 2.0, ?2. 1.9999999999999)
TC((,0;,1), =2. 1.9999999999999)
TC(0, v:1.9999999999999 2.;v?2) // _hash
TC(0, v:1.9999999999999 2.;v?2.)
TC(2, v:1.9999999999999 2.;(v;_hash v)?2)
TC(1, v:1.9999999999999 2.;(v;_hash v)?2.)
TC((), "",()) // join-over
TC("", "",/())
TC((,0), 0,/()) // leading 0 in x _vs y
TC(201512 12, 0 100_vs 20151212)
TC(-1 0, 0 100_vs-100) // c/ join
TC("", " "/"")
TC(" ", " "/" ")
TC(" ", ";"/" ")
TC(" ; ; ", ";"/(," ";," ";," "))
TC((,"alpha"), " "\"alpha") // c\ split
TC(("";"lph";""), "a"\"alpha")
TC((,"a";"pha"), "l"\"alpha")
TC(("";"";"";""), "a"\"aaa")
TC_("x:.+(`a`b;1 2); y:x; f:{.[x;,`a;:;11]}; f`y; x",".+(`a`b;1 2)")
TC_("x:.+(`a`b;1 2); y:x; f:{.[x;,`a;:;11]}; f`y; y",".+(`a`b;11 2)")
TC(1, -20<10)
TC(1, -20.0<10.0)
TC(1, -10.0<20)
#ifdef K3_ARITH
TC(0i, 0i+0i) // plus
TC(0i, 0i+0I)
TC(0n, 0i+0n)
TC(0n, 0i+0N)
TC(0n, 0i-0i) // minus
TC(0n, 0i-0I)
TC(0n, 0i-0n)
TC(0n, 0i-0N)
TC(1.0, 0n^0) // power
TC(0.0, 0n^1)
TC(0.0, 0n^0i)
TC(0.0, 0n^-0i)
TC(1.0, 0n^0n)
TC(1.0, 0^0)
TC(0.0, 0^1)
TC(0.0, 0^0i)
TC(0.0, 0^-0i)
TC(1.0, 0^0n)
TC(1.0, 0.0^0)
TC(0.0, 0.0^1)
TC(0.0, 0.0^0i)
TC(0.0, 0.0^-0i)
TC(1.0, 0.0^0n)
TC(0.0, 0^0I)
TC(0.0, 0^-0I)
TC(1.0, 0^0N)
TC(0.0, 0.0^0I)
TC(0.0, 0.0^-0I)
TC(1.0, 0.0^0N)
TC(0.0, 0n^0I)
TC(0.0, 0n^-0I)
TC(1.0, 0n^0N)
TC(1.0, 0N^0)
TC(0.0, 0N^1)
TC(0.0, 0N^0I)
TC(0.0, 0N^-0I)
TC(1.0, 0N^0N)
TC( 0n, 0i^0)
TC( 0i, 0i^1)
TC( 0i, 0i^0i)
TC(0.0, 0i^-0i)
TC( 0n, 0i^0n)
TC( 0n, 0I^0)
TC( 0i, 0I^1)
TC( 0i, 0i^0I)
TC(0.0, 0i^-0I)
TC( 0n, 0i^0N)
TC( 0i, 0I^0I)
TC(0.0, 0I^-0I)
TC( 0n, 0I^0N)
TC(1.0, 1^0)
TC(1.0, 1^1)
TC( 0n, 1^0i)
TC( 0n, 1^-0i)
TC( 0n, 1^0n)
TC( 0n, 1^0I)
TC( 0n, 1^-0I)
TC( 0n, 1^0N)
TC(1.0, 12^0)
TC( 0i, 12^0i)
TC( 0n, 12^0n)
TC( 0i, 12^0I)
TC( 0n, 12^0N)
TC(0.0, 12^-0i)
TC(0.0, 12^-0I)
TC(1.0, (-1)^0)
TC(-1.0,(-1)^1)
TC( 0n, (-1)^0n)
#endif
R 0;
}
Z I tests01()
{
//Backslashes must be represented as \\, percent-signs as %%
//For ' and // use TC_("string","string")
//TC(skip,1,1) //How to skip a test that used to look like TC(1,1)
//First argument is everything before the first exposed comma. Second argument is everything after.
// TC(sizeofS:sizeof(S),sizeofI:sizeof(I)) //not a valid test, sizeof(S) is not a K expression.
TC(1,1)
TC(1 1, 1 1)
TC(1 1,1,1)
TC(2,1+1)
TC((),())
TC((),1 2 3@())
TC((), (1 2 3)())
TC(1 2 3, (1 2 3).())
TC(3, 3 4[0])
TC(10+1+, 10 + 1 2[0] +)
TC(7 6,1+1+1+1+1+|||1 2)
TC(_n,;)
TC((;),(;))
TC((;;),(;;))
TC(1, (((((1))))))
TC(5, 1+(1+(1+(1+1))))
TC(2, 1+(((((1))))))
TC(2 2, (2 2;3 4)[0])
TC((1 2;3 4), (1 2;3 4)[0 1] )
TC(1 3, (1 2;3 4)[0 1;0])
TC(1 2, (1 2;3 4)[0;0 1])
TC(10, (10 20;30 40)[0;0])
TC(10, (10 20;30 40)[0][0])
TC(2, (1 2;3 4)[0;1])
TC(20, (10 20;30 40)[0][1])
TC(30, ((10 20;30 40);50)[0;1;0])
TC(30, ((10 20;30 40);50)[0][1][0])
TC(10 20 30, m:(1 2 3;10 20 30;100 200 300); m[1;])
TC(2 20 200, m:(1 2 3;10 20 30;100 200 300); m[;1])
//TC((0 1;1 2 3) , a:(!a)+!:/:2+!a:4; a[0 1;]) //Extension: !:/:2+!4 works. K3.2 valence err for !, !:, or (!:) (issue #553)
TC(a:2 2 2#1+!10, a[0 1;;0 1])
TC(2 , # (+;+))
TC(7, 4:(`a 1 \\ ))
TC(1, 7=4:(`.))
TC(+,+)
TC(+-|, ||;+-|)
TC(1 , 1 2 . 0)
TC(skip, 11, .(`a;();:;11);a;a;a;a) // This fails in k2.8 & k3.2
TC(`a, .(`a;();:;22))
TC(skip, 33, .(`a;();:;33);a) // This fails in k2.8 & k3.2
TC(1,a:1)
TC(2,a:2)
TC(3,+[1;2])
TC(`b, .[`b;();:;33])
TC(33,..[`b;();:;33])
TC(1+2 3,..[`b;();:;3 4])
TC(2, a:1;b:4;b:5;c:1;d:2)
TC(30, ((10 20;30 40);50)[0;1;0])
TC(`b,b:1;.[`b;();-:])
TC(33,b:33;..[`b;()])
TC(-33,b:33; ..[`b;();-:])
TC(10,a:10)
TC(1 2 3,a:1 2 3)
TC(3,a:1+a:1+a:1)
TC(1 1 1 1, a:b:c:d:1;(a,b,c,d))
TC(+, a:+)
TC(11+, 11+)
TC(1-1+, 1-1+)
TC(0, (10+1+) ~ (11+)) //Interesting case
TC(_n, a:) //In K3.2 this is parse error
TC(4,#(+;+:;0:;:))
TC(-10, a:0;a:a-10)
TC(-12, .(10;();:;-12))
TC(-3, z:1;z+:2;z-:)
TC(7 8, a:1 2 3;1+a[0 1]:6 7)
TC(`a`b, a:1 2 3;a[0 1]:`a`b)
TC(`a`b, a:(1 2 3;1.0 2.0 3.0); a[0 1]:`a`b)
TC(1, a:(((((1))))))
TC(6, a:2;f:(1+a+);a:10; f 3) //Phrases ending in verb/adverb that get converted to 7-types need to "finally resolve" variables
TC(0,a:b:10;a:14;b~14)
TC(-10, a:0; a -: 10)
TC(-1 -2 -3, a:1 2 3; a -:)
TC(6, a: 1 2 3; 1+a[0]+:4)
TC(5, a: 1 2 3; 1+a[0]+:4;a[0])
TC(2, a: 1 2 3; 1-a[0]-:)
TC(-1, a: 1 2 3; 1-a[0]-:;a[0])
TC(3, a:2; z:1 2 3; z[a])
TC(1, a:0; z:(1 2; 3 4); z[a][a])
TC(1 , a:0;z:((1 2;3 4);(5 6;7 8);(9 10;11 12));z[a][a][a])
TC(8 , a:0;z:((1 2;3 4);(5 6;7 8);(9 10;11 12));z[a][a][a:1])
TC(1 2, a:_n; 1 2[a][a][a][a][a][a][a][a][][][][][][][a][][][][][][a][][][][])
TC((1 2;3 4) , ( 1 2 \n 3 4))
TC(0 1 2,! 3)
TC(4 ,2*2 )
TC(0,+/())
TC(0,|/())
TC(1,*/())
TC(1,&/())
TC(3,+/1 2)
TC(1,+/1)
TC(1,+/,1)
TC(1 3,+\\1 2)
TC(1,+\\1)
TC(14, 2+/3 4 5)
TC(a:(1 2 3;"CCC";`x`y`z), ++a)
TC(1 2 4 7, 1+\\1 2 3)
TC((.,(`k;)), .,(`k;))
TC(0 8 , a:0;z:((1 2;3 4);(5 6;7 8);(9 10;11 12));a,(z+a:0)[a][a][a:1])
TC(0 0 0 1, 1 < -1 0 1 2 )
TC(0 0 0 1, 1 < -1 0 1 2.0)
TC(0 0 0 1, 1.0 < -1 0 1 2 )
TC(0 0 0 1, 1.0 < -1 0 1 2.0)
TC(1 1 0 0, 1 > -1 0 1 2 )
TC(1 1 0 0, 1 > -1 0 1 2.0)
TC(1 1 0 0, 1.0 > -1 0 1 2 )
TC(1 1 0 0, 1.0 > -1 0 1 2.0)
TC(0 0 0 1, "c" < "abcd")
TC(1 1 0 0, "c" > "abcd")
TC(0 0 0 1, `c < `a`b`c`d)
TC(1 1 0 0, `c > `a`b`c`d)
TC(6 ,f:|/0(0|+)\\; f 2 1 -4 2 -1 5)
TC(5#45 , f:|/0(0|+)\\; a:!10; (f (!10); f[!10]; f a; f @ a; f .,a) )
TC(2,."0+0\n1+1")
TC_("4",".\"1+1\\n2+2\"")
R 0;
}
Z I testsBook()