Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Aug 17, 2018
1 parent 694f45d commit 808110d
Show file tree
Hide file tree
Showing 4 changed files with 362 additions and 0 deletions.
96 changes: 96 additions & 0 deletions tst/testinstall/float.tst
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ gap> 355/113.0 - 355.0/113;
gap> 355/113.0 = 355.0/113;
true

#
gap> 2.0^2;
4.
gap> 2.0^-2;
0.25
gap> 2.0^2.;
4.
gap> 2.0^-2.;
0.25

#
gap> LeftQuotient(1.0, 2.0);
2.
gap> LeftQuotient(2.0, 1.0);
0.5

#
# convert floats to other types
#
Expand All @@ -90,6 +106,18 @@ gap> Rat(0.5);
gap> Rat(0.0);
0

#
# Print / View / Display for floats
#
gap> l := [ 0.0, -0.0, 1.0, Sqrt(2.0), posinf, neginf, nan ];
[ 0., -0., 1., 1.41421, inf, -inf, nan ]
gap> ViewObj(l); Print("\n");
[ 0., -0., 1., 1.41421, inf, -inf, nan ]
gap> PrintObj(l); Print("\n");
[ 0, -0, 1, 1.414213562373095, inf, -inf, nan ]
gap> Display(l);
[ 0, -0, 1, 1.414213562373095, inf, -inf, nan ]

#
#
#
Expand Down Expand Up @@ -286,6 +314,74 @@ function ( )
return 23.0;
end

#
#
#
gap> Cos(0.);
1.
gap> Sin(0.);
0.
gap> Tan(0.);
0.
gap> Acos(1.);
0.
gap> Asin(0.);
0.
gap> Log(1.);
0.
gap> Exp(0.);
1.
gap> if IsBound(Log2) then Assert(0, Log2(1.) = 0.); fi;
gap> if IsBound(Log10) then Assert(0, Log10(1.) = 0.); fi;
gap> if IsBound(Log1p) then Assert(0, Log1p(0.) = 0.); fi;
gap> if IsBound(Exp2) then Assert(0, Exp2(0.) = 1.); fi;
gap> if IsBound(Exp10) then Assert(0, Exp10(0.) = 1.); fi;
gap> if IsBound(Expm1) then Assert(0, Expm1(0.) = 0.); fi;

#
gap> Round(1.3);
1.
gap> Round(1.9);
2.
gap> Round(-1.9);
-2.
gap> Round(-1.3);
-1.

#
gap> Floor(1.3);
1.
gap> Floor(1.9);
1.
gap> Floor(-1.9);
-2.
gap> Floor(-1.3);
-2.

#
gap> Ceil(1.3);
2.
gap> Ceil(1.9);
2.
gap> Ceil(-1.9);
-1.
gap> Ceil(-1.3);
-1.

#
gap> AbsoluteValue(1.3);
1.3
gap> AbsoluteValue(1.9);
1.9
gap> AbsoluteValue(-1.9);
1.9
gap> AbsoluteValue(-1.3);
1.3

#
gap> Hypothenuse(3.,4.);
5.

#
gap> STOP_TEST( "float.tst", 1);

Expand Down
160 changes: 160 additions & 0 deletions tst/testinstall/kernel/ariths.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#
# Tests for functions defined in src/ariths.c
#
gap> START_TEST("kernel/ariths.tst");

# InUndefined
gap> 1 in 2;
Error, operations: IN of integer and integer is not defined

#
# Test the various "VerboseFOO" handlers,
# and also their "method should have returned a value" checks
#
gap> fam := NewFamily("MockFamily");;
gap> cat := NewCategory("IsMockObj",
> IsMultiplicativeElementWithInverse and
> IsAdditiveElementWithInverse and
> IsCommutativeElement and
> IsAssociativeElement and
> IsAdditivelyCommutativeElement);;
gap> type := NewType(fam, cat and IsPositionalObjectRep);;
gap> a := Objectify(type,[2]);;
gap> b := Objectify(type,[3]);;

# unary
gap> unary := [
> Zero,
> ZeroMutable,
> AdditiveInverse,
> AdditiveInverseMutable,
> One,
> OneMutable,
> Inverse,
> InverseMutable,
> ];;
gap> for m in unary do InstallMethod(m, [cat], ReturnNothing); od;

# binary
gap> binary := [
> \=,
> \<,
> \in,
> \+,
> \-,
> \*,
> \/,
> LeftQuotient,
> \^,
> Comm,
> \mod,
> ];;
gap> for m in binary do InstallMethod(m, [cat, cat], ReturnNothing); od;

#
gap> Zero(a);
Error, Method for an attribute must return a value
gap> ZeroMutable(a);
Error, ZeroOp: method should have returned a value
gap> -a;
Error, Method for an attribute must return a value
gap> AdditiveInverseMutable(a);
Error, AdditiveInverseOp: method should have returned a value
gap> One(a);
Error, Method for an attribute must return a value
gap> OneMutable(a);
Error, OneOp: method should have returned a value
gap> Inverse(a);
Error, Method for an attribute must return a value
gap> InverseMutable(a);
Error, InvOp: method should have returned a value
gap> a = b;
false
gap> a < b;
false
gap> a in b;
false
gap> a + b;
Error, SUM: method should have returned a value
gap> a - b;
Error, DIFF: method should have returned a value
gap> a * b;
Error, PROD: method should have returned a value
gap> a / b;
Error, QUO: method should have returned a value
gap> LeftQuotient(a, b);
Error, LeftQuotient: method should have returned a value
gap> a ^ b;
Error, POW: method should have returned a value
gap> Comm(a, b);
Error, Comm: method should have returned a value
gap> a mod b;
Error, mod: method should have returned a value

