Skip to content

Commit

Permalink
Fixed issue 820 and added tests
Browse files Browse the repository at this point in the history
Fixed List so that it complains if it has more than two arguments. Also changed the error type to 'ErrorNoReturn' when the arguments are 0 or greater than 2. Added some additional tests to test the error messages in these cases, and to test some of the other documented features of List, that is, it works for lists with holes, and it returns a mutable list.
  • Loading branch information
grouptheoryenthusiast committed Jun 29, 2016
1 parent eecad70 commit 814a0f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/coll.gi
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,8 @@ InstallGlobalFunction( List,
function( arg )
local tnum, C, func, res, i, elm, l;
l := Length(arg);
if l = 0 then
Error( "usage: List( <C>[, <func>] )" );
if l = 0 or l > 2 then
ErrorNoReturn( "usage: List( <C>[, <func>] )" );
fi;
tnum:= TNUM_OBJ_INT( arg[1] );
if FIRST_LIST_TNUM <= tnum and tnum <= LAST_LIST_TNUM then
Expand Down
8 changes: 8 additions & 0 deletions tst/testinstall/listgen.tst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ gap> List( [ 1 .. 10 ], x -> x^2 );
[ 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 ]
gap> List( [ 2, 1, 2, 1 ], x -> x - 1 );
[ 1, 0, 1, 0 ]
gap> List();
Error, usage: List( <C>[, <func>] )
gap> List([1..10], x->x^2, "extra argument");
Error, usage: List( <C>[, <func>] )
gap> List([,1,,3,4], x->x>2);
[ , false,, true, true ]
gap> IsMutable(List([1,2,3],x->x^2));
true
gap> Flat( List( [ 1 .. 5 ], x -> [ 1 .. x ] ) );
[ 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5 ]
gap> Reversed( [ 1, 2, 1, 2 ] );
Expand Down

0 comments on commit 814a0f6

Please sign in to comment.