From 20abb1645511d7fdc9db403ba62eb46df016ec0d Mon Sep 17 00:00:00 2001 From: "James D. Mitchell" Date: Tue, 14 May 2024 17:44:45 +0100 Subject: [PATCH] Fix tests --- gap/dot.gi | 34 ++++++++++++++++++---------------- gap/gv.gi | 6 ++++-- tst/graph.tst | 18 +++++++++--------- tst/subgraph.tst | 11 ++++++----- 4 files changed, 37 insertions(+), 32 deletions(-) diff --git a/gap/dot.gi b/gap/dot.gi index 5c4e674..b56d4ca 100644 --- a/gap/dot.gi +++ b/gap/dot.gi @@ -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("", GraphvizName(n))); -InstallMethod(ViewString, "for a graphviz edge", [IsGraphvizEdge], +InstallMethod(PrintString, "for a graphviz edge", [IsGraphvizEdge], function(e) local head, tail; head := GraphvizHead(e); @@ -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; @@ -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); @@ -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", @@ -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); diff --git a/gap/gv.gi b/gap/gv.gi index e203428..f9b2a64 100644 --- a/gap/gv.gi +++ b/gap/gv.gi @@ -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))); diff --git a/tst/graph.tst b/tst/graph.tst index d485ee1..f0a9124 100644 --- a/tst/graph.tst +++ b/tst/graph.tst @@ -33,24 +33,24 @@ gap> n := GraphvizAddNode(g, "n"); gap> g; gap> GraphvizNodes(g); -rec( n := ) +rec( n := ) gap> GraphvizAddNode(g, "x"); gap> g; gap> GraphvizNodes(g); -rec( n := , x := ) +rec( n := , x := ) # Test add node (name) gap> g := GraphvizGraph();; gap> GraphvizAddNode(g, "n"); gap> GraphvizNodes(g); -rec( n := ) +rec( n := ) gap> GraphvizAddNode(g, "x"); gap> GraphvizNodes(g); -rec( n := , x := ) +rec( n := , x := ) # Test has nodes gap> g := GraphvizGraph();; @@ -99,7 +99,7 @@ gap> GraphvizAddEdge(g, "a", "b");; gap> GraphvizAddEdge(g, "a", "c"); gap> GraphvizNodes(g); -rec( a := , b := , c := ) +rec( a := , b := , c := ) gap> GraphvizAddEdge(g, "c", "a"); gap> GraphvizAddEdge(g, "b", "d"); @@ -126,13 +126,13 @@ gap> GraphvizAddEdge(g, c, d);; gap> GraphvizRemoveNode(g, a); gap> GraphvizNodes(g); -rec( b := , c := , d := ) +rec( b := , c := , d := ) gap> GraphvizEdges(g); [ ] gap> GraphvizRemoveNode(g, b); gap> GraphvizNodes(g); -rec( c := , d := ) +rec( c := , d := ) # Test removing node gap> g := GraphvizGraph();; @@ -141,13 +141,13 @@ gap> GraphvizAddEdge(g, "c", "d");; gap> GraphvizRemoveNode(g, "a"); gap> GraphvizNodes(g); -rec( b := , c := , d := ) +rec( b := , c := , d := ) gap> GraphvizEdges(g); [ ] gap> GraphvizRemoveNode(g, "b"); gap> GraphvizNodes(g); -rec( c := , d := ) +rec( c := , d := ) # Test renaming graph gap> g := GraphvizGraph();; diff --git a/tst/subgraph.tst b/tst/subgraph.tst index 162ba6f..fb1c907 100644 --- a/tst/subgraph.tst +++ b/tst/subgraph.tst @@ -60,7 +60,8 @@ gap> g := GraphvizGraph();; gap> GraphvizAddSubgraph(g, "a");; gap> GraphvizAddContext(g, "b");; gap> GraphvizSubgraphs(g); -rec( a := , b := ) +rec( a := , + b := ) # Test adding a node to a subgraph (does or does not add to parent???) # TODO need to nail down expected behaviour! @@ -70,7 +71,7 @@ gap> GraphvizAddNode(s, "n");; gap> GraphvizNodes(g); rec( ) gap> GraphvizNodes(s); -rec( n := ) +rec( n := ) # Test adding a node to a subgraph which is already in parent fails (by name) gap> g := GraphvizGraph("r");; @@ -229,11 +230,11 @@ gap> GraphvizRemoveNode(g, "d");; gap> GraphvizNodes(g); rec( ) gap> GraphvizNodes(parent); -rec( a := ) +rec( a := ) gap> GraphvizNodes(sibling); -rec( b := ) +rec( b := ) gap> GraphvizNodes(child); -rec( c := ) +rec( c := ) # Test context attribute resetting gap> g := GraphvizDigraph();;