Skip to content

Commit

Permalink
kernel: more tests, and some minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Aug 24, 2018
1 parent 7030c45 commit e06184b
Show file tree
Hide file tree
Showing 14 changed files with 283 additions and 55 deletions.
4 changes: 2 additions & 2 deletions src/calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ typedef Obj (* ObjFunc_6ARGS) (Obj self, Obj a1, Obj a2, Obj a3, Obj a4, Obj a5,
**
** 'BODY_FUNC(<func>)' is the body.
**
** 'ENVI_FUNC(<func>)' is the environment (i.e., the local variables bag
** that was current when <func> was created).
** 'ENVI_FUNC(<func>)' is the environment (i.e., the local variables bag)
** that was current when <func> was created.
**
** 'FEXS_FUNC(<func>)' is the function expressions list (i.e., the list of
** the function expressions of the functions defined inside of <func>).
Expand Down
2 changes: 1 addition & 1 deletion src/intrprtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -4434,7 +4434,7 @@ void IntrAssertEnd2Args ( void )


if ( STATE(IntrIgnoring) == 0 )
ErrorQuit("Assertion Failure", 0, 0);
ErrorQuit("Assertion failure", 0, 0);
else
STATE(IntrIgnoring) -= 2;

Expand Down
28 changes: 3 additions & 25 deletions src/range.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,13 +610,8 @@ Obj PosRange (
low = GET_LOW_RANGE(list);
inc = GET_INC_RANGE(list);

/* look just beyond the end */
if ( istart == lenList ) {
k = 0;
}

/* look for an integer */
else if ( IS_INTOBJ(val) ) {
// look for an integer, and not beyond the list end
if ( IS_INTOBJ(val) && istart < lenList ) {
v = INT_INTOBJ(val);
if ( 0 < inc
&& low + istart * inc <= v && v <= low + (lenList-1) * inc
Expand Down Expand Up @@ -1033,24 +1028,7 @@ Obj FuncINTER_RANGE( Obj self, Obj r1, Obj r2)
SET_LEN_PLIST(r1, 0L);
return (Obj) 0;
}
/* torture:
a := [-10..10];; INTER_RANGE(a,[-10..10]); a;
a := [-10..10];; INTER_RANGE(a,[-11..10]); a;
a := [-10..10];; INTER_RANGE(a,[-10..11]); a;
a := [-10..10];; INTER_RANGE(a,[-11..9]); a;
a := [-10..10];; INTER_RANGE(a,[-9..11]); a;
a := [-10..10];; INTER_RANGE(a,[-21,-18..21]); a;
a := [-10..10];; INTER_RANGE(a,[-6,-3..21]); a;
a := [-10..10];; INTER_RANGE(a,[-21,-18..6]); a;
a := [-10,-7..20];; INTER_RANGE(a,[-21,-18..6]); a;
a := [-9,-6..21];; INTER_RANGE(a,[-21,-18..6]); a;
a := [-12,-10..20];; INTER_RANGE(a,[-21,-18..6]); a;
a := [-15,-12..3];; INTER_RANGE(a,[-21,-18..6]); a;
a := [-12,-9..3];; INTER_RANGE(a,[-21,-18..6]); a;
a := [-9,-6..3];; INTER_RANGE(a,[-21,-18..6]); a;
a := [-9,-3..3];; INTER_RANGE(a,[-21,-18..6]); a;
a := [-9,-5..3];; INTER_RANGE(a,[-21,-18..6]); a;
*/


/****************************************************************************
**
Expand Down
2 changes: 1 addition & 1 deletion src/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ Obj FuncSUBTR_SET (
static StructGVarFunc GVarFuncs [] = {

GVAR_FUNC(LIST_SORTED_LIST, 1, "list"),
GVAR_FUNC(IS_EQUAL_SET, 2, "set1, set2"),
GVAR_FUNC(IS_EQUAL_SET, 2, "list1, list2"),
GVAR_FUNC(IS_SUBSET_SET, 2, "set1, set2"),
GVAR_FUNC(ADD_SET, 2, "set, val"),
GVAR_FUNC(REM_SET, 2, "set, val"),
Expand Down
6 changes: 0 additions & 6 deletions src/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,11 +946,6 @@ UInt ExecAssert2Args (
SET_BRK_CURR_STAT( stat );
ErrorReturnVoid( "Assertion failure", 0L, 0L, "you may 'return;'");
}

/* decision must be 'True' here */
else {
return 0;
}
}
return 0;
}
Expand Down Expand Up @@ -992,7 +987,6 @@ UInt ExecAssert3Args (
PrintObj(message);
}
}
return 0;
}
return 0;
}
Expand Down
16 changes: 0 additions & 16 deletions tst/testinstall/interpreter.tst
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,3 @@ Unbind(l!{[1,3]});
^
gap> l;
[ 42, 2, 23 ]

