Skip to content

Commit

Permalink
More kernel tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Sep 2, 2018
1 parent 6aa06f5 commit e3ac042
Show file tree
Hide file tree
Showing 5 changed files with 451 additions and 19 deletions.
293 changes: 293 additions & 0 deletions tst/testinstall/coder.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@
#
# Tests for the GAP coder logic.
#
# For now this mostly focuses on testing edge cases and error
# handling in the coder.
#
# The files coder.tst and interpreter.tst closely mirror each other.
#
gap> START_TEST("coder.tst");

#
# function call with options
#
gap> f:=x->ValueOption("a");;
gap> ({}-> f(1) )();
fail
gap> ({}-> f(1 : a) )();
true
gap> ({}-> f(1 : ("a") ) )();
true
gap> ({}-> f(1 : a := 23) )();
23
gap> ({}-> f(1 : ("a") := 23 ) )();
23

#
# records
#
gap> function()
> local r;
> r := rec(a:=1);
> Display(r);
> r.a := 1;
> Display(r.a);
> Display(IsBound(r.a));
> Unbind(r.a);
> return r;
> end();
rec(
a := 1 )
1
true
rec( )

#
gap> function()
> local r;
> r := rec(a:=1);
> Display(r);
> r!.a := 1;
> Display(r!.a);
> Display(IsBound(r!.a));
> Unbind(r!.a);
> return r;
> end();
rec(
a := 1 )
1
true
rec( )

#
gap> function()
> local r;
> r := rec(("a"):=1);
> Display(r);
> r.("a") := 1;
> Display(r.("a"));
> Display(IsBound(r.("a")));
> Unbind(r.("a"));
> return r;
> end();
rec(
a := 1 )
1
true
rec( )

#
gap> function()
> local r;
> r := rec(("a"):=1);
> Display(r);
> r!.("a") := 1;
> Display(r!.("a"));
> Display(IsBound(r!.("a")));
> Unbind(r!.("a"));
> return r;
> end();
rec(
a := 1 )
1
true
rec( )

#
# component objects (atomic by default in HPC-GAP)
#
gap> r := Objectify(NewType(NewFamily("MockFamily"), IsComponentObjectRep), rec());;

#
gap> function()
> r!.a := 1;
> Display(r!.a);
> Display(IsBound(r!.a));
> Unbind(r!.a);
> Display(IsBound(r!.a));
> end();
1
true
false

#
gap> function()
> r!.("a") := 1;
> Display(r!.("a"));
> Display(IsBound(r!.("a")));
> Unbind(r!.("a"));
> Display(IsBound(r!.("a")));
> end();
1
true
false

#
# lists
#
gap> function()
> local l;
> l:=[1,2,3];
> Display(l);
> l[1] := 42;
> Display(l[1]);
> Display(IsBound(l[1]));
> Unbind(l[1]);
> Display(l);
> l{[1,3]} := [42, 23];
> Display(l);
> Display(l{[3,1]});
> end();
[ 1, 2, 3 ]
42
true
[ , 2, 3 ]
[ 42, 2, 23 ]
[ 23, 42 ]
gap> function()
> local l;
> l:=[1,2,3];
> IsBound(l{[1,3]});
> end;
Syntax error: statement expected in stream:4
IsBound(l{[1,3]});
^^^^^^^
gap> function()
> local l;
> l:=[1,2,3];
> Unbind(l{[1,3]});
> end;
Syntax error: Illegal operand for 'Unbind' in stream:4
Unbind(l{[1,3]});
^

#
gap> f:=function()
> local l;
> l:=[1,2,3];
> Display(l);
> l![1] := 42;
> Display(l![1]);
> Display(IsBound(l![1]));
> Unbind(l![1]);
> Display(l);
> end;;
gap> Display(f);
function ( )
local l;
l := [ 1, 2, 3 ];
Display( l );
l![1] := 42;
Display( l![1] );
Display( IsBound( l![1] ) );
Unbind( l![1] );
Display( l );
return;
end
gap> f();
[ 1, 2, 3 ]
42
true
[ , 2, 3 ]

