forked from kevinlawler/kona
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.c
executable file
·1374 lines (1228 loc) · 48.5 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( " x " , " y " ) ... %s\n", __FILE__, __LINE__,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);
K y = X(b);
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:%lld\n",k->c,k->t,k->n,(I)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;
R r;
}
Z I testsIO()
{
return 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
}
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({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 =:/:
//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({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(skip, 3, {b:3; g:{b}; b:4; g[]}0) //Subfunctions inherit constants
TC(123, {g:{b:1};b::123;g[]} 0;b)
TC(3, {b:3; {b:4} 0; b}0)
TC(3,{[a;b]{[c;d]c+d}[a;b]}[1;2])
TC(2,{[a;a]a+a}[1;9]) //oddly enough
//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((@[.:;"{_foo[x]} 0";:]),(1;"reserved"))//.[NULL;...] errors inside bracket should not be interpreted as projections
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 _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)
TC(3999, #5:2000#1) //5:monadic should not be subject to "..." display eliding (before displaying it anyway)
TC(5:(+), (,"+"))
TC(5:(|/), "|/")
TC(5:(_acos;_tanh;_abs;_size;_bin;_vs;_ssr), "(_acos;_tanh;_abs;_size;_bin;_vs;_ssr)")
TC_("a:.'(+;-);a@\\:1 2", "3 -1")
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 _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 _vs[2;] (leading zeroes)
TC((,0), 2 _vs 0)
TC((,1), 2 _vs 1)
TC(1 0, 2 _vs 2)
TC(1 0 1 1, 2 _vs 11)
TC(1 1 0 0, 2 _vs 12)
TC(2 0 1 0, 10 _vs 2010)
TC(1 2 3 4 5, 10 _vs 12345)
//TC(((2;2 2);(0;0 0);(1; 1 1);(0;1 2)), 10 _vs (2010;2011 2012)) //Unclear to me whether this level of generalization makes sense
//TC(skip, 2 _vs (2; 4 8;(16 32;64 128))) //see above
//Clock arithmetic _vs (bounded)
TC(1 6 40, 24 60 60 _vs 4000)
TC(0 0 0, 1 2 3 _vs 0)
TC(23 59 0, 24 60 60 _vs -60)
TC(13 20 0, 24 60 60 _vs -6000000)
TC((0 0 10;0 16 40;13 46 40) , 24 60 60 _vs/: 10 1000 1000000) // /: is redundant for us
TC(0 0, 1 1 _vs 0)
TC(skip, 0, (_+[2;]) 11) //segfault
TC((1;"parse"), @[.:;"if[1; `0:“bad unicode quotes”]";:])
//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;"type") ) //not sure on this one. think ... +:10 is ... index flip 10. Should be parse err?
TC( (@[.:;"5 (a:5)/1";:] ), (1;"type") )
TC(13, ({x(|+\\)\\1 1} 5)[5;0])
TC( (.[.:;,"@[a-b]";:]) , (1;"type") ) //specific err not important
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_("(0;1 2)", "@[.:;\"1 2(+\\:)'1 2\";:]")
TC_("(1;\"valence\")", "@[.:;\"1 2(+\\\\:)'1 2\";:]")
TC_("(1;\"type\")", "@[.:;\"(2=\\\"2\\\") 2\";:]")
TC_("(1;\"nyi\")", "@[.:;\"a/:[0;1]\";:]") //clearly, alter this test when a/:[0;1] implemented
TC_("(1;\"nyi\")", "@[.:;\"a\\\\:[0;1]\";:]")//clearly, alter this test when a\:[0;1] implemented
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(_n, do[3;."\" \"_sv 1"]) //bv_ex error mishandling was causing crash
TC(_n, do[3;."1_sv \" \""]) //^^
TC(6 7 8, (21>+/)(2+)/!3)
TC((1;"wsfull"),@[.:;"0I#0";:])
TC((1;"wsfull"),@[.:;"&0I";:])
TC((1;"wsfull"),@[.:;"!0I";:])
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(8 1, ."10 -'': 2 3")
TC(8 1, ."10 -': 2 3")
TC(8, ."10 -': 2")
TC(12, ."10 +': 2")
TC(12 5, ."10 +': 2 3")
TC(0 12345 1406932606 654583775 1449466924, 4{((1103515245*x)+12345)!(_2^31)}\\0 )
//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(skip, {x+y}/[1;], {x+y}/[1;])
TC(skip, 10, {x+y}/[1;] 2 3 4)
TC(skip, 10, ({x+y}/)[1;] 2 3 4)
TC(skip, 1 3 6 10, {x+y}\\[1;] 2 3 4) //k4 deviates from k3 and gives 3 6 10
TC(skip, 0, {x+y}\\[1;])
TC(skip, 0, {x+y}/[;1])
TC_("skip","{x+y}'[1;]")
TC_("skip","3 4 5 , {x+y}'[1;] 2 3 4")
TC_("skip","(,':)[1 2;3 4] ~ (1 2;4 3)")
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))
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 (!:)
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(11, .(`a;();:;11);a;a;a;a)
TC(`a, .(`a;();:;22))
TC(33, .(`a;();:;33);a)
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()
{
//K Manual 2.0 compliance
TC(1 0 1 0 0 2 0 1 2 1,A.I:1 2 3;A.F:2 5 7;B.F: 5 2 5 2 2 7 2 5 7 5; A.F ?/: B.F )
//TC((2 1 2 1 1 3 1 2 3 2;5 2 5 2 2 7 2 5 7 5) ,A.I:1 2 3;A.F:2 5 7;B.F: 5 2 5 2 2 7 2 5 7 5; A[;A.F?/:B.F] )
TC(10,+/1 2 3 4)
TC(26, 16 +/ 1 2 3 4)
TC(3.5, (1;"a";3.5;`xyz) 2)
TC(25 20 5 ,x:10; (x+5;x:20;x-5))
TC((98 54;2.5;3.5 -1; 54; 24) , x:99 55; (x-1;3.5-1;3.5 -1;x[1]-1;(12+13)- 1) )
TC(-3 -4 -5, - 3 4 5)
TC((-5 -2;-3;8 0 -2), - (5 2; 3; -8 0 2))
TC(5 9, 2 6 + 3)
TC(5 -6, 2 + 3 -8)
TC(5 -2, 2 6 + 3 -8)
TC(((7 8;9 10 11);(13;15 16)), (2;3 4) + ((5 6;7 8 9);(10;11 12)))
TC((2 7;-23), 2 4 -23 8 7 @ (0 4; 2))
TC(1, @"a")
TC( (1;(+;102)) , f:+; (@f;(f;102)))
TC((1;;2), (1; _n ; 2))
TC(4 3, ^ (1 2 3; "abc"; `x `y `z; 5.4 1.2 -3.56))
TC(2 3 2, ^ ((1 2; `a `b; "AB"); ("CD"; 3 4; `c `d)))
TC(2 3, ^ ((0 1 2; `a; "AB"); ("CD"; 3 4; `c `d)))
TC(3, # 1 -2 3)
TC(-2, 1 -2 3[1])
TC(4, # 3 4 5.721 1.023e10)
TC(5 , #"hello")
//End of "Terminology" section, Begin Verbs A-F
TC(9 14 19 6 5 4 3 5 7 0, d: 9 8 7 6 5 4 3 2 1 0;i: 2 7 1 8 2 8; y: 5 3 6 2 7 4;@[d;i;+;y])
TC(((9;"a";"b";"c");(8;1.5;`xyz);(7;100;3.76;`efgh)),d:9 8 7; i:(0;(1;2 2)); y: ("abc";((1.5;`xyz);(100;(3.76;`efgh)))); @[d;i;,;y] )
TC(9 60 70 6 5 4 3 30 40 0, d:9 8 7 6 5 4 3 2 1 0;i:2 7 1 8 2 8; y: 50 30 60 20 70 40; @[d;i;:;y])
TC((5 2.14;("a";"b";"cxyz")), .[(5 2.14; "abc");1 2; ,; "xyz"])
TC( ((1 2 3 400 600;4 5 6 7 500);(8 9;10;11 12);(13 14 100 300;15 16 17 18 200;19 20)),
d:((1 2 3;4 5 6 7);(8 9;10; 11 12);(13 14;15 16 17 18; 19 20)); i:(2 0;0 1 0); y:(100 200 300; 400 500 600); .[d;i;,;y])
TC((600 500;(8 9;10;11 12);(300;200;19 20)), d:((1 2 3;4 5 6 7);(8 9;10;11 12);(13 14;15 16 17 18;19 20)); i: (2 0; 0 1 0); y:(100 200 300; 400 500 600);.[d;i;:;y])
TC(((1 2 3;-4 -5 -6 -7);(8 9;10;11 12);(13 14;-15 -16 -17 -18;19 20)) , d:((1 2 3; 4 5 6 7);(8 9;10; 11 12);(13 14; 15 16 17 18;19 20)); i: (2 0; 0 1 0); y: (100 200 300; 400 500 600); .[d;i;-:])
TC(2 3 4 5 6, .[2 3;();,;4 5 6])
TC((2 4;3 5), .[2 3; ,_n;,;4 5])
TC("c" , (5 2.14;"abc") . 1 2)
TC(1,-2~4:0.0 0i)
TC(0.0 0i,0.0 0I)
TC(1, 0i = 0I)
TC(0, 0i ~ 0I)
TC(1, @1)
TC(0, @2 3 )
TC(1, @"Z" )
TC(0, @"" )
TC(1, @{x+y} )
TC(0, @(+;-) )
TC(1, @ `symbol )
TC(1, @ .((`a;2);(`b;3)) )
TC(1, @ _n)
TC(4 , #3 1 4 2 )
TC(3 , #(8 1 6;3 7;4 9 2) )
TC(1 , #"A" )
TC(1 , #,"A" )
TC(5 , #"count" )
TC("tares", 1 _ "stares")
TC("star", -2 _ "stares")
TC(7, 0 _ 7)
TC("", 88 _ "")
TC(!0 , 9 _ !6)
TC((0 1 2;3 4 5), 0 3 _ 0 1 2 3 4 5)
TC((0 1 2 3;4 5), 0 4 _ 0 1 2 3 4 5)
TC(("seas";"hells"), 0 4 _ "seashells")
TC(("try";" to";" cut";" into";" words"), a:"try to cut into words"; (0,(&a=" ")) _ a)
TC((!0;1 2;3 4 5), 1 1 3 _ !6)
TC((,3), ^ 1 2 3)
TC(1 3, ^,1 2 3)
TC(0 1 2 3 4, !5)
TC(1, 3=3)
TC(0, 3= -3)
TC(0 1 1, "cat" = "rat")
TC(0, `abc = `abcdefg)
TC(0, 3.0=3.1)
TC(0, 3.0 = 3.0001)
TC(1, 3.0 = 3.0000000000000001)
TC(2, 9 8 7 6 5 4 3 ? 7)
TC(7, 9 8 7 6 5 4 3 ? 1)
TC(2 , (8 16; "abcdef"; 4 9 2; `x`y`z`w; 4 9 2) ? 4 9 2)
TC(2 6, words:("canoe";"tug";"raft";"rowboat";"ark";"liner"); (words?"raft";words?"submarine"))
TC("a",*"abc")
TC("abc", *("abc";"defg";"hijkl"))
TC((,`pqr), *,,`pqr)
TC(`pqr, *`pqr)
TC(0,*!0)
TC(0.0, *0#0.0)
TC(" ",*0#"")
TC(`, *0#`)
TC(_n, *())
//End of 'First', Begin 'Flip'
TC((0 4 8;1 5 9;2 6 10;3 7 11) , +3 4#!12)
TC(((0 1 2;4 5;10 11);(3;6 7 8 9;12)), a:((0 1 2;3);(4 5;6 7 8 9);(10 11;12)); +a )
TC(((1;"C";`x);(2;"C";`y);(3;"C";`z)), +(1 2 3;"C";`x`y`z))
TC(((1;"C";`x);(2;"C";`y);(3;"C";`z)), +(1 2 3;"CCC";`x`y`z))
TC(`abc,+`abc)
TC(67,+67)
TC({x*y},+{x*y})
TC(`a`b`c,+`a`b`c)
TC(4, _ 4.6)
TC(-5, _ -4.6)
TC(0, 2=1.999)
TC(1, 2=1.9999999999999999999)
TC(0, 1=1.001)
TC(1, 1=1.00000000000000000001)
TC(1, _ 1.999)
TC(2, _ 1.999999999999999999)
TC((,"0";,"9") , $ 0 9)
TC("123", $"123")
TC("1.2e-34", $ 1.2e-34)
TC("**", 2$2.345)
TC(" abcd", 7$`abcd)
TC(" 2.35", 7.2 $ 2.345)
TC(" 714.00", 7.2 $ 714)
TC("2.35e+00 " , -9.2 $ 2.345)
TC("7.14e+02 " , -9.2 $ 714)
TC(27, 0$"27")
TC(3.4, 0.0$"3.4")
TC(27.0 , 0.0$"27")
TC("ab", " "$"ab")
TC(`abc , `$"abc")
TC((23;(23.4;`abc)), (0;(0.0;`)) $ ("23";("23.4";"abc")))
TC( 4#$ _log 2 , 4#$ (_exp) ? 2)
TC( 4#$_sqrt 2, 4#$ {x^2} ? 2)
TC( 2 0 3 1, > 3 1 4 2)
TC( 4 3 2 1 , 3 1 4 2[2 0 3 1])
TC(0 2 1, > (8 1 6;3 5 7; 3 9 2))
TC("zoned", a:"dozen"; a[>a])
TC(2 1 0, > `aaa `bb `c)
//End of 'Grade Down', Begin 'Grade Up'
TC(1 3 0 2, < 3 1 4 2)
TC(1 2 3 4, 3 1 4 2[1 3 0 2])
TC("adept",a:"taped"; a[<a])
TC((1 2 0;(3 5 7;4 9 2;8 1 6)),ms:(8 1 6;3 5 7;4 9 2); (<ms;ms[<ms]) )
TC((0 2 3;1 4 5), = 2 1 2 2 1 1 )
TC((,0;1 2 4;,3;,5;,6),="weekend")
TC((0 2 5;1 4;,3),=(9 2 3;4 5;9 2 3;6 7 8;4 5;9 2 3))
TC("e","abcdefg"@4)
TC("faded","abcdefg"@ 5 0 3 4 3)
TC(("fa";("d";,"ed")),"abcdefg"@(5 0;(3;,4 3)))
TC(((7 4 9 2;3 5);(3 5;7 4 9 2;8 1 6)), (8 1 6;3 5;7 4 9 2) @ ( 2 1; 1 2 0))
TC((2 3 4;("abcdefg";2 3 4)), d:.((`a;2 3 4);(`b;"abcdefg")); (d @`a; d @ `b`a))
TC(((8 9;10;11 12);11 12;11) , d:((1 2 3;4 5 6 7);(8 9;10;11 12);(13 14;15 16 17 18;19 20) ); (d . 1; d . 1 2; d . 1 2 0) )
TC(11 11, d:((1 2 3;4 5 6 7);(8 9;10;11 12);(13 14;15 16 17 18;19 20) ); ((((d @ 1)@2)@0);(d @/1 2 0)) )
TC(((13 14;15 16 17 18);(1 2 3;4 5 6 7)), d:((1 2 3;4 5 6 7);(8 9;10;11 12);(13 14;15 16 17 18;19 20) ); d . (2 0;0 1) )
TC((1 2 3;8 9;13 14), d:((1 2 3;4 5 6 7);(8 9;10;11 12);(13 14;15 16 17 18;19 20) ); d . (;0) )
TC(((2 1;5 4);(14 13;16 15;20 19)), d:((1 2 3;4 5 6 7);(8 9;10;11 12);(13 14;15 16 17 18;19 20)); d . (0 2;;1 0) )
TC(30,(1;.((`a; 2 3 4);(`b; 10 20 30 40))) . (1; `b; 2))
TC(1 2 3, 1 2 3 . ())
TC(10, 10 . ())
TC(1 4 5 6 7, 1 , 4 5 6 7)
TC(1 2 3 4, 1 2 3 , 4)
TC(1 2 3 4 5 6 7, 1 2 3 , 4 5 6 7)
TC((1;2;3;8 1 6;3 5 7;4 9 2), 1 2 3, (8 1 6;3 5 7;4 9 2))
TC(0 0 0 1, 1 < -1 0 1 2)
TC(1, "a" < "z")
TC(0 1, "aA" < "Z")
TC(0 1, `inch`mile < `foot`yard)
TC(1,1 < 1.000000000001)
TC(0,1 < 1.0000000000000000001)
TC(1,0.999999999999 < 1)
TC(0,0.999999999999999999 < 1)
TC(x:.((`a;4 4);(`b;"aa"));x, .(. x))
TC(1, 2 3 ~ 2 3)
TC(0, () ~ !0)
TC(0, "a" ~ ,"a")
TC(8, 3|8)
TC(3, 3| -8)
TC(987.65, 123.45 | 987.65)
TC(123.45, 123.45 | -987.65)
TC(0 1 1 1, 0 0 1 1 | 0 1 0 1)
TC(3, 3 & 8)
TC(-8, 3 & -8)
TC(123.45, 123.45 & 987.65)
TC(-987.65, 123.45 & -987.65)
TC(0 0 0 1, 0 0 1 1 & 0 1 0 1)
TC(1 1 0 0, 1 > -1 0 1 2)
TC(0, "a" > "z")
TC(1 0, "aA" > "Z")
TC(1 0, `inch`mile > `foot`yard)
TC(1, 1.000000000001 > 1)
TC(0, 1.0000000000000000001 > 1)
TC(1,1 > 0.999999999999)
TC(0,1 > 0.999999999999999999)
TC(0 1,~ 1 0 )
TC(0 1 0, ~ 4.6 0 -4.6)
TC( ~`c , `c.) // Attribute in Not/Attribute
//End of 'Not/Attribute', begin 'Plus'
TC(8.0, 2^3)
TC(-8.0, -2^3)
TC(1.0, 0^0)
TC(4.0,-2.0^2)
TC(3#$1.414214,3#$ 2.0^0.5)
TC(0i,10^1000)
TC(9 6 8 7, ? 9 6 8 6 9 7 8 9 6)
TC("strange",?"strange")
TC("racon",?"raccoon")
TC((9 2 3;4 5;6 7 8), ? (9 2 3;4 5;9 2 3;6 7 8;4 5;9 2 3))
TC(2.0 , %% 2) //Kind of cheating here. C parser complains on single %
TC(1.0, %%1)
TC(0i, %%0)
TC(2 4 1 3, |3 1 4 2)
TC(m:(8 1 6;3 5 7;4 9 2); |m , (4 9 2;3 5 7;8 1 6))
TC(`three, *|`one`two`three)
TC("a",|"a")
TC(!0, |!0)
TC((,3 1 4 2), |,3 1 4 2)
TC(2,5 ! 3)
//TC(0.0, 2.4 ! 0.4) //yields 0.4 in K4
TC(0.0,2.0 ! 1.0)
TC(2.0,5.0 ! 3)
TC((" 0";"0.1") , 3 $ 1.8 -2.7 ! 0.2)
TC(-1,5 ! -3)
TC(-1.0, 5.0 ! -3.0)
TC(-3 0 -1, -3 4 -17 ! -4)
TC(-3 0 -1.0, -3.0 4 -17 ! -4)
TC("fghabcde", 5 ! "abcdefgh")
TC("fghabcde", 21 ! "abcdefgh")
TC("defghabc", -5 ! "abcdefgh")
TC("defghabc", -21 ! "abcdefgh")
TC(!0, ^ 3.14)
TC(4 3 2, r:(("ab";"cd";"ef");("gh";"ij";"kl");("mn";"op";"qr");("st";"uv";"wx"));^r) //see refactor below
TC(4 3, s:(("aby";"cd";"ef");("gh";"i";"kl1");("mn";"opz";"qr");("st";"uv";"w"));^s)
TC((,4), t:(("ab";"cd";"ef");("gh";"ij");("kl";"mn";"op";"qr");("st";"uv";"wx"));^t)
TC(4 5 6 , 3 # 4 5 6 7 8 9)
TC(7 8 9, -3 # 4 5 6 7 8 9)
TC(4 5 6 7 8 9 4 5, 8 # 4 5 6 7 8 9)
TC(9 4 5 6 7 8 9 4 5 6 7 8 9, -13 # 4 5 6 7 8 9)
TC(1, r:(("ab";"cd";"ef");("gh";"ij";"kl");("mn";"op";"qr");("st";"uv";"wx")); r ~ 4 3 2 # "abcdefghijklmnopqrstuvwxyz")
TC(2 3 4 0, ^ 2 3 4 0 7 8 # "abc")
TC(("ab";"cd"), 2 -1 # "abcd" )
TC(("abcd";"efgh"), 2 -1 # "abcdefgh")
TC(2 2,^ 2 -1 # "abcd" )
TC(2 4,^ 2 -1 # "abcdefgh")
TC((,"abc";,"def"), 2 -1 3 # "abcdef")
TC((("abc";"def");("ghi";"jkl")), 2 -1 3 # "abcdefghijkl")
TC(2 1 3, ^ 2 -1 3 # "abcdef")
TC(2 2 3, ^ 2 -1 3 # "abcdefghijkl")
TC(14, ."2+3*4")
TC(2 4 7, & 0 0 1 0 1 0 0 1)
TC( 0 0 0 2 2 2 2, & 3 0 4)
TC(0 0 0, &3)
//End 'Where'. End Verbs.
//Begin Adverbs. Begin 'Each'
TC_("(!6;!4;!5)","!:' 6 4 5")
TC_("6 4 5"," #:'!:'6 4 5")
TC_("(1 0;2 1 0)", "|:'!:'2 3")
TC_("15 6 10", "+/' !:'6 4 5")
TC_("\"ab\"", "\"a\" ,' \"b\"")
TC_("1", "(\"a\",'\"b\") ~ \"a\" , \"b\"")
TC_("(\"ab\";\"ac\";\"ad\")"," \"a\" ,' \"bcd\"")
TC_("(\"ad\";\"bd\";\"cd\")"," \"abc\" ,' \"d\"")
TC_("(\"ad\";\"be\";\"cf\")"," \"abc\" ,' \"def\"")
//Begin 'Each Left'
TC((2 5 6 7;3 5 6 7;4 5 6 7), 2 3 4 ,\\: 5 6 7)
TC_("3 5 5 11 11", "-': 1 4 9 14 25 36")
TC((2 3 4 5;2 3 4 6;2 3 4 7) , 2 3 4 ,/: 5 6 7)
TC(3, 1 7 2 4 6 10 3 ? 4)
TC(7, 1 7 2 4 6 10 3 ? 4 3)
TC(3 6, 1 7 2 4 6 10 3 ?/: 4 3)
TC(16,10+/1 2 3)
TC(6,+/1 2 3)
TC(1, +/1)
TC(1, +/,1)
TC(9, |/1 4 -6 9 1 3)
TC(-6 , &/ 1 4 -6 9 1 3)
TC_("(\"a\";1;2;`bc;\"x\";\"y\";\"z\";2.35)",",//(\"a\";(1 2;`bc;(\"xyz\";2.35)))") //TC_ for raze ",//" (not comment)
TC_("25.0", "|/,//(1;(2.3 25.0;(6 7 -9;10)))" )
TC_("-9.0", "&/,//(1;(2.3 25;(6 7 -9;10)))" )
TC(1 4 9 16, +\\ 1 3 5 7)
//End Adverbs
//Amend, Index, Apply & Assign
TC(6 7 8, a:1 2 3;a+:5; a)
TC((0 2 4;1 3 5) , b: 3 2 # ! 6; r: b +:; b ) //manual has error
TC(((101 2 103;103 4 105);(103 105;101 103)) , a:(1 2 3;3 4 5); r: a[1 0;0 2] +: 100; (a;r) )
TC((10 11 12 13;(`ab;"cde");-8 -9 -10 -11), a:3 4#!12; a[1]:(`ab;"cde"); a[0]+:10;a[2] -:;a )
TC((101 2 103 4;101 103 ) ,a:1+!4;r: a[0 2] +: 100; (a;r) )
TC( (.,(`a;(`b;"c"))) , d:.,(`a;1 2 3); d[`a]: (`b;"c"); d)
TC_(".((`a;1;)\n (`b;1;)\n (`c;1;))","a[`a`b`c]:1;a")
//System Functions
TC(2#1.0, _abs - _cos 0 0)
//Names
TC( a.b_c.d:1;a.b_c.d, 1)
TC_("#:'(1;,1;1 2;1 2 3)","1 1 2 3")
TC_("skip", "#'(1;1 2)" "(#[1;];#[1 2;])") //This is true, and will pass, but set to skip until projections are actually compared correctly
TC_("a:(#'3 4 6)[0]; a 9", "9 9 9")
TC_(".'\"98\"", ".'\"98\"") // .'"98" was causing crash bug. now projects
TC(1, 4 _in 1 7 2 4 6 3)
TC(0, 4 3 _in 1 7 2 4 6 3)
TC(1 1, 4 3 _in\\: 1 7 2 4 6 3)
TC(skip,("abcdefg";"bdf"), dir:.((`a;2 3 4);(`b;"abcdefg")); (`dir . `b; `dir . (`b;1 3 5)) ) //dename without path creation
TC(skip,(1 2 3;"2+3";`button), c:.((`a;1 2 3);(`b;"2+3";.,(`c;`button))); (c.a;c.b;c.b..c))
TC(skip, 1 2, d:_n;d. 1 2) // d . or d. ?
TC(skip, _n, ."r:2+3*4")
//TC_("\"..\"" , "a:\"The quick. Brown fox.\"; b: & {(x=\" \") & y=\".\"}': a; a[b]")
TC(3, {x-2} 5)
TC(9.0, {x^2} @ 3)
TC(skip, 15, f:{a:10; :x+a; a:20}; f[5])
TC( 12 23, a:2 3;b:10 20; {a+b} . ,_n)
TC(skip, "{[x;y] x+y}", ${[x;y] x+y})
TC(6, {x+y+z}[1;2;3])
TC(6, g:{x+y+z}[1;;3]; g[2])
TC(6, h:{x+y+z}[1]; h[2;3])
TC(6, e:{x+y+z}[;2]; e[1;3])
TC(skip, (,5; 12 6 3) , f:{:[x ! 2; x; _ x %% 2]} ; (f\\ 5; f\\ 12) )
TC(skip, 640640 320320 160160 80080, b:{x>100000}; b f\\ 640640)
TC(skip, 2, {}$"1+1")
TC(("canoe";`dinghy;"kayak";66545;{x+y}) , ("canoe";`dinghy),("kayak";66545;{x+y}) )
TC(skip, 1++, 1+a:+) //Should seven_types merge sub-seven_types ?
TC(skip, +\\(!2;!3)) //error (adverbs check intermediate values)
TC((1;"index"), @[.:;"1+/() 1 2 3";:])
TC(640640, f:{:[x!2;x;_ x*0.5]}; (640640<) f/640640)
TC(320320, f:{:[x!2;x;_ x*0.5]}; (640639<) f/640640)
TC(5005, f:{:[x!2;x;_ x*0.5]}; (10000<) f/640640)
TC(5005, f:{:[x!2;x;_ x*0.5]}; {x>10000} f/640640)
TC((,640640), f:{:[x!2;x;_ x*0.5]}; (640640<) f\\640640)
TC(640640 320320, f:{:[x!2;x;_ x*0.5]}; (640639<) f\\640640)
TC(640640 320320 160160 80080 40040 20020 10010 5005,f:{:[x!2;x;_ x*0.5]}; (10000<) f\\640640)
TC(640640 320320 160160 80080 40040 20020 10010 5005,f:{:[x!2;x;_ x*0.5]}; {x>10000} f\\640640)
TC(1, a:`a`b`c!3 3#!9;b:.((`a;0 1 2);(`b;3 4 5);(`c;6 7 8));a~b )
TC((1;"type") , @[.:;"_sin _sin (;)";:])
TC((1;"type") , @[.:;"_sin _sin (0;)";:])
TC((1;"domain") , @[.:;".`\"1\"";:])
TC((1;"domain") , @[.:;".`\" \"";:])
TC((1;"domain") , @[.:;".`\"Ŕ̡̢͘͝x̀2́̀H̨̀͘l͘͞͞͠v̶̡͘͡k̷̡͞͝ ̛(̨͏͏͞Q̧͏y̵̴͘͠͡,̶̴̴̕͞\"";:])
TC(_n,.`"f")
TC(_n,.`".f")
TC(_n,.`".k.xyz")
TC(_n,.`".k.xyz.")
TC(_n,.`".k.xyz.b")
TC(_n,.`".k.xyz..b")
TC(_ssr[1], _ssr 1)
TC(_ssr[1;2], (_ssr 1) 2)
TC(_ssr[()], _ssr ())
TC(_ssr[("this";"is";,"at")], _ssr ("this";"is";,"at"))
TC("that", _ssr["this";"is";,"at"])
//Regressions
TC(2, _2.5)
R 0;
}
//K x; K zero=Ki(0); K a=Ki(9);
//K b = enumerate(a); K c = times(b,b); K d = plus(b,c); K e = times(enlist(promote(a)), promote(a));
//K f=newK(0,2); kK(f)[0]=b; kK(f)[1]=e; K empty=newK(0,0);
//K g=newK(0,4); kK(g)[0]=f; kK(g)[1]=empty; kK(g)[2]=f; kK(g)[3]=enumerate(zero);
//K h=enlist(enlist(enlist(enumerate(Ki(5)))));
//K i=plus(Ki(2),enumerate(Ki(3))); K j=take_reshape(reverse(plus(Ki(3),enumerate(Ki(3)))),enumerate(Ki(10)));
//K k=join(join(Ki(2),Kf(3.0)),Kc('c')); K l=take_reshape(Ki(3),Kc('d'));
//TODO: add a test to make sure wordfuncs (,/:) and (,\:) work and have valence 2
/*
show(enumerate(Ki(10)));
show(format_dyadic(Ki( 10),Kf(123.45678)));
show(format_dyadic(Ki(-10),Kf(123.45678)));
show(format_dyadic(Ki(3),Kf(123.45678)));
printf("%.*f\n",9, 123.123456789012345 );
*/
/*
show(Kf(1.2));
show(format(Kc('c')));
show(format(Kf(1.123456789)));
show(format(Ks(sp("what"))));
show(count(format(Ks(sp("ok")))));
show(count(format(Ks(sp("o")))));
show(count(format(Ks(sp("")))));
*/
/*
K z=newK(0,3);
DO(z->n, kK(z)[i]=enumerate(Ki(10)))
K e2=plus(Ki(1),enumerate(Ki(2)));
K je=join(enlist(join(enlist(e2),enlist(e2))),enlist(e2));
show(je);
show(dot(z,je));
*/
/*
//Dictionaries
K dict=newK(0,2);
kK(dict)[0]=newK(0,2);
kK(dict)[1]=newK(0,2);
x=kK(dict)[0];
kK(x)[0]=Ks(sp("a"));
kK(x)[1]=Ki(9);
x=kK(dict)[1];
kK(x)[0]=Ks(sp("b"));
kK(x)[1]=Kf(4.5);
//show(dict);
K gd=dot_monadic(dict);
//show(gd); P("%d\n", isKey(gd,sp("a"))); P("%d\n", isKey(gd,sp("b"))); P("%d\n", isKey(gd,sp("c")));
K d2=newK(0,2);
kK(d2)[0]=cl0ne(kK(dict)[0]);
K b2=newK(0,3);
kK(b2)[0]=Ks(sp("f"));
kK(b2)[1]=Kc('r');;
kK(b2)[2]=dot_monadic(dict);
kK(d2)[1]=b2;
K d3=newK(0,2);
kK(d3)[0]=join(Ks(sp("a")),Ks(sp("b")));
kK(d3)[1]=join(Ks(sp("c")),Ks(sp("d")));
//show(d2);
//show(dot_monadic(d2));
//show(dot_monadic(dot_monadic(d2)));
//show(dot_monadic(drop_cut(Ki(-1),d2)));
show(dot_monadic(d3));//Also a valid dictionary
show(at_verb(dot_monadic(dict), Ks(sp("a"))));
show(at_verb(dot_monadic(d2), Ks(sp("f"))));
show(at_verb(dot_monadic(d2), Kn()));
show(dot_monadic(d2));
show(dot(dot_monadic(d2),Kn()));
*/
//DO(10,dd(rp2(i)))
//printf("%d\n", rp2(-1)); printf("%d\n", rp2(0)); printf("%d\n", rp2(1)); printf("%d\n", rp2(2)); printf("%d\n", rp2(3)); printf("%d\n", rp2(4));
//printf("%d\n", rp2(5)); printf("%d\n", rp2(6)); printf("%d\n", rp2(7)); printf("%lld\n", rp2(8));