Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve errors messages for various set operations (AddSet, UniteSet, ...) #4145

Merged
merged 1 commit into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/set.gi
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,22 @@ InstallMethod( SubtractSet,
RemoveSet( set, obj );
od;
end );


#############################################################################
##
## Fallback methods to give better user feedback if the first argument is
## not mutable or not a set
##
BindGlobal("_REQUIRE_MUTABLE_SET",
function( set, obj )
if not IsMutable(set) or not IsSSortedList( set ) then
Error( "<set> must be a mutable proper set" );
fi;
TryNextMethod();
end );
InstallOtherMethod( AddSet, "for two objects", [ IsObject, IsObject ], _REQUIRE_MUTABLE_SET);
InstallOtherMethod( RemoveSet, "for two objects", [ IsObject, IsObject ], _REQUIRE_MUTABLE_SET);
InstallOtherMethod( UniteSet, "for two objects", [ IsObject, IsObject ], _REQUIRE_MUTABLE_SET);
InstallOtherMethod( IntersectSet, "for two objects", [ IsObject, IsObject ], _REQUIRE_MUTABLE_SET);
InstallOtherMethod( SubtractSet, "for two objects", [ IsObject, IsObject ], _REQUIRE_MUTABLE_SET);
42 changes: 42 additions & 0 deletions tst/testinstall/set.tst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,48 @@ gap> HasIsSSortedList(c) and IsSSortedList(c);
true
gap> AddSet(a,(5,6));

#
gap> AddSet(Immutable([]), 1);
Error, <set> must be a mutable proper set
gap> AddSet(fail, 1);
Error, <set> must be a mutable proper set
gap> AddSet([2,1], 1);
Error, ADD_SET: <set> must be a mutable proper set (not a non-strictly-sorted \
plain list of cyclotomics)

#
gap> RemoveSet(Immutable([]), 1);
Error, <set> must be a mutable proper set
gap> RemoveSet(fail, 1);
Error, <set> must be a mutable proper set
gap> RemoveSet([2,1], 1);
Error, REM_SET: <set> must be a mutable proper set (not a non-strictly-sorted \
plain list of cyclotomics)

#
gap> UniteSet(Immutable([]), 1);
Error, <set> must be a mutable proper set
gap> UniteSet(fail, 1);
Error, <set> must be a mutable proper set
gap> UniteSet([2,1], 1);
Error, <set> must be a mutable proper set

#
gap> IntersectSet(Immutable([]), 1);
Error, <set> must be a mutable proper set
gap> IntersectSet(fail, 1);
Error, <set> must be a mutable proper set
gap> IntersectSet([2,1], 1);
Error, <set> must be a mutable proper set

#
gap> SubtractSet(Immutable([]), 1);
Error, <set> must be a mutable proper set
gap> SubtractSet(fail, 1);
Error, <set> must be a mutable proper set
gap> SubtractSet([2,1], 1);
Error, <set> must be a mutable proper set

#gap> HasIsSSortedList(a) and IsSSortedList(a);
#true
gap> c:=Union(a,[(1,2),(1,2,3)]);
Expand Down