Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
james-d-mitchell committed May 14, 2024
1 parent 03f5e1e commit 20abb16
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 32 deletions.
34 changes: 18 additions & 16 deletions gap/dot.gi
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ InstallMethod(GraphvizDigraph, "for no args", [], {} -> GraphvizDigraph(""));
# ViewString
#############################################################################

InstallMethod(ViewString, "for a graphviz node", [IsGraphvizNode],
InstallMethod(PrintString, "for a graphviz node", [IsGraphvizNode],
n -> StringFormatted("<graphviz node {}>", GraphvizName(n)));

InstallMethod(ViewString, "for a graphviz edge", [IsGraphvizEdge],
InstallMethod(PrintString, "for a graphviz edge", [IsGraphvizEdge],
function(e)
local head, tail;
head := GraphvizHead(e);
Expand All @@ -61,7 +61,8 @@ function(e)
GraphvizName(tail));
end);

InstallMethod(ViewString, "for a graphviz (di)graph", [IsGraphvizObjectWithSubobjects],
InstallMethod(PrintString, "for a graphviz object with subobjects",
[IsGraphvizObjectWithSubobjects],
function(g)
local result, edges, nodes, kind;

Expand Down Expand Up @@ -406,9 +407,8 @@ function(graph, name)
# contexts and subgraphs, rather than just subgraphs as the name suggests
# See https://github.com/digraphs/graphviz/issues/19
if IsBound(subgraphs[name]) then
# TODO why are we talking about subgraphs in the error?
ErrorFormatted("the 1st argument (a graphviz (di)graph) already has ",
" a subgraph with name \"{}\"", name);
" a context or subgraph with name \"{}\"", name);
fi;

ctx := GV_Context(graph, name);
Expand Down Expand Up @@ -527,11 +527,14 @@ end);
InstallMethod(String, "for a graphviz (di)graph",
[IsGraphvizObjectWithSubobjects], graph -> GV_StringifyGraph(graph, false));

InstallMethod(PrintObj, "for a graphviz (di)graph",
[IsGraphvizObjectWithSubobjects],
function(gv)
Print(String(gv));
end);
# Can't do the following because it conflicts with the PrintString above, we
# leave this here as a reminder.

# InstallMethod(PrintObj, "for a graphviz object with subobjects",
# [IsGraphvizObjectWithSubobjects],
# function(gv)
# Print(String(gv));
# end);

InstallMethod(GraphvizSetNodeLabels,
"for a graphviz (di)graph and list of colors",
Expand Down Expand Up @@ -574,11 +577,10 @@ function(c)
if IsString(c) then
c := StringFormatted("\"{}\"", c);
fi;
ErrorFormatted("invalid color {} ({}), ",
"valid colors are RGB values or names from ",
"the GraphViz 2.44.1 X11 Color Scheme",
" http://graphviz.org/doc/info/colors.html",
c,
TNAM_OBJ(c));
ErrorFormatted("invalid color {} ({}), valid colors are RGB values ",
"or names from the GraphViz 2.44.1 X11 Color Scheme",
" http://graphviz.org/doc/info/colors.html",
c,
TNAM_OBJ(c));
fi;
end);
6 changes: 4 additions & 2 deletions gap/gv.gi
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,10 @@ InstallOtherMethod(IsBound\[\],
InstallMethod(GV_MapNames, "for a graphviz map",
[GV_IsMap], m -> RecNames(m!.Data));

InstallMethod(ViewString, "for a graphviz map", [GV_IsMap],
m -> String(m!.Data));
InstallMethod(ViewObj, "for a graphviz map", [GV_IsMap],
function(m)
ViewObj(m!.Data);
end);

InstallMethod(Size, "for a graphviz map",
[GV_IsMap], m -> Length(GV_MapNames(m)));
Expand Down
18 changes: 9 additions & 9 deletions tst/graph.tst
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ gap> n := GraphvizAddNode(g, "n");
gap> g;
<graphviz graph with 1 node and 0 edges>
gap> GraphvizNodes(g);
rec( n := <object> )
rec( n := <graphviz node n> )
gap> GraphvizAddNode(g, "x");
<graphviz node x>
gap> g;
<graphviz graph with 2 nodes and 0 edges>
gap> GraphvizNodes(g);
rec( n := <object>, x := <object> )
rec( n := <graphviz node n>, x := <graphviz node x> )

# Test add node (name)
gap> g := GraphvizGraph();;
gap> GraphvizAddNode(g, "n");
<graphviz node n>
gap> GraphvizNodes(g);
rec( n := <object> )
rec( n := <graphviz node n> )
gap> GraphvizAddNode(g, "x");
<graphviz node x>
gap> GraphvizNodes(g);
rec( n := <object>, x := <object> )
rec( n := <graphviz node n>, x := <graphviz node x> )

# Test has nodes
gap> g := GraphvizGraph();;
Expand Down Expand Up @@ -99,7 +99,7 @@ gap> GraphvizAddEdge(g, "a", "b");;
gap> GraphvizAddEdge(g, "a", "c");
<graphviz edge (a, c)>
gap> GraphvizNodes(g);
rec( a := <object>, b := <object>, c := <object> )
rec( a := <graphviz node a>, b := <graphviz node b>, c := <graphviz node c> )
gap> GraphvizAddEdge(g, "c", "a");
<graphviz edge (c, a)>
gap> GraphvizAddEdge(g, "b", "d");
Expand All @@ -126,13 +126,13 @@ gap> GraphvizAddEdge(g, c, d);;
gap> GraphvizRemoveNode(g, a);
<graphviz graph with 3 nodes and 1 edge>
gap> GraphvizNodes(g);
rec( b := <object>, c := <object>, d := <object> )
rec( b := <graphviz node b>, c := <graphviz node c>, d := <graphviz node d> )
gap> GraphvizEdges(g);
[ <graphviz edge (c, d)> ]
gap> GraphvizRemoveNode(g, b);
<graphviz graph with 2 nodes and 1 edge>
gap> GraphvizNodes(g);
rec( c := <object>, d := <object> )
rec( c := <graphviz node c>, d := <graphviz node d> )

# Test removing node
gap> g := GraphvizGraph();;
Expand All @@ -141,13 +141,13 @@ gap> GraphvizAddEdge(g, "c", "d");;
gap> GraphvizRemoveNode(g, "a");
<graphviz graph with 3 nodes and 1 edge>
gap> GraphvizNodes(g);
rec( b := <object>, c := <object>, d := <object> )
rec( b := <graphviz node b>, c := <graphviz node c>, d := <graphviz node d> )
gap> GraphvizEdges(g);
[ <graphviz edge (c, d)> ]
gap> GraphvizRemoveNode(g, "b");
<graphviz graph with 2 nodes and 1 edge>
gap> GraphvizNodes(g);
rec( c := <object>, d := <object> )
rec( c := <graphviz node c>, d := <graphviz node d> )

# Test renaming graph
gap> g := GraphvizGraph();;
Expand Down
11 changes: 6 additions & 5 deletions tst/subgraph.tst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ gap> g := GraphvizGraph();;
gap> GraphvizAddSubgraph(g, "a");;
gap> GraphvizAddContext(g, "b");;
gap> GraphvizSubgraphs(g);
rec( a := <object>, b := <object> )
rec( a := <graphviz graph a with 0 nodes and 0 edges>,
b := <graphviz context b with 0 nodes and 0 edges> )

# Test adding a node to a subgraph (does or does not add to parent???)
# TODO need to nail down expected behaviour!
Expand All @@ -70,7 +71,7 @@ gap> GraphvizAddNode(s, "n");;
gap> GraphvizNodes(g);
rec( )
gap> GraphvizNodes(s);
rec( n := <object> )
rec( n := <graphviz node n> )

# Test adding a node to a subgraph which is already in parent fails (by name)
gap> g := GraphvizGraph("r");;
Expand Down Expand Up @@ -229,11 +230,11 @@ gap> GraphvizRemoveNode(g, "d");;
gap> GraphvizNodes(g);
rec( )
gap> GraphvizNodes(parent);
rec( a := <object> )
rec( a := <graphviz node a> )
gap> GraphvizNodes(sibling);
rec( b := <object> )
rec( b := <graphviz node b> )
gap> GraphvizNodes(child);
rec( c := <object> )
rec( c := <graphviz node c> )

# Test context attribute resetting
gap> g := GraphvizDigraph();;
Expand Down

0 comments on commit 20abb16

Please sign in to comment.