Skip to content

Commit 042eefb

Browse files
committed
increase code coverage
1 parent 3e4e538 commit 042eefb

2 files changed

Lines changed: 73 additions & 26 deletions

File tree

lib/gslp.gi

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,16 @@ InstallMethod( NrOutputsOfGeneralizedStraightLineProgram,
9393
local data;
9494

9595
if IsStraightLineProgram( gslp ) then
96-
data:= LinesOfStraightLineProgram( gslp );
97-
data:= data[ Length( data ) ];
96+
# The value is in general not set in the construction.
97+
data:= Last( LinesOfStraightLineProgram( gslp ) );
9898
if ForAll( data, IsList ) then
9999
return Length( data );
100100
else
101101
return 1;
102102
fi;
103103
else
104-
data:= DataOfGeneralizedStraightLineProgram( gslp );
105-
if data[1] = "union" then
106-
return Sum( List( data[2],
107-
NrOutputsOfGeneralizedStraightLineProgram ), 0 );
108-
else
109-
data:= data[2];
110-
data:= data[ Length( data ) ];
111-
return NrOutputsOfGeneralizedStraightLineProgram( data );
112-
fi;
104+
# The value should get set in the construction.
105+
Error( "attribute value got lost?" );
113106
fi;
114107
end );
115108

@@ -123,12 +116,8 @@ InstallMethod( ResultOfGeneralizedStraightLineProgram,
123116
function( gslp, gens )
124117
local data, result, prg;
125118

126-
if IsStraightLineProgram( gslp ) then
127-
# This is necessary because the method for slps was installed
128-
# before the implication from gslps increased the rank of the filter
129-
# `IsStraightLineProgram'.
130-
TryNextMethod();
131-
fi;
119+
# We may assume that the 'IsStraightLineProgram' method has higher rank.
120+
Assert( 1, not IsStraightLineProgram( gslp ) );
132121

133122
data:= DataOfGeneralizedStraightLineProgram( gslp );
134123
if data[1] = "union" then
@@ -185,21 +174,18 @@ InstallMethod( EquivalentStraightLineProgram,
185174
##
186175
InstallMethod( ViewString,
187176
[ "IsGeneralizedStraightLineProgram" ],
188-
function( gslp )
189-
if IsStraightLineProgram( gslp ) then
190-
TryNextMethod();
191-
fi;
192-
return "<generalized straight line program>";
193-
end );
177+
gslp -> "<generalized straight line program>" );
178+
179+
InstallMethod( ViewString,
180+
[ "IsStraightLineProgram" ],
181+
slp -> "<straight line program>" );
182+
#T eventually move this to the GAP library
194183

195184
InstallMethod( String,
196185
[ "IsGeneralizedStraightLineProgram" ],
197186
function( gslp )
198187
local data;
199188

200-
if IsStraightLineProgram( gslp ) then
201-
TryNextMethod();
202-
fi;
203189
data:= DataOfGeneralizedStraightLineProgram( gslp );
204190
return Concatenation( "GeneralizedStraightLineProgram( \"",
205191
data[1], "\", [ ",

tst/gslp.tst

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#@local prg, data
2+
############################################################################
3+
##
4+
#W gslp.tst Utils Package Thomas Breuer
5+
##
6+
#Y Copyright (C) 2026, The GAP Group
7+
##
8+
gap> START_TEST( "gslp.tst" );
9+
10+
#
11+
gap> ReadPackage( "utils", "tst/loadall.g" );;
12+
gap> UtilsLoadingComplete;
13+
true
14+
15+
# test inconsistent input for `GeneralizedStraightLineProgram`
16+
gap> GeneralizedStraightLineProgram( "union", [[[1,2]]], 1 );
17+
Error, usage: GeneralizedStraightLineProgram( <lines>[, <nrgens>] ) or General\
18+
izedStraightLineProgram( <kind>, <list> )
19+
gap> GeneralizedStraightLineProgram( "union", [] );
20+
Error, <list> must be a nonempty list
21+
gap> GeneralizedStraightLineProgram( "union",
22+
> [ [ [[[1,2]]], 1 ], [ [[[1,3]]], 2 ] ] );
23+
Error, all entries of <list> must have the same input number
24+
gap> GeneralizedStraightLineProgram( "compose",
25+
> [ [ [[[1,2]]], 1 ], [ [[[1,3]]], 2 ] ] );
26+
Error, inputs and outputs for <list> are not compatible
27+
gap> GeneralizedStraightLineProgram( "other", [[[1,2]]] );
28+
Error, <kind> must be one of "union", "compose"
29+
30+
# test cases of `NrOutputsOfGeneralizedStraightLineProgram`
31+
gap> prg:= StraightLineProgram( [ [1,2,2,3], [3,-1] ], 2 );;
32+
gap> NrOutputsOfGeneralizedStraightLineProgram( prg );
33+
1
34+
35+
# test `false` cases of `IsInternallyConsistent`
36+
gap> prg:= GeneralizedStraightLineProgram( "compose",
37+
> [ [ [[[1,2]]], 1 ], [ [[[1,3]]], 1 ] ] );;
38+
gap> ResetFilterObj( prg, HasNrInputsOfGeneralizedStraightLineProgram );
39+
gap> SetNrInputsOfGeneralizedStraightLineProgram( prg, 3 );
40+
gap> IsInternallyConsistent( prg );
41+
false
42+
gap> data:= ShallowCopy( DataOfGeneralizedStraightLineProgram( prg ) );;
43+
gap> data[1]:= "other";;
44+
gap> ResetFilterObj( prg, HasDataOfGeneralizedStraightLineProgram );
45+
gap> SetDataOfGeneralizedStraightLineProgram( prg, data );
46+
gap> IsInternallyConsistent( prg );
47+
false
48+
49+
# `ViewString` and `String`
50+
gap> ViewString( StraightLineProgram( [[[1,2]]], 1 ) );
51+
"<straight line program>"
52+
gap> ViewString( GeneralizedStraightLineProgram( "union", [ [[[1,2]]] ] ) );
53+
"<generalized straight line program>"
54+
gap> String( StraightLineProgram( [[[1,2]]], 1 ) );
55+
"StraightLineProgram( [ [ [ 1, 2 ] ] ], 1 )"
56+
gap> String( GeneralizedStraightLineProgram( "union", [ [[[1,2]]] ] ) );
57+
"GeneralizedStraightLineProgram( \"union\", [ StraightLineProgram( [ [ 1, 2 ] \
58+
], 1 ) ] )"
59+
60+
#
61+
gap> STOP_TEST( "gslp.tst" );

0 commit comments

Comments
 (0)