Skip to content

Commit e3ac042

Browse files
committed
More kernel tests
1 parent 6aa06f5 commit e3ac042

File tree

5 files changed

+451
-19
lines changed

5 files changed

+451
-19
lines changed

tst/testinstall/coder.tst

Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
#
2+
# Tests for the GAP coder logic.
3+
#
4+
# For now this mostly focuses on testing edge cases and error
5+
# handling in the coder.
6+
#
7+
# The files coder.tst and interpreter.tst closely mirror each other.
8+
#
9+
gap> START_TEST("coder.tst");
10+
11+
#
12+
# function call with options
13+
#
14+
gap> f:=x->ValueOption("a");;
15+
gap> ({}-> f(1) )();
16+
fail
17+
gap> ({}-> f(1 : a) )();
18+
true
19+
gap> ({}-> f(1 : ("a") ) )();
20+
true
21+
gap> ({}-> f(1 : a := 23) )();
22+
23
23+
gap> ({}-> f(1 : ("a") := 23 ) )();
24+
23
25+
26+
#
27+
# records
28+
#
29+
gap> function()
30+
> local r;
31+
> r := rec(a:=1);
32+
> Display(r);
33+
> r.a := 1;
34+
> Display(r.a);
35+
> Display(IsBound(r.a));
36+
> Unbind(r.a);
37+
> return r;
38+
> end();
39+
rec(
40+
a := 1 )
41+
1
42+
true
43+
rec( )
44+
45+
#
46+
gap> function()
47+
> local r;
48+
> r := rec(a:=1);
49+
> Display(r);
50+
> r!.a := 1;
51+
> Display(r!.a);
52+
> Display(IsBound(r!.a));
53+
> Unbind(r!.a);
54+
> return r;
55+
> end();
56+
rec(
57+
a := 1 )
58+
1
59+
true
60+
rec( )
61+
62+
#
63+
gap> function()
64+
> local r;
65+
> r := rec(("a"):=1);
66+
> Display(r);
67+
> r.("a") := 1;
68+
> Display(r.("a"));
69+
> Display(IsBound(r.("a")));
70+
> Unbind(r.("a"));
71+
> return r;
72+
> end();
73+
rec(
74+
a := 1 )
75+
1
76+
true
77+
rec( )
78+
79+
#
80+
gap> function()
81+
> local r;
82+
> r := rec(("a"):=1);
83+
> Display(r);
84+
> r!.("a") := 1;
85+
> Display(r!.("a"));
86+
> Display(IsBound(r!.("a")));
87+
> Unbind(r!.("a"));
88+
> return r;
89+
> end();
90+
rec(
91+
a := 1 )
92+
1
93+
true
94+
rec( )
95+
96+
#
97+
# component objects (atomic by default in HPC-GAP)
98+
#
99+
gap> r := Objectify(NewType(NewFamily("MockFamily"), IsComponentObjectRep), rec());;
100+
101+
#
102+
gap> function()
103+
> r!.a := 1;
104+
> Display(r!.a);
105+
> Display(IsBound(r!.a));
106+
> Unbind(r!.a);
107+
> Display(IsBound(r!.a));
108+
> end();
109+
1
110+
true
111+
false
112+
113+
#
114+
gap> function()
115+
> r!.("a") := 1;
116+
> Display(r!.("a"));
117+
> Display(IsBound(r!.("a")));
118+
> Unbind(r!.("a"));
119+
> Display(IsBound(r!.("a")));
120+
> end();
121+
1
122+
true
123+
false
124+
125+
#
126+
# lists
127+
#
128+
gap> function()
129+
> local l;
130+
> l:=[1,2,3];
131+
> Display(l);
132+
> l[1] := 42;
133+
> Display(l[1]);
134+
> Display(IsBound(l[1]));
135+
> Unbind(l[1]);
136+
> Display(l);
137+
> l{[1,3]} := [42, 23];
138+
> Display(l);
139+
> Display(l{[3,1]});
140+
> end();
141+
[ 1, 2, 3 ]
142+
42
143+
true
144+
[ , 2, 3 ]
145+
[ 42, 2, 23 ]
146+
[ 23, 42 ]
147+
gap> function()
148+
> local l;
149+
> l:=[1,2,3];
150+
> IsBound(l{[1,3]});
151+
> end;
152+
Syntax error: statement expected in stream:4
153+
IsBound(l{[1,3]});
154+
^^^^^^^
155+
gap> function()
156+
> local l;
157+
> l:=[1,2,3];
158+
> Unbind(l{[1,3]});
159+
> end;
160+
Syntax error: Illegal operand for 'Unbind' in stream:4
161+
Unbind(l{[1,3]});
162+
^
163+
164+
#
165+
gap> f:=function()
166+
> local l;
167+
> l:=[1,2,3];
168+
> Display(l);
169+
> l![1] := 42;
170+
> Display(l![1]);
171+
> Display(IsBound(l![1]));
172+
> Unbind(l![1]);
173+
> Display(l);
174+
> end;;
175+
gap> Display(f);
176+
function ( )
177+
local l;
178+
l := [ 1, 2, 3 ];
179+
Display( l );
180+
l![1] := 42;
181+
Display( l![1] );
182+
Display( IsBound( l![1] ) );
183+
Unbind( l![1] );
184+
Display( l );
185+
return;
186+
end
187+
gap> f();
188+
[ 1, 2, 3 ]
189+
42
190+
true
191+
[ , 2, 3 ]
192+
193+
#
194+
gap> l := [1,2,3];;
195+
gap> function() l![fail] := 42; end();
196+
Error, PosObj Assignment: <position> must be a positive integer (not a boolean\
197+
or fail)
198+
gap> function() return l![fail]; end();
199+
Error, PosObj Element: <position> must be a positive integer (not a boolean or\
200+
fail)
201+
gap> function() return IsBound(l![fail]); end();
202+
Error, PosObj Element: <position> must be a positive integer (not a boolean or\
203+
fail)
204+
gap> function() Unbind(l![fail]); end();
205+
Error, PosObj Assignment: <position> must be a positive integer (not a boolean\
206+
or fail)
207+
208+
#
209+
# posobj
210+
#
211+
gap> l := Objectify(NewType(NewFamily("MockFamily"), IsPositionalObjectRep),[]);;
212+
213+
#
214+
gap> l![1] := 42;
215+
42
216+
gap> l![1];
217+
42
218+
gap> IsBound(l![1]);
219+
true
220+
gap> Unbind(l![1]);
221+
gap> IsBound(l![1]);
222+
false
223+
224+
#
225+
gap> function()
226+
> l![1] := 42;
227+
> Display(l![1]);
228+
> Display(IsBound(l![1]));
229+
> Unbind(l![1]);
230+
> Display(IsBound(l![1]));
231+
> end();
232+
42
233+
true
234+
false
235+
236+
#
237+
gap> function() l![fail] := 42; end();
238+
Error, PosObj Assignment: <position> must be a positive integer (not a boolean\
239+
or fail)
240+
gap> function() return l![fail]; end();
241+
Error, PosObj Element: <position> must be a positive integer (not a boolean or\
242+
fail)
243+
gap> function() return IsBound(l![fail]); end();
244+
Error, PosObj Element: <position> must be a positive integer (not a boolean or\
245+
fail)
246+
gap> function() Unbind(l![fail]); end();
247+
Error, PosObj Assignment: <position> must be a positive integer (not a boolean\
248+
or fail)
249+
250+
#
251+
# atomic posobj (HPC-GAP)
252+
#
253+
gap> l := Objectify(NewType(NewFamily("MockFamily"), IsAtomicPositionalObjectRep),[23]);;
254+
255+
#
256+
gap> l![1] := 42;
257+
42
258+
gap> l![1];
259+
42
260+
gap> IsBound(l![1]);
261+
true
262+
gap> Unbind(l![1]);
263+
gap> IsBound(l![1]);
264+
false
265+
266+
#
267+
gap> function()
268+
> l![1] := 42;
269+
> Display(l![1]);
270+
> Display(IsBound(l![1]));
271+
> Unbind(l![1]);
272+
> Display(IsBound(l![1]));
273+
> end();
274+
42
275+
true
276+
false
277+
278+
#
279+
gap> function() l![fail] := 42; end();
280+
Error, PosObj Assignment: <position> must be a positive integer (not a boolean\
281+
or fail)
282+
gap> function() return l![fail]; end();
283+
Error, PosObj Element: <position> must be a positive integer (not a boolean or\
284+
fail)
285+
gap> function() return IsBound(l![fail]); end();
286+
Error, PosObj Element: <position> must be a positive integer (not a boolean or\
287+
fail)
288+
gap> function() Unbind(l![fail]); end();
289+
Error, PosObj Assignment: <position> must be a positive integer (not a boolean\
290+
or fail)
291+
292+
#
293+
gap> STOP_TEST("coder.tst", 1);

