|
2 | 2 | using System.Linq;
|
3 | 3 | using NUnit.Framework;
|
4 | 4 |
|
5 |
| -namespace Rubjerg.Graphviz.Test |
| 5 | +namespace Rubjerg.Graphviz.Test; |
| 6 | + |
| 7 | +[TestFixture()] |
| 8 | +public class CGraphBasicOperations |
6 | 9 | {
|
7 |
| - [TestFixture()] |
8 |
| - public class CGraphBasicOperations |
| 10 | + [Test()] |
| 11 | + public void TestCopyAttributes() |
9 | 12 | {
|
10 |
| - [Test()] |
11 |
| - public void TestCopyAttributes() |
12 |
| - { |
13 |
| - RootGraph root = Utils.CreateUniqueTestGraph(); |
14 |
| - Node n1 = root.GetOrAddNode("1"); |
15 |
| - Node.IntroduceAttribute(root, "test", "foo"); |
16 |
| - Assert.AreEqual("foo", n1.GetAttribute("test")); |
17 |
| - n1.SetAttribute("test", "bar"); |
18 |
| - Assert.AreEqual("bar", n1.GetAttribute("test")); |
19 |
| - |
20 |
| - RootGraph root2 = Utils.CreateUniqueTestGraph(); |
21 |
| - Node n2 = root2.GetOrAddNode("2"); |
22 |
| - Assert.AreEqual(null, n2.GetAttribute("test")); |
23 |
| - Assert.AreEqual(0, n1.CopyAttributesTo(n2)); |
24 |
| - Assert.AreEqual("bar", n2.GetAttribute("test")); |
25 |
| - } |
| 13 | + RootGraph root = Utils.CreateUniqueTestGraph(); |
| 14 | + Node n1 = root.GetOrAddNode("1"); |
| 15 | + Node.IntroduceAttribute(root, "test", "foo"); |
| 16 | + Assert.AreEqual("foo", n1.GetAttribute("test")); |
| 17 | + n1.SetAttribute("test", "bar"); |
| 18 | + Assert.AreEqual("bar", n1.GetAttribute("test")); |
| 19 | + |
| 20 | + RootGraph root2 = Utils.CreateUniqueTestGraph(); |
| 21 | + Node n2 = root2.GetOrAddNode("2"); |
| 22 | + Assert.AreEqual(null, n2.GetAttribute("test")); |
| 23 | + Assert.AreEqual(0, n1.CopyAttributesTo(n2)); |
| 24 | + Assert.AreEqual("bar", n2.GetAttribute("test")); |
| 25 | + } |
26 | 26 |
|
27 |
| - [Test()] |
28 |
| - public void TestDeletions() |
29 |
| - { |
30 |
| - RootGraph root = Utils.CreateUniqueTestGraph(); |
| 27 | + [Test()] |
| 28 | + public void TestDeletions() |
| 29 | + { |
| 30 | + RootGraph root = Utils.CreateUniqueTestGraph(); |
31 | 31 |
|
32 |
| - Node tail = root.GetOrAddNode("1"); |
33 |
| - Node head = root.GetOrAddNode("2"); |
34 |
| - Node other = root.GetOrAddNode("3"); |
| 32 | + Node tail = root.GetOrAddNode("1"); |
| 33 | + Node head = root.GetOrAddNode("2"); |
| 34 | + Node other = root.GetOrAddNode("3"); |
35 | 35 |
|
36 |
| - Edge edge = root.GetOrAddEdge(tail, head, "edge"); |
37 |
| - Edge tailout = root.GetOrAddEdge(tail, other, "tailout"); |
38 |
| - Edge headout = root.GetOrAddEdge(head, other, "headout"); |
39 |
| - Edge tailin = root.GetOrAddEdge(other, tail, "tailin"); |
40 |
| - Edge headin = root.GetOrAddEdge(other, head, "headin"); |
| 36 | + Edge edge = root.GetOrAddEdge(tail, head, "edge"); |
| 37 | + Edge tailout = root.GetOrAddEdge(tail, other, "tailout"); |
| 38 | + Edge headout = root.GetOrAddEdge(head, other, "headout"); |
| 39 | + Edge tailin = root.GetOrAddEdge(other, tail, "tailin"); |
| 40 | + Edge headin = root.GetOrAddEdge(other, head, "headin"); |
41 | 41 |
|
42 |
| - Assert.IsTrue(root.Equals(root.MyRootGraph)); |
43 |
| - Assert.IsTrue(root.Equals(tail.MyRootGraph)); |
44 |
| - Assert.IsTrue(root.Equals(edge.MyRootGraph)); |
| 42 | + Assert.IsTrue(root.Equals(root.MyRootGraph)); |
| 43 | + Assert.IsTrue(root.Equals(tail.MyRootGraph)); |
| 44 | + Assert.IsTrue(root.Equals(edge.MyRootGraph)); |
45 | 45 |
|
46 |
| - Assert.AreEqual(3, tail.TotalDegree()); |
47 |
| - Assert.AreEqual(3, head.TotalDegree()); |
48 |
| - Assert.AreEqual(3, root.Nodes().Count()); |
| 46 | + Assert.AreEqual(3, tail.TotalDegree()); |
| 47 | + Assert.AreEqual(3, head.TotalDegree()); |
| 48 | + Assert.AreEqual(3, root.Nodes().Count()); |
49 | 49 |
|
50 |
| - root.Delete(edge); |
| 50 | + root.Delete(edge); |
51 | 51 |
|
52 |
| - Assert.AreEqual(2, tail.TotalDegree()); |
53 |
| - Assert.AreEqual(2, head.TotalDegree()); |
54 |
| - Assert.AreEqual(3, root.Nodes().Count()); |
| 52 | + Assert.AreEqual(2, tail.TotalDegree()); |
| 53 | + Assert.AreEqual(2, head.TotalDegree()); |
| 54 | + Assert.AreEqual(3, root.Nodes().Count()); |
55 | 55 |
|
56 |
| - root.Delete(tail); |
| 56 | + root.Delete(tail); |
57 | 57 |
|
58 |
| - Assert.AreEqual(2, root.Nodes().Count()); |
59 |
| - Assert.AreEqual(2, other.TotalDegree()); |
60 |
| - } |
| 58 | + Assert.AreEqual(2, root.Nodes().Count()); |
| 59 | + Assert.AreEqual(2, other.TotalDegree()); |
| 60 | + } |
61 | 61 |
|
62 |
| - [Test()] |
63 |
| - public void TestNodeMerge() |
64 |
| - { |
65 |
| - RootGraph root = Utils.CreateUniqueTestGraph(); |
66 |
| - Node merge = root.GetOrAddNode("merge"); |
67 |
| - Node target = root.GetOrAddNode("target"); |
68 |
| - Node other = root.GetOrAddNode("other"); |
69 |
| - |
70 |
| - Edge selfloop = root.GetOrAddEdge(merge, merge, "selfloop"); |
71 |
| - Edge contracted = root.GetOrAddEdge(merge, target, "contracted"); |
72 |
| - Edge counter = root.GetOrAddEdge(target, merge, "counter"); |
73 |
| - Edge mergeout = root.GetOrAddEdge(merge, other, "mergeout"); |
74 |
| - Edge targetout = root.GetOrAddEdge(target, other, "targetout"); |
75 |
| - Edge mergein = root.GetOrAddEdge(other, merge, "mergein"); |
76 |
| - Edge targetin = root.GetOrAddEdge(other, target, "targetin"); |
77 |
| - |
78 |
| - Assert.AreEqual(6, merge.TotalDegree()); |
79 |
| - Assert.AreEqual(4, target.TotalDegree()); |
80 |
| - Assert.AreEqual(3, root.Nodes().Count()); |
81 |
| - |
82 |
| - //root.ComputeDotLayout(); |
83 |
| - //root.ToSvgFile("dump1.svg"); |
84 |
| - //root.FreeLayout(); |
85 |
| - //root.ToDotFile("dump1.dot"); |
86 |
| - |
87 |
| - root.Merge(merge, target); |
88 |
| - |
89 |
| - //root.ComputeDotLayout(); |
90 |
| - //root.ToSvgFile("dump2.svg"); |
91 |
| - //root.FreeLayout(); |
92 |
| - //root.ToDotFile("dump2.dot"); |
93 |
| - |
94 |
| - Assert.AreEqual(2, root.Nodes().Count()); |
95 |
| - Assert.AreEqual(3, target.InDegree()); |
96 |
| - Assert.AreEqual(3, target.OutDegree()); |
97 |
| - Assert.AreEqual(2, other.InDegree()); |
98 |
| - Assert.AreEqual(2, other.OutDegree()); |
99 |
| - } |
| 62 | + [Test()] |
| 63 | + public void TestNodeMerge() |
| 64 | + { |
| 65 | + RootGraph root = Utils.CreateUniqueTestGraph(); |
| 66 | + Node merge = root.GetOrAddNode("merge"); |
| 67 | + Node target = root.GetOrAddNode("target"); |
| 68 | + Node other = root.GetOrAddNode("other"); |
| 69 | + |
| 70 | + Edge selfloop = root.GetOrAddEdge(merge, merge, "selfloop"); |
| 71 | + Edge contracted = root.GetOrAddEdge(merge, target, "contracted"); |
| 72 | + Edge counter = root.GetOrAddEdge(target, merge, "counter"); |
| 73 | + Edge mergeout = root.GetOrAddEdge(merge, other, "mergeout"); |
| 74 | + Edge targetout = root.GetOrAddEdge(target, other, "targetout"); |
| 75 | + Edge mergein = root.GetOrAddEdge(other, merge, "mergein"); |
| 76 | + Edge targetin = root.GetOrAddEdge(other, target, "targetin"); |
| 77 | + |
| 78 | + Assert.AreEqual(6, merge.TotalDegree()); |
| 79 | + Assert.AreEqual(4, target.TotalDegree()); |
| 80 | + Assert.AreEqual(3, root.Nodes().Count()); |
| 81 | + |
| 82 | + //root.ComputeDotLayout(); |
| 83 | + //root.ToSvgFile("dump1.svg"); |
| 84 | + //root.FreeLayout(); |
| 85 | + //root.ToDotFile("dump1.dot"); |
| 86 | + |
| 87 | + root.Merge(merge, target); |
| 88 | + |
| 89 | + //root.ComputeDotLayout(); |
| 90 | + //root.ToSvgFile("dump2.svg"); |
| 91 | + //root.FreeLayout(); |
| 92 | + //root.ToDotFile("dump2.dot"); |
| 93 | + |
| 94 | + Assert.AreEqual(2, root.Nodes().Count()); |
| 95 | + Assert.AreEqual(3, target.InDegree()); |
| 96 | + Assert.AreEqual(3, target.OutDegree()); |
| 97 | + Assert.AreEqual(2, other.InDegree()); |
| 98 | + Assert.AreEqual(2, other.OutDegree()); |
| 99 | + } |
100 | 100 |
|
101 |
| - [Test()] |
102 |
| - public void TestEdgeContraction() |
| 101 | + [Test()] |
| 102 | + public void TestEdgeContraction() |
| 103 | + { |
| 104 | + //NativeMethods.AllocConsole(); |
| 105 | + RootGraph root = Utils.CreateUniqueTestGraph(); |
| 106 | + Node tail = root.GetOrAddNode("x"); |
| 107 | + Node head = root.GetOrAddNode("xx"); |
| 108 | + Node other = root.GetOrAddNode("xxx"); |
| 109 | + |
| 110 | + Edge contracted = root.GetOrAddEdge(tail, head, "tocontract"); |
| 111 | + Edge parallel = root.GetOrAddEdge(tail, head, "parallel"); |
| 112 | + Edge counterparallel = root.GetOrAddEdge(head, tail, "counterparallel"); |
| 113 | + Edge tailout = root.GetOrAddEdge(tail, other, "tailout"); |
| 114 | + Edge headout = root.GetOrAddEdge(head, other, "headout"); |
| 115 | + Edge tailin = root.GetOrAddEdge(other, tail, "tailin"); |
| 116 | + Edge headin = root.GetOrAddEdge(other, head, "headin"); |
| 117 | + |
| 118 | + foreach (Node n in root.Nodes()) |
103 | 119 | {
|
104 |
| - //NativeMethods.AllocConsole(); |
105 |
| - RootGraph root = Utils.CreateUniqueTestGraph(); |
106 |
| - Node tail = root.GetOrAddNode("x"); |
107 |
| - Node head = root.GetOrAddNode("xx"); |
108 |
| - Node other = root.GetOrAddNode("xxx"); |
109 |
| - |
110 |
| - Edge contracted = root.GetOrAddEdge(tail, head, "tocontract"); |
111 |
| - Edge parallel = root.GetOrAddEdge(tail, head, "parallel"); |
112 |
| - Edge counterparallel = root.GetOrAddEdge(head, tail, "counterparallel"); |
113 |
| - Edge tailout = root.GetOrAddEdge(tail, other, "tailout"); |
114 |
| - Edge headout = root.GetOrAddEdge(head, other, "headout"); |
115 |
| - Edge tailin = root.GetOrAddEdge(other, tail, "tailin"); |
116 |
| - Edge headin = root.GetOrAddEdge(other, head, "headin"); |
117 |
| - |
118 |
| - foreach (Node n in root.Nodes()) |
| 120 | + n.SafeSetAttribute("label", n.GetName(), "no"); |
| 121 | + n.SafeSetAttribute("fontname", "Arial", "Arial"); |
| 122 | + foreach (Edge e in n.EdgesOut()) |
119 | 123 | {
|
120 |
| - n.SafeSetAttribute("label", n.GetName(), "no"); |
121 |
| - n.SafeSetAttribute("fontname", "Arial", "Arial"); |
122 |
| - foreach (Edge e in n.EdgesOut()) |
123 |
| - { |
124 |
| - e.SafeSetAttribute("label", e.GetName(), "no"); |
125 |
| - e.SafeSetAttribute("fontname", "Arial", "Arial"); |
126 |
| - } |
| 124 | + e.SafeSetAttribute("label", e.GetName(), "no"); |
| 125 | + e.SafeSetAttribute("fontname", "Arial", "Arial"); |
127 | 126 | }
|
| 127 | + } |
128 | 128 |
|
129 | 129 |
|
130 |
| - Assert.AreEqual(5, tail.TotalDegree()); |
131 |
| - Assert.AreEqual(5, head.TotalDegree()); |
132 |
| - Assert.AreEqual(3, root.Nodes().Count()); |
| 130 | + Assert.AreEqual(5, tail.TotalDegree()); |
| 131 | + Assert.AreEqual(5, head.TotalDegree()); |
| 132 | + Assert.AreEqual(3, root.Nodes().Count()); |
133 | 133 |
|
134 |
| - Node contraction = root.Contract(contracted, "contraction result"); |
| 134 | + Node contraction = root.Contract(contracted, "contraction result"); |
135 | 135 |
|
136 |
| - foreach (Node n in root.Nodes()) |
| 136 | + foreach (Node n in root.Nodes()) |
| 137 | + { |
| 138 | + n.SafeSetAttribute("label", n.GetName(), "no"); |
| 139 | + n.SafeSetAttribute("fontname", "Arial", "Arial"); |
| 140 | + foreach (Edge e in n.EdgesOut()) |
137 | 141 | {
|
138 |
| - n.SafeSetAttribute("label", n.GetName(), "no"); |
139 |
| - n.SafeSetAttribute("fontname", "Arial", "Arial"); |
140 |
| - foreach (Edge e in n.EdgesOut()) |
141 |
| - { |
142 |
| - e.SafeSetAttribute("label", e.GetName(), "no"); |
143 |
| - e.SafeSetAttribute("fontname", "Arial", "Arial"); |
144 |
| - } |
| 142 | + e.SafeSetAttribute("label", e.GetName(), "no"); |
| 143 | + e.SafeSetAttribute("fontname", "Arial", "Arial"); |
145 | 144 | }
|
146 |
| - |
147 |
| - //Console.Read(); |
148 |
| - Assert.AreEqual(2, root.Nodes().Count()); |
149 |
| - Assert.AreEqual(2, contraction.InDegree()); |
150 |
| - Assert.AreEqual(2, contraction.OutDegree()); |
151 |
| - Assert.AreEqual(2, other.InDegree()); |
152 |
| - Assert.AreEqual(2, other.OutDegree()); |
153 | 145 | }
|
154 | 146 |
|
| 147 | + //Console.Read(); |
| 148 | + Assert.AreEqual(2, root.Nodes().Count()); |
| 149 | + Assert.AreEqual(2, contraction.InDegree()); |
| 150 | + Assert.AreEqual(2, contraction.OutDegree()); |
| 151 | + Assert.AreEqual(2, other.InDegree()); |
| 152 | + Assert.AreEqual(2, other.OutDegree()); |
155 | 153 | }
|
| 154 | + |
156 | 155 | }
|
0 commit comments