#
# assertions
#
gap> Assert(0, true);
gap> Assert(0, false);
Error, Assertion Failure
gap> Assert(0, 0);
Error, <condition> in Assert must yield 'true' or 'false' (not a integer)
gap> Assert(0, true, "bla");
gap> Assert(0, false, "bla\n");
bla
gap> Assert(0, false, 1); Print("\n");
1
gap> Assert(0, 0, "bla");
Error, <condition> in Assert must yield 'true' or 'false' (not a integer)
9 changes: 9 additions & 0 deletions tst/testinstall/kernel/exprs.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Tests for functions defined in src/exprs.c
#
gap> START_TEST("kernel/exprs.tst");

#

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

# test Assert with two arguments
gap> Assert(0, 0);
Error, <condition> in Assert must yield 'true' or 'false' (not a integer)
gap> Assert(0, true);
gap> Assert(0, false);
Error, Assertion failure
gap> Assert(100, 0);
gap> Assert(100, true);
gap> Assert(100, false);

# test Assert with three arguments
gap> Assert(0, 0, "message\n");
Error, <condition> in Assert must yield 'true' or 'false' (not a integer)
gap> Assert(0, true, "message\n");
gap> Assert(0, false, "message\n");
message
gap> Assert(0, false, 1); Print("\n"); # message can also be any object
1
gap> Assert(100, 0, "message\n");
gap> Assert(100, true, "message\n");
gap> Assert(100, false, "message\n");

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

#
gap> a := [-10..10];; INTER_RANGE(a,[-10..10]); a;
[ -10 .. 10 ]
gap> a := [-10..10];; INTER_RANGE(a,[-11..10]); a;
[ -10 .. 10 ]
gap> a := [-10..10];; INTER_RANGE(a,[-10..11]); a;
[ -10 .. 10 ]
gap> a := [-10..10];; INTER_RANGE(a,[-11..9]); a;
[ -10 .. 9 ]
gap> a := [-10..10];; INTER_RANGE(a,[-9..11]); a;
[ -9 .. 10 ]
gap> a := [-10..10];; INTER_RANGE(a,[-21,-18..21]); a;
[ -9, -6 .. 9 ]
gap> a := [-10..10];; INTER_RANGE(a,[-6,-3..21]); a;
[ -6, -3 .. 9 ]
gap> a := [-10..10];; INTER_RANGE(a,[-21,-18..6]); a;
[ -9, -6 .. 6 ]
gap> a := [-10,-7..20];; INTER_RANGE(a,[-21,-18..6]); a;
[ ]
gap> a := [-9,-6..21];; INTER_RANGE(a,[-21,-18..6]); a;
[ -9, -6 .. 6 ]
gap> a := [-12,-10..20];; INTER_RANGE(a,[-21,-18..6]); a;
[ -12, -6 .. 6 ]
gap> a := [-15,-12..3];; INTER_RANGE(a,[-21,-18..6]); a;
[ -15, -12 .. 3 ]
gap> a := [-12,-9..3];; INTER_RANGE(a,[-21,-18..6]); a;
[ -12, -9 .. 3 ]
gap> a := [-9,-6..3];; INTER_RANGE(a,[-21,-18..6]); a;
[ -9, -6 .. 3 ]
gap> a := [-9,-3..3];; INTER_RANGE(a,[-21,-18..6]); a;
[ -9, -3 .. 3 ]
gap> a := [-9,-5..3];; INTER_RANGE(a,[-21,-18..6]); a;
[ -9, 3 ]

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

