Skip to content

Commit c4d6a38

Browse files
Add tst/examples
1 parent b9045e8 commit c4d6a38

20 files changed

+1613
-1
lines changed

etc/tst-local-vars.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python3
2+
"""
3+
This simple script adds the local variables used in a GAP tst file to the top
4+
of the file.
5+
"""
6+
import os
7+
import re
8+
import sys
9+
import textwrap
10+
11+
import yaml
12+
from bs4 import BeautifulSoup
13+
14+
15+
def main():
16+
if sys.version_info[0] < 3:
17+
raise Exception("Python 3 is required")
18+
args = sys.argv[1:]
19+
pattern1 = re.compile(r"(\w+)\s*:=")
20+
pattern2 = re.compile(r"for (\w+) in")
21+
for fname in args:
22+
lvars = []
23+
with open(fname, "r") as f:
24+
lines = f.read()
25+
lvars.extend([x.group(1) for x in re.finditer(pattern1, lines)])
26+
lvars.extend([x.group(1) for x in re.finditer(pattern2, lines)])
27+
lvars = ", ".join(sorted([*{*lvars}]))
28+
lvars = [x if x[-1] != "," else x[:-1] for x in textwrap.wrap(lvars, width=72)]
29+
lvars = [""] + ["#@local " + x for x in lvars]
30+
lines = lines.split("\n")
31+
pos = next(i for i in range(len(lines)) if "START_TEST" in lines[i])
32+
lines = lines[:pos] + lvars + lines[pos:]
33+
lines = "\n".join(lines)
34+
with open(fname, "w") as f:
35+
print(f"Writing local variables to {fname}...")
36+
f.write(lines)
37+
38+
39+
if __name__ == "__main__":
40+
main()

tst/dot.tst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
##
88
#############################################################################
99
##
10+
11+
#@local a, b, color, e, g, label, n, shape
1012
gap> START_TEST("graphviz package: dot.tst");
1113
gap> LoadPackage("graphviz", false);;
1214

tst/edge.tst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
##
88
#############################################################################
99
##
10+
11+
#@local a, a1, a2, ab, b, c, cd, color, d, e, e1, e2, g, g1, label, n
1012
gap> START_TEST("graphviz package: edge.tst");
1113
gap> LoadPackage("graphviz", false);;
1214

@@ -81,7 +83,7 @@ gap> a2 := GraphvizAddNode(g1, "a");;
8183
gap> c := GraphvizAddNode(g1, "c");;
8284
gap> e1 := GraphvizAddEdge(g, d, a1);;
8385
gap> e2 := GraphvizAddEdge(g, a2, c);;
84-
Error, Different node in graph with name a.
86+
Error, Different node in graph with name a
8587
gap> GraphvizEdges(g);
8688
[ <graphviz edge (d, a)> ]
8789