tst/testinstall/integer.tst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,24 @@ gap> last = List([1..10], n->PrimeDivisors(-n));
3939
true
4040

4141
#
42-
gap> n:=(2^31-1)*(2^61-1);;
42+
gap> n:=(2^31-1)*(2^61-1);; # product of two "small" primes
4343
gap> PartialFactorization(n);
4444
[ 2147483647, 2305843009213693951 ]
4545
gap> FactorsInt(n);
4646
[ 2147483647, 2305843009213693951 ]
47-
gap> PartialFactorization(2^155-19);
47+
gap> n:=2^155-19;; # not a prime; GAP fails to fully factorize it, though FactInt finds all 4 factors
48+
gap> PartialFactorization(n);
4849
[ 167, 273484587823896504154881143846609846492502347 ]
49-
gap> n:=(2^2203-1)*(2^2281-1);;
50+
gap> n:=(2^2203-1)*(2^2281-1);; # product of two "large" primes
51+
gap> PartialFactorization(n) = [ n ];
52+
true
53+
gap> n:=2^255-19;; # this is a "large" prime for which GAP only knows it is probably prime
5054
gap> PartialFactorization(n) = [ n ];
5155
true
56+
gap> FactorsInt(n) = [ n ];
57+
#I FactorsInt: used the following factor(s) which are probably primes:
58+
#I 57896044618658097711785492504343953926634992332820282019728792003956564819949
59+
true
5260

5361
#
5462
gap> Filtered([-4..20], IsPrimePowerInt);

0 commit comments

Comments
 (0)