Skip to content

Commit

Permalink
lib: improve error handling for Image, ... v2
Browse files Browse the repository at this point in the history
Add improvements suggested in the reviews.
  • Loading branch information
ssiccha committed Jun 24, 2019
1 parent 83b0950 commit 21d7375
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 63 deletions.
55 changes: 30 additions & 25 deletions hpcgap/lib/mapping.gi
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ InstallGlobalFunction( Image, function ( arg )
fi;
return ImageElm( map, elm );

# image of a set or list of elments <elm> under the mapping <map>
# image of a collection of elments <elm> under the mapping <map>
elif CollFamSourceEqFamElms( FamilyObj( map ), FamilyObj(elm) ) then
if not IsSubset( Source( map ), elm ) then
ErrorNoReturn( "<coll> must be a subset of Source(<map>)" );
ErrorNoReturn( "the collection <elm> must be contained in ",
"Source(<map>)" );
fi;

if IsDomain( elm ) or IsSSortedList( elm ) then
Expand All @@ -203,10 +204,10 @@ InstallGlobalFunction( Image, function ( arg )
return [];

else
ErrorNoReturn( "families of <elm> or <coll> and Source(<map>) ",
"don't match, ",
"maybe <elm> or <coll> are not contained in ",
"Source(<map>) or aren't homogeneous lists," );
ErrorNoReturn( "the families of the element or collection <elm> ",
"and Source(<map>) don't match, ",
"maybe <elm> is not contained in Source(<map>) or ",
"is not a homogeneous list or collection" );
fi;
fi;
ErrorNoReturn( "usage: Image(<map>), Image(<map>,<elm>), ",
Expand Down Expand Up @@ -246,10 +247,11 @@ InstallGlobalFunction( Images, function ( arg )
fi;
return ImagesElm( map, elm );

# image of a set or list of elments <elm> under the mapping <map>
# image of a collection of elments <elm> under the mapping <map>
elif CollFamSourceEqFamElms( FamilyObj( map ), FamilyObj(elm) ) then
if not IsSubset( Source( map ), elm ) then
ErrorNoReturn( "<coll> must be a subset of Source(<map>)" );
ErrorNoReturn( "the collection <elm> must be contained in ",
"Source(<map>)" );
fi;

if IsDomain( elm ) or IsSSortedList( elm ) then
Expand All @@ -264,10 +266,10 @@ InstallGlobalFunction( Images, function ( arg )
return [];

else
ErrorNoReturn( "families of <elm> or <coll> and Source(<map>) ",
"don't match, ",
"maybe <elm> or <coll> are not contained in ",
"Source(<map>) or aren't homogeneous lists," );
ErrorNoReturn( "the families of the element or collection <elm> ",
"and Source(<map>) don't match, ",
"maybe <elm> is not contained in Source(<map>) or ",
"is not a homogeneous list or collection" );
fi;
fi;
ErrorNoReturn( "usage: Images(<map>), Images(<map>,<elm>), ",
Expand Down Expand Up @@ -303,16 +305,18 @@ InstallGlobalFunction( PreImage, function ( arg )
# preimage of a single element <img> under <map>
if FamRangeEqFamElm( FamilyObj( map ), FamilyObj( img ) ) then
if not ( IsInjective( map ) and IsSurjective( map ) ) then
ErrorNoReturn( "<map> must be an inj. and surj. mapping" );
ErrorNoReturn( "<map> must be an injective and surjective ",
"mapping" );
elif not img in Range( map ) then
ErrorNoReturn( "<elm> must be an element of Range(<map>)" );
fi;
return PreImageElm( map, img );

# preimage of a set or list of elments <img> under <map>
# preimage of a collection of elments <img> under <map>
elif CollFamRangeEqFamElms( FamilyObj( map ), FamilyObj( img ) ) then
if not IsSubset( Range( map ), img ) then
ErrorNoReturn( "<coll> must be a subset of Range(<map>)" );
ErrorNoReturn( "the collection <elm> must be contained in ",
"Range(<map>)" );
fi;

if IsDomain( img ) or IsSSortedList( img ) then
Expand All @@ -327,10 +331,10 @@ InstallGlobalFunction( PreImage, function ( arg )
return [];

else
ErrorNoReturn( "families of <elm> or <coll> and Range(<map>) ",
"don't match, ",
"maybe <elm> or <coll> are not contained in ",
"Range(<map>) or aren't homogeneous lists," );
ErrorNoReturn( "the families of the element or collection <elm> ",
"and Range(<map>) don't match, ",
"maybe <elm> is not contained in Range(<map>) or ",
"is not a homogeneous list or collection" );
fi;
fi;
ErrorNoReturn( "usage: PreImage(<map>), PreImage(<map>,<img>), ",
Expand Down Expand Up @@ -370,10 +374,11 @@ InstallGlobalFunction( PreImages, function ( arg )
fi;
return PreImagesElm( map, img );

# preimage of a set or list of elements <img> under <map>
# preimage of a collection of elements <img> under <map>
elif CollFamRangeEqFamElms( FamilyObj( map ), FamilyObj( img ) ) then
if not IsSubset( Range( map ), img ) then
ErrorNoReturn( "<coll> must be a subset of Range(<map>)" );
ErrorNoReturn( "the collection <elm> must be contained in ",
"Range(<map>)" );
fi;

if IsDomain( img ) or IsSSortedList( img ) then
Expand All @@ -388,10 +393,10 @@ InstallGlobalFunction( PreImages, function ( arg )
return [];

else
ErrorNoReturn( "families of <elm> or <coll> and Range(<map>) ",
"don't match, ",
"maybe <elm> or <coll> are not contained in ",
"Range(<map>) or aren't homogeneous lists," );
ErrorNoReturn( "the families of the element or collection <elm> ",
"and Range(<map>) don't match, ",
"maybe <elm> is not contained in Range(<map>) or ",
"is not a homogeneous list or collection" );
fi;
fi;
ErrorNoReturn( "usage: PreImages(<map>), PreImages(<map>,<img>), ",
Expand Down
55 changes: 30 additions & 25 deletions lib/mapping.gi
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,11 @@ InstallGlobalFunction( Image, function ( arg )
fi;
return ImageElm( map, elm );

# image of a set or list of elments <elm> under the mapping <map>
# image of a collection of elments <elm> under the mapping <map>
elif CollFamSourceEqFamElms( FamilyObj( map ), FamilyObj(elm) ) then
if not IsSubset( Source( map ), elm ) then
ErrorNoReturn( "<coll> must be a subset of Source(<map>)" );
ErrorNoReturn( "the collection <elm> must be contained in ",
"Source(<map>)" );
fi;

if IsDomain( elm ) or IsSSortedList( elm ) then
Expand All @@ -200,10 +201,10 @@ InstallGlobalFunction( Image, function ( arg )
return [];

else
ErrorNoReturn( "families of <elm> or <coll> and Source(<map>) ",
"don't match, ",
"maybe <elm> or <coll> are not contained in ",
"Source(<map>) or aren't homogeneous lists," );
ErrorNoReturn( "the families of the element or collection <elm> ",
"and Source(<map>) don't match, ",
"maybe <elm> is not contained in Source(<map>) or ",
"is not a homogeneous list or collection" );
fi;
fi;
ErrorNoReturn( "usage: Image(<map>), Image(<map>,<elm>), ",
Expand Down Expand Up @@ -243,10 +244,11 @@ InstallGlobalFunction( Images, function ( arg )
fi;
return ImagesElm( map, elm );

# image of a set or list of elments <elm> under the mapping <map>
# image of a collection of elments <elm> under the mapping <map>
elif CollFamSourceEqFamElms( FamilyObj( map ), FamilyObj(elm) ) then
if not IsSubset( Source( map ), elm ) then
ErrorNoReturn( "<coll> must be a subset of Source(<map>)" );
ErrorNoReturn( "the collection <elm> must be contained in ",
"Source(<map>)" );
fi;

if IsDomain( elm ) or IsSSortedList( elm ) then
Expand All @@ -261,10 +263,10 @@ InstallGlobalFunction( Images, function ( arg )
return [];

else
ErrorNoReturn( "families of <elm> or <coll> and Source(<map>) ",
"don't match, ",
"maybe <elm> or <coll> are not contained in ",
"Source(<map>) or aren't homogeneous lists," );
ErrorNoReturn( "the families of the element or collection <elm> ",
"and Source(<map>) don't match, ",
"maybe <elm> is not contained in Source(<map>) or ",
"is not a homogeneous list or collection" );
fi;
fi;
ErrorNoReturn( "usage: Images(<map>), Images(<map>,<elm>), ",
Expand Down Expand Up @@ -300,16 +302,18 @@ InstallGlobalFunction( PreImage, function ( arg )
# preimage of a single element <img> under <map>
if FamRangeEqFamElm( FamilyObj( map ), FamilyObj( img ) ) then
if not ( IsInjective( map ) and IsSurjective( map ) ) then
ErrorNoReturn( "<map> must be an inj. and surj. mapping" );
ErrorNoReturn( "<map> must be an injective and surjective ",
"mapping" );
elif not img in Range( map ) then
ErrorNoReturn( "<elm> must be an element of Range(<map>)" );
fi;
return PreImageElm( map, img );

# preimage of a set or list of elments <img> under <map>
# preimage of a collection of elments <img> under <map>
elif CollFamRangeEqFamElms( FamilyObj( map ), FamilyObj( img ) ) then
if not IsSubset( Range( map ), img ) then
ErrorNoReturn( "<coll> must be a subset of Range(<map>)" );
ErrorNoReturn( "the collection <elm> must be contained in ",
"Range(<map>)" );
fi;

if IsDomain( img ) or IsSSortedList( img ) then
Expand All @@ -324,10 +328,10 @@ InstallGlobalFunction( PreImage, function ( arg )
return [];

else
ErrorNoReturn( "families of <elm> or <coll> and Range(<map>) ",
"don't match, ",
"maybe <elm> or <coll> are not contained in ",
"Range(<map>) or aren't homogeneous lists," );
ErrorNoReturn( "the families of the element or collection <elm> ",
"and Range(<map>) don't match, ",
"maybe <elm> is not contained in Range(<map>) or ",
"is not a homogeneous list or collection" );
fi;
fi;
ErrorNoReturn( "usage: PreImage(<map>), PreImage(<map>,<img>), ",
Expand Down Expand Up @@ -367,10 +371,11 @@ InstallGlobalFunction( PreImages, function ( arg )
fi;
return PreImagesElm( map, img );

# preimage of a set or list of elements <img> under <map>
# preimage of a collection of elements <img> under <map>
elif CollFamRangeEqFamElms( FamilyObj( map ), FamilyObj( img ) ) then
if not IsSubset( Range( map ), img ) then
ErrorNoReturn( "<coll> must be a subset of Range(<map>)" );
ErrorNoReturn( "the collection <elm> must be contained in ",
"Range(<map>)" );
fi;

if IsDomain( img ) or IsSSortedList( img ) then
Expand All @@ -385,10 +390,10 @@ InstallGlobalFunction( PreImages, function ( arg )
return [];

else
ErrorNoReturn( "families of <elm> or <coll> and Range(<map>) ",
"don't match, ",
"maybe <elm> or <coll> are not contained in ",
"Range(<map>) or aren't homogeneous lists," );
ErrorNoReturn( "the families of the element or collection <elm> ",
"and Range(<map>) don't match, ",
"maybe <elm> is not contained in Range(<map>) or ",
"is not a homogeneous list or collection" );
fi;
fi;
ErrorNoReturn( "usage: PreImages(<map>), PreImages(<map>,<img>), ",
Expand Down
30 changes: 17 additions & 13 deletions tst/testinstall/mapping.tst
Original file line number Diff line number Diff line change
Expand Up @@ -338,47 +338,51 @@ Error, <map> must be single-valued and total
gap> 0*Z(3) ^ map;
Error, <map> must be single-valued and total
gap> Image(mapBijective, Z(5));
Error, families of <elm> or <coll> and Source(<map>) don't match, maybe <elm> \
or <coll> are not contained in Source(<map>) or aren't homogeneous lists,
Error, the families of the element or collection <elm> and Source(<map>) don't\
match, maybe <elm> is not contained in Source(<map>) or is not a homogeneous \
list or collection
gap> Image(mapBijective, Z(9));
Error, <elm> must be an element of Source(<map>)
gap> Image(map, [Z(3), Z(9)]);
Error, <coll> must be a subset of Source(<map>)
Error, the collection <elm> must be contained in Source(<map>)
# Images
gap> Images(x -> x, 1);
Error, <map> must be a general mapping
gap> Images(mapBijective, Z(9));
Error, <elm> must be an element of Source(<map>)
gap> Images(map, [Z(3), Z(9)]);
Error, <coll> must be a subset of Source(<map>)
Error, the collection <elm> must be contained in Source(<map>)
gap> Image(mapBijective, Z(5));
Error, families of <elm> or <coll> and Source(<map>) don't match, maybe <elm> \
or <coll> are not contained in Source(<map>) or aren't homogeneous lists,
Error, the families of the element or collection <elm> and Source(<map>) don't\
match, maybe <elm> is not contained in Source(<map>) or is not a homogeneous \
list or collection

# PreImage
gap> PreImage(x -> x, 1);
Error, <map> must be a general mapping
gap> PreImage(map, Z(3));
Error, <map> must be an inj. and surj. mapping
Error, <map> must be an injective and surjective mapping
gap> PreImage(mapBijective, Z(9));
Error, <elm> must be an element of Range(<map>)
gap> PreImage(mapBijective, [Z(3), Z(9)]);
Error, <coll> must be a subset of Range(<map>)
Error, the collection <elm> must be contained in Range(<map>)
gap> PreImage(mapBijective, Z(5));
Error, families of <elm> or <coll> and Range(<map>) don't match, maybe <elm> o\
r <coll> are not contained in Range(<map>) or aren't homogeneous lists,
Error, the families of the element or collection <elm> and Range(<map>) don't \
match, maybe <elm> is not contained in Range(<map>) or is not a homogeneous li\
st or collection
# PreImages
gap> PreImages(x -> x, 1);
Error, <map> must be a general mapping
gap> PreImages(mapBijective, Z(9));
Error, <elm> must be an element of Range(<map>)
gap> PreImages(mapBijective, [Z(3), Z(9)]);
Error, <coll> must be a subset of Range(<map>)
Error, the collection <elm> must be contained in Range(<map>)
gap> PreImages(mapBijective, Z(5));
Error, families of <elm> or <coll> and Range(<map>) don't match, maybe <elm> o\
r <coll> are not contained in Range(<map>) or aren't homogeneous lists,
Error, the families of the element or collection <elm> and Range(<map>) don't \
match, maybe <elm> is not contained in Range(<map>) or is not a homogeneous li\
st or collection

# NiceMonomorphism, RestrictedMapping for matrix groups
gap> g := Group((1,2),(3,4));;
Expand Down

0 comments on commit 21d7375

Please sign in to comment.