source: git/Tst/Short/countedref_s.tst @ 0054e7

spielwiese
Last change on this file since 0054e7 was ef52d6, checked in by Oleksandr Motsak <motsak@…>, 11 years ago
Update testsuite wrt current master (320c4f5e64cad778b4ada9556a9b0a6c71cab83a) NOTE: some wrong/bad tests were removed... TODO: add the reset of these updates after updating LIB/
  • Property mode set to 100644
File size: 14.2 KB
Line 
1// File: countedref_s.tst
2// Tests for reference and shared data types
3LIB "tst.lib";
4tst_init();
5
6system("reference");
7system("shared");
8
9
10
11
12// reference huhu=17;
13int koko=17;
14
15reference huhu=koko;
16// string(huhu);
17//string(huhu);
18int(huhu);
19//string(huhu);
20
21
22huhu;
23
24string(huhu);
25reference hihi = huhu;
26
27hihi;
28
29hihi;
30string(hihi);
31
32ring r=0,x,dp;
33
34number(hihi);
35int(hihi);
36
37hihi+huhu;
38hihi+huhu;
39hihi*hihi;
40
41hihi*12;
42huhu+10;
43hihi+10;
44
45
46
47int obj =19;
48reference pobj = obj;
49//attrib(pobj, "huhu","qweqw");
50
51//ython_run("def myprint(*args): print args");
52//attrib(myprint);
53//attrib(myprint, "func_name");
54
55kill obj, pobj;
56
57//attrib(myprint, "func_name", "byAnyOtherName");
58//attrib(myprint, "func_name");
59
60//list(huhu,huhu,hihi);
61
62"qwewqewqeqw";
63
64huhu;
65hihi;
66"da";
67huhu="qweeqw";
68"hier";
69huhu;
70hihi;
71
72typeof(huhu);
73
74int neunzehn = 19;
75reference ref1 =neunzehn;
76reference ref2 = ref1;
77def ref3=ref1;
78
79(ref1,ref2,ref3);
80//ref1=16;
81
82(ref1,ref2,ref3);
83list lllll = list(17,13);
84reference ref1 = lllll;
85ref2 = ref1;
86ref3=ref1;
87"huhu";
88
89
90ref1;ref2;ref3;
91
92//ref2[1]=9;
93ref1;ref2;ref3;
94ref_extract(ref2);
95ref_extract(ref1);
96
97
98list lll = list(1,2);
99reference lref = lll;
100
101lref;
102"lref[2]:";
103
104int elt = lref[2];
105elt;
106lref[2]=3;
107
108lref;
109//Countedref::setitem(lref,2,3);
110lref;
111//lref[2];
112"skip write";///lref[2]=8;
113//lref[2];
114"huhu";
115lref;
116"hihi";
117list ll=(1,2,3);
118ll[2];
119ll[2]=7;
120ll;
121
122
123
124reference part = ll[2];
125part;
126part=17;
127ll;
128
129typeof(part);
130
131
132ring r =0,(x,y,z),lp;
133
134poly p = x+y+z;
135
136reference pref = p;
137
138pref;
139
140ring q = 0,(x,y),lp;
141
142pref;
143
144
145setring(r);
146pref;
147poly ppp = 7;
148reference pppref = ppp;
149
150setring(q);
151poly pp=1;
152
153reference ppref = pp;
154
155
156pref + ppref;
157
158pref + pppref;
159
160setring(r);
161pref + pppref;
162kill pppref;
163ring r=0,(x,y,z),dp;
164poly f=x2+y2+z2+x+y+z;
165
166poly xp=x;
167poly yp=y;
168poly zp=z;
169reference fref = f;
170reference xref=xp;
171reference yref=yp;
172reference zref=zp;
173subst(f,x,link(yref),y,zp);
174subst(fref,x,yp,y,zp);
175subst(fref,x,yp,y,zref);
176
177ring r=0,(x,y,z),dp;
178poly p = x+y;
179reference ref7=p;
180ref7;
181ring q=0,(x,y),dp;
182ref7;
183poly p = x+y;
184ref7=p;
185ref7;
186
187newstruct("mystruct", "int i, int j");
188
189mystruct stru;
190stru.i = 17;
191
192//stru.j =19;
193stru.i;
194//stru;
195
196//reference sref = stru;
197
198//sref;
199//sref.i=9;
200//sref;
201//stru;
202
203reference spart = stru.i;
204//spart;
205//spart;
206//spart;
207spart =12;
208spart;
209stru;
210
211
212
213list listoflists = list(list(1,2,3));
214
215reference lolref = listoflists;
216
217lolref[1];
218
219lolref[1][2];
220lolref[1][2]=9;
221listoflists;
222mystruct ms;
223
224ms.i=2;
225ms.j=3;
226list listofnewstr = list(ms);
227
228
229
230reference lonren = listofnewstr;
231
232lonren[1];
233listofnewstr[1].i;// doesn'nt work
234
235reference refelt = listofnewstr[1];
236refelt.i = 7;
237
238lonren;
239listofnewstr;
240
241reference refelt2 =lonren[1];
242refelt2.i = 17;
243listofnewstr;
244
245
246//reference rseq=(1,2,3);
247
248//rseq;
249
250
251def copyref = refelt2;
252
253copyref;
254typeof(copyref);
255
256list ll17=list(1,2,4);
257shared sh17 = list(1,2,4);
258
259sh17;
260sh17[1]=7;
261
262sh17;
263
264reference ref17 = sh17;
265
266ref17[2]=19;
267sh17;
268
269shared ll19=ref17;
270ll19[3]=9;
271
272sh17;
273
274
275 typeof(link(sh17));
276
277shared sh19 = list(7,8,9);
278
279sh19;
280
281sh19[2]=5;
282sh19;
283
284
285list ll23;
286reference ref23 =ll23;
287ref23;
288
289
290kill ll23;
291ref23;
292
293list ll24 = list(1,2,3);
294shared data = ll24[2];
295shared dataA = data;
296data;
297typeof(data);
298data =17;
299typeof(data);
300
301data;
302dataA;
303
304
305typeof(link(data));
306
307//  list ll24 = list(1,2,3);
308ll24;
309
310shared data2 = ll24;
311typeof(link(data2));
312data2;
313data2[2];
314data2[2] =19;
315data2[2];
316data2;
317
318
319shared data3 =12;
320data3;
321data3 =13;
322data3;
323
324
325
326newstruct("teststruct","int i,int j");
327
328teststruct ts;
329reference tsref =ts;
330
331tsref.i=17;
332ts;
333
334
335shared tssh=ts;
336
337tssh.j = 9;
338
339ts;
340tssh;
341
342int ival=17;
343shared iref =ival;
344shared iref2 =iref;
345
346iref2 = 19;
347
348iref;
349iref2;
350ival;
351
352
353list lval=list(56,9);
354shared lRef =lval;
355shared lref2 =lRef;
356
357lref2 = list(324,253);
358
359lRef;
360lref2;
361lval;
362
363// some debugging commands
364
365int db; int db2;
366reference dbref = db;
367reference dbref2 = dbref;
368reference dbref3 = db;
369
370system(dbref, count);
371system(dbref, same, dbref);
372system(dbref, same, dbref2);
373system(dbref, same, dbref3);
374system(dbref, same, db2);
375
376system(dbref, likewise, dbref);
377system(dbref, likewise, dbref2);
378system(dbref, likewise, dbref3);
379system(dbref, like, dbref);
380system(dbref, like, dbref2);
381system(dbref, like, dbref3);
382system(dbref, like, db);
383system(dbref, like, db2);
384
385system(dbref, "typeof");
386system(dbref, "type");
387
388system(dbref, name);
389system(dbref2, name);
390
391system(dbref, enumerate) == system(dbref2, enumerate);
392system(dbref, enumerate) == system(dbref, enumerate);
393system(dbref, enumerate) != system(dbref3, enumerate);
394
395
396shared mem = 17;
397shared mem2 = mem;
398shared mem3 = link(mem);
399
400system(mem, count);
401system(mem, same, mem);
402system(mem, same, mem2);
403system(mem, same, mem3);
404system(mem, same, db2);
405
406system(mem, likewise, mem);
407system(mem, likewise, mem2);
408system(mem, likewise, mem3);
409system(mem, like, mem);
410system(mem, like, mem2);
411system(mem, like, mem3);
412system(mem, like, db);
413system(mem, like, db2);
414
415system(mem, "typeof");
416system(mem, "type");
417
418system(mem, name) == system(mem2, name);
419
420system(mem, enumerate) == system(mem2, enumerate);
421system(mem, enumerate) == system(mem, enumerate);
422system(mem, enumerate) != system(mem3, enumerate);
423
424reference memref = mem;
425system(mem, same, memref);
426system(mem, likewise, memref);
427
428// subexpressions
429shared shll =19;
430list llsh;
431llsh [1] = shll;
432typeof(llsh[1]);
433llsh;
434
435shared shll2 =12;
436
437llsh[1] = shll2;
438
439llsh;
440
441shll;
442
443shared shll3 =llsh[1];
444shll3 =14;
445
446
447llsh;
448
449shll;
450
451reference llshref = llsh[1];
452llshref = 13;
453llsh;
454shll;
455
456typeof(llsh[1]);
457
458
459shared sh5=5;
460
461list ll5=list(sh5);
462
463ll5[2]= sh5;
464ll5[2]=7;
465ll5;
466sh5;
467
468
469def defed = sh5;
470typeof(defed);
471defed=17;
472
473sh5;
474
475shared  shll6=list();
476
477shared shll7=shll6;
478shll6[1]=17;
479
480shll7;
481
482
483newstruct("mystrsh", "int i");
484
485mystrsh mystrval8;
486
487shared val8 = mystrval8;
488val8;
489
490shared val9= val8;
491val8.i=17;
492
493val9;
494
495newstruct("mystrsh2", "def sh");
496
497mystrsh2 mystrval10;
498
499shared val17 = 17;
500mystrval10.sh = val17;
501mystrsh2 mystrval11 = mystrval10;
502
503mystrval10;
504mystrval11;
505
506shared ref10sh= mystrval10.sh;
507ref10sh=10;
508
509mystrval11;
510system(mystrval11.sh, name)==system(mystrval10.sh, name);
511shared val11 =  mystrval11.sh;
512val11=9;
513mystrval11;
514mystrval10;
515
516
517shared(mystrval11.sh) = 11;
518
519
520
521mystrval10;
522system(mystrval11.sh, name)==system(mystrval10.sh, name);;
523
524shared myllsh= 19;
525list myllval;
526myllval[1]= myllsh;
527
528shared(myllval[1]) = 17;
529myllval;
530myllsh;
531
532shared(myllval[1]) = 18;
533myllval;
534myllsh;
535
536shared shvalOFmyllval_1 = myllval[1];
537shvalOFmyllval_1 = 3;
538myllsh;
539typeof(myllval[1]);
540
541
542
543proc replace(def lhs, def rhs) { lhs = rhs; }
544
545replace(myllval[1], 14);
546
547myllval;
548myllsh;
549
550shared(myllval[1]) =15;
551typeof(myllval[1]);
552
553myllval;
554myllsh;
555
556myllval[1] =16;
557
558typeof(myllval[1]);
559myllval;
560myllsh;
561
562link(myllsh);
563
564                                 
565shared val=1;
566val;         
567list ll=list(val);
568ll;               
569link(ll[1])=8;     
570val;             
571ll;
572shared vv =ll[1];
573vv=9;           
574ll;             
575vv;             
576val;
577reference vvv=ll[1];
578vvv=9;
579ll;   
580typeof(ll[1]);
581ll[1]=val;
582shared vv =ll[1];
583
584
585
586
587
588ring r2=0,x,dp;
589
590poly p = x+1;
591
592shared p_sh =p;
593
594
595ring r3=0,x,dp;
596
597p_sh;
598
599setring(r2);
600
601p_sh;
602
603
604
605kill mem, mem2, mem3;
606shared mem = list(17);
607shared mem2 = mem;
608shared mem3 = link(mem);
609
610system(mem, count);
611system(mem, same, mem);
612system(mem, same, mem2);
613system(mem, same, mem3);
614system(mem, same, db2);
615system(mem, like, mem);
616system(mem, like, mem2);
617system(mem, like, mem3);
618system(mem, like, db2);
619
620
621shared llr = list(1,2,3);
622
623llr;
624ring r=0,x,dp;
625
626llr[1]=x+1;
627
628llr;
629
630ring q=0,y,dp;
631
632llr;
633
634setring(r);
635
636llr;
637
638
639shared sharedp =x;
640sharedp;
641setring q;
642sharedp;
643setring(r);
644sharedp;
645setring q;
646sharedp=y;
647sharedp;
648
649setring(r);
650sharedp;
651setring q;
652sharedp;
653
654setring(r);
655poly xpoly=x;
656reference refp =xpoly;
657refp;
658setring q;
659refp;
660setring(r);
661refp;
662setring q;
663refp=y;
664refp;
665
666setring(r);
667refp;
668setring q;
669refp;
670
671
672
673kill ll, r, q;
674
675shared ll =list(1,2,3);
676 ring r=0,x,dp;
677ll[1] =x;
678ring q=0,y,dp;
679ll;
680ll[1];
681ll;
682setring r;
683ll;
684setring q;
685ll[1]=y;
686ll;
687setring r;
688ll;
689ll[1];
690setring q;
691ll[1];
692
693"qewqe";
694
695"qweewq";
696
697shared llshort=list(1,2);
698
699llshort;
700llshort[3]=17;
701
702llshort;
703
704/// Pratical examples: cache
705echo=1;
706newstruct("sqcache", "shared table");
707
708proc cached_square(sqcache cache, int arg)
709{
710  if (arg == 0) { return (0); }
711  shared value = cache.table[arg];
712  if (system(value, undef)) { value = arg^2; }
713  return (int(value));
714}
715
716system("install", "sqcache", "(", cached_square, 4);
717sqcache square;
718
719shared init = list();
720square.table = init;
721
722int t=timer;
723int i, j,k,n;
724n = 100;
725init=(0:n);
726  for( i = 0; i <n; i++) {
727   k = square(i);
728  }
729  for( i = 0; i <n; i++) {
730   k = square(i);
731  }
732  for( i = 0; i <n; i++) {
733   k = square(i);
734  }
735  for( i = 0; i <n; i++) {
736   k = square(i);
737  }
738  for( i = 0; i <n; i++) {
739   k = square(i);
740  }
741  for( i = 0; i <n; i++) {
742   k = square(i);
743  }
744  for( i = 0; i <n; i++) {
745   k = square(i);
746  }
747  for( i = 0; i <n; i++) {
748   k = square(i);
749  }
750  for( i = 0; i <n; i++) {
751   k = square(i);
752  }
753  for( i = 0; i <n; i++) {
754   k = square(i);
755  }
756
757
758
759int time1 = timer -t;
760t=timer;
761list cll=(0:n+1);
762  for( i = 1; i <=n; i++) {
763   cll[i] = (i^2);
764  }
765  for( i = 1; i <=n; i++) {
766   k = cll[i];
767  }
768  for( i = 1; i <=n; i++) {
769   k = cll[i];
770  }
771  for( i = 1; i <=n; i++) {
772   k = cll[i];
773  }
774  for( i = 1; i <=n; i++) {
775   k = cll[i];
776  }
777  for( i = 1; i <=n; i++) {
778   k = cll[i];
779  }
780  for( i = 1; i <=n; i++) {
781   k = cll[i];
782  }
783  for( i = 1; i <=n; i++) {
784   k = cll[i];
785  }
786  for( i = 1; i <=n; i++) {
787   k = cll[i];
788  }
789  for( i = 1; i <=n; i++) {
790   k = cll[i];
791  }
792
793
794
795
796
797int time2 = timer -t;
798
799
800
801
802//time1;
803//time2;
804
805
806newstruct("bdd", "int idx,shared high,shared low");
807bdd diag;
808shared zero=0;
809diag.high=zero;
810diag.low=zero;
811diag.idx = 0;
812
813//for (i=0; i <=n; i++)
814n=20;
815proc chain(shared arg)
816{
817bdd diag;
818diag.idx = arg.idx+1;
819diag.high=arg;
820diag.low=arg;
821return (diag);
822}
823
824
825t=timer;
826for (i=0; i<=n; i++ )
827{
828  diag = chain(diag);
829}
830//timer-t;
831
832shared iter=diag;
833//while(int(iter.idx)) {
834//  iter.idx;
835//  iter = iter.high;
836//}
837
838proc print_bdd(shared iter) {
839  string res = "("+string(iter.idx)+", ";
840  shared it1=iter.high;
841  shared it0=iter.low;
842
843 if (int(iter.idx))
844 {
845  res=res +  print_bdd(it1) + " : ";
846  res= res+ print_bdd(it0)+ ")";
847 }
848 return (res);// print_bdd(iter.low);
849}
850shared iter2=diag;
851
852//print_bdd(iter2);
853
854newstruct("bdd0", "int idx,def high,def low");
855bdd0 diag0;
856diag0.idx=0;
857diag0.high=0;
858diag0.low=0;
859
860
861proc chain0(bdd0 arg)
862{
863bdd0 diag;
864diag.idx = arg.idx+1;
865diag.high=arg;
866diag.low=arg;
867return (diag);
868}
869
870/// Deactivate "classical" way, take too long (many copies)
871n=0;
872t=timer;
873def val;
874for (i=0; i<=n; i++ )
875{
876  val =chain0(diag0);
877   diag0=val;
878}
879//timer-t;
880
881proc print_bdd0(def iter) {
882  string res = "("+string(iter.idx)+", ";
883  def it1=iter.high;
884  def it0=iter.low;
885
886 if (int(iter.idx))
887 {
888  res=res +  print_bdd0(it1) + " : ";
889  res= res+ print_bdd0(it0)+ ")";
890 }
891 return (res);// print_bdd(iter.low);
892}
893
894
895//print_bdd0(diag0);
896
897//diag;
898
899kill sh17,sh18;
900bdd b01;
901
902(b01.idx)=0;
903shared sh17=17;
904shared sh18=18;
905b01.high = sh17;
906b01.low  = sh18;
907
908
909b01.high;
910b01.low;
911
912def(b01.high) = 19;
913def(b01.low)  = 20;
914
915b01.high;
916b01.low;
917
918sh17;
919sh18;
920kill ll;
921
922shared ll1=1; shared ll2=2;
923list ll=list(ll1, ll2);
924typeof(ll[1]);
925
926
927def(ll[1]) = 3;
928ll;
929ll1;
930typeof(ll[1]);
931
932
933shared(ll[1]) = 5;
934ll;
935ll1;
936typeof(ll[1]);
937
938
939shared ll3=2;
940
941ll[3]=ll3;
942
943typeof(ll[3]);
944ll;
945
946def(ll[3])=4;
947
948ll3; ll;
949typeof(ll[3]);
950
951ll[4]=1;
952
953ll[4] = ll3;
954ll;
955def(ll[4])=17;
956ll;
957
958
959bdd b02;
960
961b02.high;
962def(b02.high);
963def(b02.high)=9;
964
965b02.high;
966typeof(b02.high);
967
968kill ll;
969
970list ll;
971ll[1] = ll1;
972shared(ll[1]) = 3333;
973ll;
974
975
976
977kill ll;
978
979shared ll=list();
980shared llsync=ll;
981def(ll[1])=list(3,4);
982ll;
983
984def(def(ll[1])[3])=list(5,6);
985ll;
986
987def(ll[1])[3]=list(8);
988ll;
989
990
991ll[1][3]=list(6);
992ll;
993llsync;
994
995kill sh;
996newstruct("bbx", "def i");
997bbx box;
998
999shared sh=box;
1000sh;
1001sh.i =list(1,2);
1002sh;
1003
1004sh.i[2]=19;
1005
1006sh;
1007sh.i;
1008
1009system(sh, "help");
1010
1011
1012kill i, iref;
1013int i =9;
1014shared iref = i;
1015link l1 = "ssi:fork"; open(l1);
1016write(l1, quote(list(iref, iref)));
1017
1018waitfirst(list(l1), 500);
1019def argi = read(l1);
1020argi;
1021typeof(argi[1]);
1022typeof(argi[2]);
1023
1024
1025//typeof(link(argi));
1026close(l1);
1027
1028
1029kill i, iref,l1;
1030int i =9;
1031reference iref = i;
1032link l1 = "ssi:fork"; open(l1);
1033write(l1, quote(def(iref)));
1034
1035waitfirst(list(l1), 500);
1036def argi = read(l1);
1037argi;
1038typeof(argi);
1039typeof(link(argi));
1040close(l1);
1041
1042i=10;
1043argi;
1044
1045shared backtest=list(17,9);
1046
1047backtest;
1048
1049shared backtest_1 = backtest[1];
1050
1051backtest_1;
1052
1053backtest_1=6;
1054backtest;
1055kill backtest;
1056
1057backtest_1;
1058
1059backtest_1;
1060
1061kill i, ll;
1062int i = 17;
1063reference ref = i;
1064
1065ref;
1066ref + ref;  // Automated 'dereferencing'
1067ref + 4;
10684 + ref;
1069
1070
1071list ll=(1,2,3,4,5);
1072ref=3;
1073ll[ref];
1074
1075kill r;
1076ring r=0,(x,y,z),dp;
1077poly p = x+y+z;
1078shared xsh = x+1;
1079poly(xsh);
1080poly(xsh);
1081poly(xsh);
1082
1083
1084
1085// Checking side effects
1086list changeme;
1087changeme;
1088
1089proc setfirst(reference ll, def arg) { ll[1] = arg; }
1090
1091setfirst(changeme, 17);
1092changeme;
1093
1094// Checking differenct variants of list conversion
1095
1096shared shlist = list(1,2,3);
1097list thelist = shlist;
1098thelist;
1099list(shlist);
1100link(shlist);
1101
1102/// Checking that link deeply copies indeed
1103kill r, xsh, ll;
1104ring r = 0, (x,y,z), dp;
1105poly p = x + y + z;
1106shared xsh = x;
1107
1108subst(p, xsh,1, y,2, z,3);        // fails
1109subst(p, poly(xsh),1, y,2, z,3);  // good
1110subst(p, link(xsh),1, y,2, z,3);  // fine
1111subst(p, link(xsh),1, y,2, z,3);  // fine
1112subst(p, link(xsh),1, y,2, z,3);  // fine
1113
1114list ll = list(xsh, xsh, xsh);
1115ll[1] = y;      // replaced only first entry
1116ll;
1117shared(ll[2]) = z;    // replaces the others
1118ll;
1119def(ll[2]) = x;       // generic alternative
1120ll;
1121
1122// --------------------------------------------------------
1123kill r, ref, ref2;
1124ring r;ideal I = maxideal(1);ideal J = I;
1125reference ref = I;
1126
1127attrib(ref, "huhu", 11);
1128
1129attrib(ref, "huhu");
1130attrib(I, "huhu");
1131
1132attrib(ref, "huhu", 111);
1133
1134attrib(ref, "huhu");
1135attrib(I, "huhu");
1136
1137
1138reference ref2= I;
1139attrib(ref2, "huhu");
1140
1141attrib(ref, "hihi", 12);
1142
1143attrib(ref, "huhu");
1144attrib(I, "huhu");
1145attrib(ref, "hihi");
1146attrib(I, "hihi");
1147
1148attrib(ref2, "huhu");
1149attrib(ref2, "hihi");
1150
1151attrib(I, "isSB");
1152attrib(ref2, "isSB");
1153
1154attrib(ref2, "isSB", 0);
1155
1156attrib(I, "isSB");
1157
1158
1159attrib(ref2, "isSB");
1160
1161
1162
1163attrib(I, "isSB", 1);
1164attrib(I, "isSB");
1165
1166attrib(ref2, "isSB");
1167
1168shared shval= I;
1169// Ensure reloading does not damage something
1170system("reference");
1171system("shared");
1172reference refTwo = ref2;
1173shared shval2 = shval;
1174refTwo;
1175shval2[1] == shval[1];
1176kill refTwo, shval2;
1177system("reference");
1178system("shared");
1179reference refTwo = ref2;
1180shared shval2 = shval;
1181refTwo;
1182shval2[1] == shval[1];
1183kill refTwo, shval2;
1184
1185// --------------------------------------------------------
1186tst_status(1);$
1187
Note: See TracBrowser for help on using the repository browser.