Skip to content

Commit

Permalink
Fix ShallowCopy for IteratorOfPartitionsSet
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed May 25, 2021
1 parent 146b9a4 commit 5a1fe5f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/combinat.gi
Original file line number Diff line number Diff line change
Expand Up @@ -2500,7 +2500,7 @@ InstallGlobalFunction( IteratorOfPartitionsSet, function( s )
return out;
end;

shallowCopy := iter -> rec( next := ShallowCopy( iter!.next ) );
shallowCopy := iter -> rec( next := ShallowCopy( iter!.next ), s := iter!.s );

isDone := iter -> iter!.next = false;

Expand Down
26 changes: 9 additions & 17 deletions tst/testinstall/combinat.tst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
##
## This file tests the functions that mainly deal with combinatorics.
##
#@local i,iter,list,n,pn,it
#@local i,iter,list,n,pn1,pn2,it
gap> START_TEST("combinat.tst");

#F Factorial( <n> ) . . . . . . . . . . . . . . . . factorial of an integer
Expand Down Expand Up @@ -461,30 +461,22 @@ gap> NrRestrictedPartitions( 100, [2,3,5,7,11,13,17], 10 );

#F IteratorOfPartitions( <n> )
gap> for n in [ 1 .. 15 ] do
> pn:= Partitions( n );
> iter:= IteratorOfPartitions( n );
> list:= [];
> for i in [ 1 .. Length( pn ) ] do
> Add( list, NextIterator( iter ) );
> od;
> if not IsDoneIterator( iter ) then
> pn1:= Partitions( n );
> pn2:= List( IteratorOfPartitions( n ) );
> if Length(pn1) <> Length(pn2) then
> Error( "wrong number of elements" );
> elif pn <> list then
> elif pn1 <> pn2 then
> Error( "different elements" );
> fi;
> od;

#F IteratorOfPartitionsSet( <set> )
gap> for s in [[], [5], [1,2,3,4], [2,5,7], ["a","b","c","d","e"], [3..13]] do
> pn:= PartitionsSet( s );
> iter:= IteratorOfPartitionsSet( s );
> list:= [];
> for i in [ 1 .. Length( pn ) ] do
> Add( list, NextIterator( iter ) );
> od;
> if not IsDoneIterator( iter ) then
> pn1:= PartitionsSet( s );
> pn2:= List( IteratorOfPartitionsSet( s ) );
> if Length(pn1) <> Length(pn2) then
> Error( "wrong number of elements" );
> elif Set(pn) <> Set(list) then
> elif Set(pn1) <> Set(pn2) then
> Error( "different elements" );
> fi;
> od;
Expand Down

0 comments on commit 5a1fe5f

Please sign in to comment.