8 print(
"\n=== Test 1: Creating graph ===")
12 g1.add_node(
"A", label=
"Start", shape=
"box")
13 g1.add_node(
"B", label=
"Process", shape=
"ellipse")
14 g1.add_node(
"C", label=
"Decision", shape=
"diamond")
15 g1.add_node(
"D", label=
"End", shape=
"box")
18 g1.add_edge(
"A",
"B", label=
"next")
19 g1.add_edge(
"B",
"C", label=
"evaluate")
20 g1.add_edge(
"C",
"D", label=
"yes")
21 g1.add_edge(
"C",
"B", label=
"no", style=
"dashed")
24 g1.save_to_dot(
"test1_graph.dot")
27 print(
"Displaying graph with GraphViz (dot layout):")
28 g1.display_with_graphviz(layout=
"dot")
30 print(
"\nDisplaying graph with Matplotlib:")
31 g1.display_with_matplotlib()
33 print(
"\n=== Test 2: Loading graph from .dot file ===")
34 if os.path.exists(
"example_graph.dot"):
36 if g2.load_from_dot(
"example_graph.dot"):
37 print(f
"Number of nodes: {g2.get_node_count()}")
38 print(f
"Number of edges: {g2.get_edge_count()}")
39 print(f
"Nodes: {g2.get_nodes()}")
40 print(f
"Edges: {g2.get_edges()}")
43 print(
"\nDisplaying graph with GraphViz (neato layout):")
44 g2.display_with_graphviz(layout=
"neato")
46 print(
"\n=== Test 3: Creating a more complex graph ===")
50 for i
in range(1, 11):
51 g3.add_node(f
"Node{i}")
54 for i
in range(1, 10):
55 g3.add_edge(f
"Node{i}", f
"Node{i+1}")
56 g3.add_edge(
"Node10",
"Node1")
59 g3.add_edge(
"Node1",
"Node5")
60 g3.add_edge(
"Node3",
"Node8")
61 g3.add_edge(
"Node7",
"Node2")
64 print(
"\nDisplaying complex graph with GraphViz (dot layout):")
65 g3.display_with_graphviz(layout=
"dot")
67 print(
"\nDisplaying complex graph with GraphViz (circo layout):")
68 g3.display_with_graphviz(layout=
"circo")
70 print(
"\nDisplaying complex graph with GraphViz (fdp layout):")
71 g3.display_with_graphviz(layout=
"fdp")
73 print(
"\nDisplaying complex graph with Matplotlib:")
74 g3.display_with_matplotlib()