tst/examples/angles.tst

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#############################################################################
2+
##
3+
## examples/angles.tst
4+
## Copyright (C) 2024 James D. Mitchell
5+
##
6+
## Licensing information can be found in the README file of this package.
7+
##
8+
#############################################################################
9+
##
10+
11+
# https://graphviz.readthedocs.io/en/stable/examples.html
12+
# https://www.graphviz.org/Gallery/gradient/angles.html
13+
14+
#@local cluster1, cluster2, g, node, pair, pairs
15+
gap> START_TEST("graphviz package: examples/angles.tst");
16+
gap> LoadPackage("graphviz");
17+
true
18+
gap> g := GraphvizDigraph("G");
19+
<graphviz digraph G with 0 nodes and 0 edges>
20+
gap> GraphvizSetAttr(g, "bgcolor", "blue");
21+
<graphviz digraph G with 0 nodes and 0 edges>
22+
gap> cluster1 := GraphvizAddSubgraph(g, "cluster_1");
23+
<graphviz digraph cluster_1 with 0 nodes and 0 edges>
24+
gap> GraphvizSetAttr(cluster1, "fontcolor", "white");
25+
<graphviz digraph cluster_1 with 0 nodes and 0 edges>
26+
gap> GraphvizSetAttr(cluster1, Concatenation("node[shape=circle, style=filled,",
27+
> "fillcolor=\"white:black\", gradientangle=360, label=\"n9:n360\",",
28+
> "fontcolor=black]"));
29+
<graphviz digraph cluster_1 with 0 nodes and 0 edges>
30+
gap> GraphvizAddNode(cluster1, "n9");
31+
<graphviz node n9>
32+
gap> pairs := ListN([8, 7 .. 1], [315, 270 .. 0], {x, y} -> [x, y]);
33+
[ [ 8, 315 ], [ 7, 270 ], [ 6, 225 ], [ 5, 180 ], [ 4, 135 ], [ 3, 90 ],
34+
[ 2, 45 ], [ 1, 0 ] ]
35+
gap> for pair in pairs do
36+
> node := GraphvizAddNode(cluster1, StringFormatted("n{}", pair[1]));
37+
> GraphvizSetAttr(node, "gradientangle", StringFormatted("{}", pair[2]));
38+
> GraphvizSetAttr(node, "label",
39+
> StringFormatted("\"n{}:{}\"", pair[1], pair[2]));
40+
> od;
41+
gap> GraphvizSetAttr(cluster1,
42+
> "label",
43+
> "Linear Angle Variations (white to black gradient)");
44+
<graphviz digraph cluster_1 with 9 nodes and 0 edges>
45+
gap> cluster2 := GraphvizAddSubgraph(g, "cluster_2");
46+
<graphviz digraph cluster_2 with 0 nodes and 0 edges>
47+
gap> GraphvizSetAttr(cluster2, "fontcolor", "white");
48+
<graphviz digraph cluster_2 with 0 nodes and 0 edges>
49+
gap> GraphvizSetAttr(cluster2, Concatenation("node[shape=circle, style=radial,",
50+
> "fillcolor=\"white:black\", gradientangle=360,",
51+
> "label=\"n9:n360\", fontcolor=black]"));
52+
<graphviz digraph cluster_2 with 0 nodes and 0 edges>
53+
gap> GraphvizAddNode(cluster2, "n18");
54+
<graphviz node n18>
55+
gap> pairs := ListN([17, 16 .. 10], [315, 270 .. 0], {x, y} -> [x, y]);
56+
[ [ 17, 315 ], [ 16, 270 ], [ 15, 225 ], [ 14, 180 ], [ 13, 135 ],
57+
[ 12, 90 ], [ 11, 45 ], [ 10, 0 ] ]
58+
gap> for pair in pairs do
59+
> node := GraphvizAddNode(cluster2, StringFormatted("n{}", pair[1]));
60+
> GraphvizSetAttr(node, "gradientangle", StringFormatted("{}", pair[2]));
61+
> GraphvizSetAttr(node, "label", StringFormatted("\"n{}:{}\"",
62+
> pair[1], pair[2]));
63+
> od;
64+
gap> GraphvizSetAttr(cluster2, "label",
65+
> "Radial Angle Variations (white to black gradient)");
66+
<graphviz digraph cluster_2 with 9 nodes and 0 edges>
67+
gap> GraphvizAddEdge(g, "n5", "n14");
68+
<graphviz edge (n5, n14)>
69+
gap> AsString(g);
70+
"//dot\ndigraph G {\n\tbgcolor=blue \nsubgraph cluster_1 {\n\tfontcolor=white \
71+
node[shape=circle, style=filled,fillcolor=\"white:black\", gradientangle=360, \
72+
label=\"n9:n360\",fontcolor=black] label=\"Linear Angle Variations (white to b\
73+
lack gradient)\" \n\tn9\n\tn8 [gradientangle=315, label=\"n8:315\"]\n\tn7 [gra\
74+
dientangle=270, label=\"n7:270\"]\n\tn6 [gradientangle=225, label=\"n6:225\"]\
75+
\n\tn5 [gradientangle=180, label=\"n5:180\"]\n\tn4 [gradientangle=135, label=\
76+
\"n4:135\"]\n\tn3 [gradientangle=90, label=\"n3:90\"]\n\tn2 [gradientangle=45,\
77+
label=\"n2:45\"]\n\tn1 [gradientangle=0, label=\"n1:0\"]\n}\nsubgraph cluster\
78+
_2 {\n\tfontcolor=white node[shape=circle, style=radial,fillcolor=\"white:blac\
79+
k\", gradientangle=360,label=\"n9:n360\", fontcolor=black] label=\"Radial Angl\
80+
e Variations (white to black gradient)\" \n\tn18\n\tn17 [gradientangle=315, la\
81+
bel=\"n17:315\"]\n\tn16 [gradientangle=270, label=\"n16:270\"]\n\tn15 [gradien\
82+
tangle=225, label=\"n15:225\"]\n\tn14 [gradientangle=180, label=\"n14:180\"]\n\
83+
\tn13 [gradientangle=135, label=\"n13:135\"]\n\tn12 [gradientangle=90, label=\
84+
\"n12:90\"]\n\tn11 [gradientangle=45, label=\"n11:45\"]\n\tn10 [gradientangle=\
85+
0, label=\"n10:0\"]\n}\n\tn5 -> n14\n}\n"
86+
87+
#
88+
gap> STOP_TEST("graphviz package: angles.tst");

tst/examples/btree.tst

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#############################################################################
2+
##
3+
## btree.tst
4+
## Copyright (C) 2024 Matthew Pancer
5+
##
6+
## Licensing information can be found in the README file of this package.
7+
##
8+
#############################################################################
9+
##
10+
11+
# https://graphviz.readthedocs.io/en/stable/examples.html
12+
# https://graphviz.org/Gallery/directed/unix.html
13+
14+
#@local s
15+
gap> START_TEST("graphviz package: examples/btree.tst");
16+
gap> LoadPackage("graphviz");
17+
true
18+
19+
#
20+
gap> s := GraphvizDigraph("g");
21+
<graphviz digraph g with 0 nodes and 0 edges>
22+
gap> GraphvizSetAttr(s, "node [shape=record, height=.1]");
23+
<graphviz digraph g with 0 nodes and 0 edges>
24+
gap> GraphvizSetAttr(GraphvizAddNode(s, "node0"), "label", "<f0> |<f1> G|<f2>");
25+
<graphviz node node0>
26+
gap> GraphvizSetAttr(GraphvizAddNode(s, "node1"), "label", "<f0> |<f1> E|<f2>");
27+
<graphviz node node1>
28+
gap> GraphvizSetAttr(GraphvizAddNode(s, "node2"), "label", "<f0> |<f1> B|<f2>");
29+
<graphviz node node2>
30+
gap> GraphvizSetAttr(GraphvizAddNode(s, "node3"), "label", "<f0> |<f1> F|<f2>");
31+
<graphviz node node3>
32+
gap> GraphvizSetAttr(GraphvizAddNode(s, "node4"), "label", "<f0> |<f1> R|<f2>");
33+
<graphviz node node4>
34+
gap> GraphvizSetAttr(GraphvizAddNode(s, "node5"), "label", "<f0> |<f1> H|<f2>");
35+
<graphviz node node5>
36+
gap> GraphvizSetAttr(GraphvizAddNode(s, "node6"), "label", "<f0> |<f1> Y|<f2>");
37+
<graphviz node node6>
38+
gap> GraphvizSetAttr(GraphvizAddNode(s, "node7"), "label", "<f0> |<f1> A|<f2>");
39+
<graphviz node node7>
40+
gap> GraphvizSetAttr(GraphvizAddNode(s, "node8"), "label", "<f0> |<f1> C|<f2>");
41+
<graphviz node node8>
42+
gap> GraphvizAddEdge(s, "node0:f2", "node4:f1");
43+
<graphviz edge (node0:f2, node4:f1)>
44+
gap> GraphvizAddEdge(s, "node0:f0", "node1:f1");
45+
<graphviz edge (node0:f0, node1:f1)>
46+
gap> GraphvizAddEdge(s, "node1:f0", "node2:f1");
47+
<graphviz edge (node1:f0, node2:f1)>
48+
gap> GraphvizAddEdge(s, "node1:f2", "node3:f1");
49+
<graphviz edge (node1:f2, node3:f1)>
50+
gap> GraphvizAddEdge(s, "node2:f2", "node8:f1");
51+
<graphviz edge (node2:f2, node8:f1)>
52+
gap> GraphvizAddEdge(s, "node2:f0", "node7:f1");
53+
<graphviz edge (node2:f0, node7:f1)>
54+
gap> GraphvizAddEdge(s, "node4:f2", "node6:f1");
55+
<graphviz edge (node4:f2, node6:f1)>
56+
gap> GraphvizAddEdge(s, "node4:f0", "node5:f1");
57+
<graphviz edge (node4:f0, node5:f1)>
58+
gap> Print(AsString(s));
59+
//dot
60+
digraph g {
61+
node [shape=record, height=.1]
62+
node0 [label="<f0> |<f1> G|<f2>"]
63+
node1 [label="<f0> |<f1> E|<f2>"]
64+
node2 [label="<f0> |<f1> B|<f2>"]
65+
node3 [label="<f0> |<f1> F|<f2>"]
66+
node4 [label="<f0> |<f1> R|<f2>"]
67+
node5 [label="<f0> |<f1> H|<f2>"]
68+
node6 [label="<f0> |<f1> Y|<f2>"]
69+
node7 [label="<f0> |<f1> A|<f2>"]
70+
node8 [label="<f0> |<f1> C|<f2>"]
71+
node0:f2
72+
node4:f1
73+
node0:f2 -> node4:f1
74+
node0:f0
75+
node1:f1
76+
node0:f0 -> node1:f1
77+
node1:f0
78+
node2:f1
79+
node1:f0 -> node2:f1
80+
node1:f2
81+
node3:f1
82+
node1:f2 -> node3:f1
83+
node2:f2
84+
node8:f1
85+
node2:f2 -> node8:f1
86+
node2:f0
87+
node7:f1
88+
node2:f0 -> node7:f1
89+
node4:f2
90+
node6:f1
91+
node4:f2 -> node6:f1
92+
node4:f0
93+
node5:f1
94+
node4:f0 -> node5:f1
95+
}
96+
97+
#
98+
gap> STOP_TEST("graphviz package: btree.tst");

tst/examples/cluster.tst

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#############################################################################
2+
##
3+
## cluster.tst
4+
## Copyright (C) 2024 Matthew Pancer
5+
##
6+
## Licensing information can be found in the README file of this package.
7+
##
8+
#############################################################################
9+
##
10+
11+
# https://graphviz.readthedocs.io/en/stable/examples.html
12+
13+
#@local cluster0, cluster1, graph
14+
gap> START_TEST("graphviz package: examples/cluster.tst");
15+
gap> LoadPackage("graphviz");
16+
true
17+
gap> graph := GraphvizDigraph("G");
18+
<graphviz digraph G with 0 nodes and 0 edges>
19+
20+
#
21+
gap> cluster0 := GraphvizAddSubgraph(graph, "cluster_0");
22+
<graphviz digraph cluster_0 with 0 nodes and 0 edges>
23+
gap> GraphvizSetAttr(cluster0, "color=\"lightgrey\"");
24+
<graphviz digraph cluster_0 with 0 nodes and 0 edges>
25+
gap> GraphvizSetAttr(cluster0, "style=\"filled\"");
26+
<graphviz digraph cluster_0 with 0 nodes and 0 edges>
27+
gap> GraphvizSetAttr(cluster0, "node [color=\"white\", style=\"filled\"]");
28+
<graphviz digraph cluster_0 with 0 nodes and 0 edges>
29+
gap> GraphvizAddEdge(cluster0, "a0", "a1");
30+
<graphviz edge (a0, a1)>
31+
gap> GraphvizAddEdge(cluster0, "a1", "a2");
32+
<graphviz edge (a1, a2)>
33+
gap> GraphvizAddEdge(cluster0, "a2", "a3");
34+
<graphviz edge (a2, a3)>
35+
gap> GraphvizSetAttr(cluster0, "label=\"process #1\"");
36+
<graphviz digraph cluster_0 with 4 nodes and 3 edges>
37+
38+
#
39+
gap> cluster1 := GraphvizAddSubgraph(graph, "cluster_1");
40+
<graphviz digraph cluster_1 with 0 nodes and 0 edges>
41+
gap> GraphvizSetAttr(cluster1, "color=\"blue\"");
42+
<graphviz digraph cluster_1 with 0 nodes and 0 edges>
43+
gap> GraphvizSetAttr(cluster1, "node [style=\"filled\"]");
44+
<graphviz digraph cluster_1 with 0 nodes and 0 edges>
45+
gap> GraphvizAddEdge(cluster1, "b0", "b1");
46+
<graphviz edge (b0, b1)>
47+
gap> GraphvizAddEdge(cluster1, "b1", "b2");
48+
<graphviz edge (b1, b2)>
49+
gap> GraphvizAddEdge(cluster1, "b2", "b3");
50+
<graphviz edge (b2, b3)>
51+
gap> GraphvizSetAttr(cluster1, "label=\"process #2\"");
52+
<graphviz digraph cluster_1 with 4 nodes and 3 edges>
53+
54+
#
55+
gap> GraphvizAddEdge(graph, "start", "a0");
56+
<graphviz edge (start, a0)>
57+
gap> GraphvizAddEdge(graph, "start", "b0");
58+
<graphviz edge (start, b0)>
59+
gap> GraphvizAddEdge(graph, "a1", "b3");
60+
<graphviz edge (a1, b3)>
61+
gap> GraphvizAddEdge(graph, "b2", "a3");
62+
<graphviz edge (b2, a3)>
63+
gap> GraphvizAddEdge(graph, "a3", "a0");
64+
<graphviz edge (a3, a0)>
65+
gap> GraphvizAddEdge(graph, "a3", "end");
66+
<graphviz edge (a3, end)>
67+
gap> GraphvizAddEdge(graph, "b3", "end");
68+
<graphviz edge (b3, end)>
69+
70+
#
71+
gap> GraphvizSetAttr(graph["start"], "shape", "Mdiamond");
72+
<graphviz node start>
73+
gap> GraphvizSetAttr(graph["end"], "shape", "Msquare");
74+
<graphviz node end>
75+
76+
#
77+
gap> Print(AsString(graph));
78+
//dot
79+
digraph G {
80+
subgraph cluster_0 {
81+
color="lightgrey" style="filled" node [color="white", style="filled"] label="\
82+
process #1"
83+
a0
84+
a1
85+
a0 -> a1
86+
a2
87+
a1 -> a2
88+
a3
89+
a2 -> a3
90+
}
91+
subgraph cluster_1 {
92+
color="blue" node [style="filled"] label="process #2"
93+
b0
94+
b1
95+
b0 -> b1
96+
b2
97+
b1 -> b2
98+
b3
99+
b2 -> b3
100+
}
101+
start [shape=Mdiamond]
102+
start -> a0
103+
start -> b0
104+
a1 -> b3
105+
b2 -> a3
106+
a3 -> a0
107+
end [shape=Msquare]
108+
a3 -> end
109+
b3 -> end
110+
}
111+
112+
#
113+
gap> STOP_TEST("graphviz package: cluster.tst");

0 commit comments

Comments
 (0)