#
gap> IsSet(1);
false
gap> LIST_SORTED_LIST(1);
Error, Set: <list> must be a small list (not a integer)

#
gap> IS_EQUAL_SET;
function( list1, list2 ) ... end
gap> IS_EQUAL_SET(1,1);
Error, IsEqualSet: <list1> must be a small list (not a integer)
gap> IS_EQUAL_SET([],1);
Error, IsEqualSet: <list2> must be a small list (not a integer)
gap> IS_EQUAL_SET([],[]);
true

#
gap> IS_SUBSET_SET;
function( set1, set2 ) ... end
gap> IS_SUBSET_SET(1,1);
Error, IsSubsetSet: <set1> must be a small list (not a integer)
gap> IS_SUBSET_SET([],1);
Error, IsSubsetSet: <set2> must be a small list (not a integer)
gap> IS_SUBSET_SET([],[]);
true
gap> IS_SUBSET_SET([1,2,3],[1,2]);
true
gap> IS_SUBSET_SET([1,2,3],[2,1]);
true
gap> IS_SUBSET_SET([1,2,3],[,1]);
true
gap> IS_SUBSET_SET([1,2,3],[1,2,4]);
false
gap> IS_SUBSET_SET([1,2,3],[2,1,4]);
false
gap> IS_SUBSET_SET([1,2,3],[,1,4]);
false

#
gap> ADD_SET;
function( set, val ) ... end
gap> ADD_SET(1,1);
Error, AddSet: <set> must be a mutable proper set (not a integer)

#
gap> REM_SET;
function( set, val ) ... end
gap> REM_SET(1,1);
Error, RemoveSet: <set> must be a mutable proper set (not a integer)

#
gap> UNITE_SET;
function( set1, set2 ) ... end
gap> UNITE_SET(1,1);
Error, UniteSet: <set1> must be a mutable proper set (not a integer)
gap> UNITE_SET([],1);
Error, UniteSet: <set2> must be a small list (not a integer)
gap> UNITE_SET([],[]);

#
gap> INTER_SET;
function( set1, set2 ) ... end
gap> INTER_SET(1,1);
Error, IntersectSet: <set1> must be a mutable proper set (not a integer)
gap> INTER_SET([],1);
Error, IntersectSet: <set2> must be a small list (not a integer)
gap> INTER_SET([],[]);

#
gap> SUBTR_SET;
function( set1, set2 ) ... end
gap> SUBTR_SET(1,1);
Error, SubtractSet: <set1> must be a mutable proper set (not a integer)
gap> SUBTR_SET([],1);
Error, SubtractSet: <set2> must be a small list (not a integer)
gap> SUBTR_SET([],[]);

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

# test checks in ExecForRangeHelper
gap> f := function(a) local x; for x in [a..1] do od; end;;
gap> f('x');
Error, Range: <first> must be an integer (not a character)
gap> f := function(a) local x; for x in [1..a] do od; end;;
gap> f('x');
Error, Range: <last> must be an integer (not a character)

# test Assert with two arguments
gap> function() Assert(0, 0); end();
Error, Assertion condition must evaluate to 'true' or 'false', not a integer
gap> function() Assert(0, true); end();
gap> function() Assert(0, false); end();
Error, Assertion failure
gap> function() Assert(100, 0); end();
gap> function() Assert(100, true); end();
gap> function() Assert(100, false); end();

# test Assert with three arguments
gap> function() Assert(0, 0, "message\n"); end();
Error, Assertion condition must evaluate to 'true' or 'false', not a integer
gap> function() Assert(0, true, "message\n"); end();
gap> function() Assert(0, false, "message\n"); end();
message
gap> function() Assert(0, false, 1); Print("\n"); end(); # message can also be any object
1
gap> function() Assert(100, 0, "message\n"); end();
gap> function() Assert(100, true, "message\n"); end();
gap> function() Assert(100, false, "message\n"); end();

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

0 comments on commit e06184b

Please sign in to comment.