#
gap> meths := Concatenation(unary, binary);;
gap> TraceMethods(meths);

#
gap> Zero(a);
#I ZeroImmutable at stream:1
Error, Method for an attribute must return a value
gap> ZeroMutable(a);
#I ZeroMutable at stream:1
Error, ZeroOp: method should have returned a value
gap> -a;
#I AdditiveInverseImmutable at stream:1
Error, Method for an attribute must return a value
gap> AdditiveInverseMutable(a);
#I AdditiveInverseMutable at stream:1
Error, AdditiveInverseOp: method should have returned a value
gap> One(a);
#I OneImmutable at stream:1
Error, Method for an attribute must return a value
gap> OneMutable(a);
#I OneMutable at stream:1
Error, OneOp: method should have returned a value
gap> Inverse(a);
#I InverseImmutable at stream:1
Error, Method for an attribute must return a value
gap> InverseMutable(a);
#I InverseMutable at stream:1
Error, InvOp: method should have returned a value
gap> a = b;
#I = at stream:1
false
gap> a < b;
#I < at stream:1
false
gap> a in b;
#I in at stream:1
false
gap> a + b;
#I + at stream:1
Error, SUM: method should have returned a value
gap> a - b;
#I - at stream:1
Error, DIFF: method should have returned a value
gap> a * b;
#I * at stream:1
Error, PROD: method should have returned a value
gap> a / b;
#I / at stream:1
Error, QUO: method should have returned a value
gap> LeftQuotient(a, b);
Error, LeftQuotient: method should have returned a value
gap> a ^ b;
#I ^ at stream:1
Error, POW: method should have returned a value
gap> Comm(a, b);
#I Comm at stream:1
Error, Comm: method should have returned a value
gap> a mod b;
#I mod at stream:1
Error, mod: method should have returned a value

#
gap> UntraceMethods(meths);

#
gap> STOP_TEST("kernel/ariths.tst", 1);
14 changes: 14 additions & 0 deletions tst/testinstall/kernel/macfloat.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Tests for functions defined in src/macfloat.c
#
gap> START_TEST("kernel/macfloat.tst");

#
gap> MACFLOAT_INT(fail);
fail
gap> MACFLOAT_STRING(fail);
Error, MACFLOAT_STRING: object to be converted must be a string not a boolean \
or fail

#
gap> STOP_TEST("kernel/macfloat.tst", 1);
92 changes: 92 additions & 0 deletions tst/testinstall/kernel/records.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#
# Tests for functions defined in src/records.c
#
gap> START_TEST("kernel/records.tst");

#
# setup: a precord, and a custom record object
#
gap> r:=rec(1:=2);
rec( 1 := 2 )
gap> fam := NewFamily("MockFamily");;
gap> cat := NewCategory("IsMockRecord", IsRecord);;
gap> type := NewType(fam, cat and IsPositionalObjectRep);;
gap> mockRec := Objectify(type,["myName"]);;

# RNamIntg, RNamObj
gap> ForAll([1,-1,"abc"], x -> IsInt(RNamObj(x)));
true
gap> RNamObj(fail);
Error, Record: '<rec>.(<obj>)' <obj> must be a string or an integer

# NameRNam
gap> ForAll([1,-1,"abc"], x -> NameRNam(RNamObj(x)) = String(x));
true
gap> NameRNam(-1);
Error, NameRName: <rnam> must be a record name (not a integer)
gap> NameRNam(fail);
Error, NameRName: <rnam> must be a record name (not a boolean or fail)

# ElmRecHandler
gap> ELM_REC(r, RNamObj(1));
2
gap> ELM_REC(r, RNamObj(2));
Error, Record Element: '<rec>.2' must have an assigned value

# ElmRecError
gap> fail.1;
Error, Record Element: <rec> must be a record (not a boolean or fail)

# ElmRecObject
gap> InstallMethod(\., [cat, IsPosInt], function(x,i) end);
gap> mockRec.1;
Error, Record access method must return a value
gap> InstallMethod(\., [cat, IsPosInt], function(x,i) return 42; end);
gap> mockRec.1;
42

# IsbRecHandler
gap> ISB_REC(r, RNamObj(1));
true
gap> ISB_REC(r, RNamObj(2));
false

# IsbRecError
gap> IsBound(fail.1);
Error, Record IsBound: <rec> must be a record (not a boolean or fail)

# IsbRecObject
gap> InstallMethod(IsBound\., [cat, IsPosInt], {x,i} -> (i = RNamObj(1)));
gap> IsBound(mockRec.1);
true
gap> IsBound(mockRec.2);
false

# AssRecHandler
gap> ASS_REC(r, RNamObj(3), 42);
gap> r;
rec( 1 := 2, 3 := 42 )

# AssRecError
gap> fail.1 := 2;
Error, Record Assignment: <rec> must be a record (not a boolean or fail)

# AssRecObject
gap> InstallMethod(\.\:\=, [cat, IsPosInt, IsObject], function(x,i,v) end);
gap> ASS_REC(mockRec, RNamObj(1), 2);
gap> mockRec.1 := 2;
2

# UnbRecHandler
gap> UNB_REC(r, RNamObj(2));

# UnbRecError
gap> Unbind(fail.1);
Error, Record Unbind: <rec> must be a record (not a boolean or fail)

# UnbRecObject
gap> InstallMethod(Unbind\., [cat, IsPosInt], function(x,i) end);
gap> Unbind(mockRec.1);

#
gap> STOP_TEST("kernel/records.tst", 1);

0 comments on commit 808110d

Please sign in to comment.