#
gap> l := [1,2,3];;
gap> function() l![fail] := 42; end();
Error, PosObj Assignment: <position> must be a positive integer (not a boolean\
or fail)
gap> function() return l![fail]; end();
Error, PosObj Element: <position> must be a positive integer (not a boolean or\
fail)
gap> function() return IsBound(l![fail]); end();
Error, PosObj Element: <position> must be a positive integer (not a boolean or\
fail)
gap> function() Unbind(l![fail]); end();
Error, PosObj Assignment: <position> must be a positive integer (not a boolean\
or fail)

#
# posobj
#
gap> l := Objectify(NewType(NewFamily("MockFamily"), IsPositionalObjectRep),[]);;

#
gap> l![1] := 42;
42
gap> l![1];
42
gap> IsBound(l![1]);
true
gap> Unbind(l![1]);
gap> IsBound(l![1]);
false

#
gap> function()
> l![1] := 42;
> Display(l![1]);
> Display(IsBound(l![1]));
> Unbind(l![1]);
> Display(IsBound(l![1]));
> end();
42
true
false

#
gap> function() l![fail] := 42; end();
Error, PosObj Assignment: <position> must be a positive integer (not a boolean\
or fail)
gap> function() return l![fail]; end();
Error, PosObj Element: <position> must be a positive integer (not a boolean or\
fail)
gap> function() return IsBound(l![fail]); end();
Error, PosObj Element: <position> must be a positive integer (not a boolean or\
fail)
gap> function() Unbind(l![fail]); end();
Error, PosObj Assignment: <position> must be a positive integer (not a boolean\
or fail)

#
# atomic posobj (HPC-GAP)
#
gap> l := Objectify(NewType(NewFamily("MockFamily"), IsAtomicPositionalObjectRep),[23]);;

#
gap> l![1] := 42;
42
gap> l![1];
42
gap> IsBound(l![1]);
true
gap> Unbind(l![1]);
gap> IsBound(l![1]);
false

#
gap> function()
> l![1] := 42;
> Display(l![1]);
> Display(IsBound(l![1]));
> Unbind(l![1]);
> Display(IsBound(l![1]));
> end();
42
true
false

#
gap> function() l![fail] := 42; end();
Error, PosObj Assignment: <position> must be a positive integer (not a boolean\
or fail)
gap> function() return l![fail]; end();
Error, PosObj Element: <position> must be a positive integer (not a boolean or\
fail)
gap> function() return IsBound(l![fail]); end();
Error, PosObj Element: <position> must be a positive integer (not a boolean or\
fail)
gap> function() Unbind(l![fail]); end();
Error, PosObj Assignment: <position> must be a positive integer (not a boolean\
or fail)

#
gap> STOP_TEST("coder.tst", 1);
14 changes: 11 additions & 3 deletions tst/testinstall/integer.tst
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,24 @@ gap> last = List([1..10], n->PrimeDivisors(-n));
true

#
gap> n:=(2^31-1)*(2^61-1);;
gap> n:=(2^31-1)*(2^61-1);; # product of two "small" primes
gap> PartialFactorization(n);
[ 2147483647, 2305843009213693951 ]
gap> FactorsInt(n);
[ 2147483647, 2305843009213693951 ]
gap> PartialFactorization(2^155-19);
gap> n:=2^155-19;; # not a prime; GAP fails to fully factorize it, though FactInt finds all 4 factors
gap> PartialFactorization(n);
[ 167, 273484587823896504154881143846609846492502347 ]
gap> n:=(2^2203-1)*(2^2281-1);;
gap> n:=(2^2203-1)*(2^2281-1);; # product of two "large" primes
gap> PartialFactorization(n) = [ n ];
true
gap> n:=2^255-19;; # this is a "large" prime for which GAP only knows it is probably prime
gap> PartialFactorization(n) = [ n ];
true
gap> FactorsInt(n) = [ n ];
#I FactorsInt: used the following factor(s) which are probably primes:
#I 57896044618658097711785492504343953926634992332820282019728792003956564819949
true

#
gap> Filtered([-4..20], IsPrimePowerInt);
Expand Down
Loading

0 comments on commit e3ac042

Please sign in to comment.