-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
362 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |