public void AddEdge() { // no edges // add // edges Assert.AreEqual(0, mySimpleGraph.m_adjacency[0, 1]); Assert.AreEqual(0, mySimpleGraph.m_adjacency[0, 2]); Assert.AreEqual(0, mySimpleGraph.m_adjacency[1, 0]); Assert.AreEqual(0, mySimpleGraph.m_adjacency[2, 0]); mySimpleGraph.AddEdge(0, 1); mySimpleGraph.AddEdge(0, 2); mySimpleGraph.AddEdge(0, 0); Assert.AreEqual(1, mySimpleGraph.m_adjacency[0, 1]); Assert.AreEqual(1, mySimpleGraph.m_adjacency[0, 2]); Assert.AreEqual(1, mySimpleGraph.m_adjacency[1, 0]); Assert.AreEqual(1, mySimpleGraph.m_adjacency[2, 0]); }
public void WeakVertices() { List <Vertex <int> > Weak = new List <Vertex <int> >(); string ResultString = ""; Weak = myGraph.WeakVertices(); // 7 if (Weak.Count > 0) { foreach (Vertex <int> item in Weak) { ResultString += item.Value.ToString() + " "; } } Assert.AreEqual("7 ", ResultString); Assert.AreEqual(1, Weak.Count); ResultString = ""; SimpleGraph <int> newGraph = new SimpleGraph <int>(myGraph.capacity); newGraph = myGraph; Assert.AreEqual(newGraph, myGraph); newGraph.RemoveEdge(12, 13); newGraph.RemoveEdge(12, 0); newGraph.RemoveEdge(12, 7); Weak = newGraph.WeakVertices(); // 7 14 if (Weak.Count > 0) { foreach (Vertex <int> item in Weak) { ResultString += item.Value.ToString() + " "; } } Assert.AreEqual("7 14 ", ResultString); Assert.AreEqual(2, Weak.Count); ResultString = ""; // 14 newGraph.AddEdge(5, 10); //newGraph.AddEdge(5, 4); Weak = newGraph.WeakVertices(); if (Weak.Count > 0) { foreach (Vertex <int> item in Weak) { ResultString += item.Value.ToString() + " "; } } Assert.AreEqual("14 ", ResultString); Assert.AreEqual(1, Weak.Count); ResultString = ""; // 8 10 12 14 newGraph.RemoveEdge(3, 7); newGraph.RemoveEdge(11, 7); newGraph.RemoveEdge(12, 7); Weak = newGraph.WeakVertices(); if (Weak.Count > 0) { foreach (Vertex <int> item in Weak) { ResultString += item.Value.ToString() + " "; } } Assert.AreEqual("8 10 12 14 ", ResultString); Assert.AreEqual(4, Weak.Count); ResultString = ""; // 14 newGraph.AddEdge(11, 7); Weak = newGraph.WeakVertices(); if (Weak.Count > 0) { foreach (Vertex <int> item in Weak) { ResultString += item.Value.ToString() + " "; } } Assert.AreEqual("14 ", ResultString); Assert.AreEqual(1, Weak.Count); ResultString = ""; }
public void TestInitialize() { myGraph = new SimpleGraph <int>(30); myGraph.AddVertex(1); // 0 myGraph.AddVertex(2); // 1 myGraph.AddVertex(3); // 2 myGraph.AddVertex(6); // 3 myGraph.AddVertex(5); // 4 myGraph.AddVertex(7); // 5 myGraph.AddVertex(4); // 6 myGraph.AddVertex(8); // 7 myGraph.AddVertex(9); // 8 myGraph.AddVertex(10); // 9 myGraph.AddVertex(13); // 10 myGraph.AddVertex(12); // 11 myGraph.AddVertex(14); // 12 myGraph.AddVertex(77); // 13 myGraph.AddEdge(0, 1); myGraph.AddEdge(0, 2); myGraph.AddEdge(0, 3); myGraph.AddEdge(1, 4); myGraph.AddEdge(1, 5); myGraph.AddEdge(2, 6); myGraph.AddEdge(3, 7); myGraph.AddEdge(7, 8); myGraph.AddEdge(7, 9); myGraph.AddEdge(2, 8); myGraph.AddEdge(8, 10); myGraph.AddEdge(1, 10); myGraph.AddEdge(2, 10); myGraph.AddEdge(4, 10); myGraph.AddEdge(6, 8); myGraph.AddEdge(6, 10); myGraph.AddEdge(6, 3); myGraph.AddEdge(1, 2); myGraph.AddEdge(2, 3); myGraph.AddEdge(9, 11); myGraph.AddEdge(11, 12); myGraph.AddEdge(11, 7); myGraph.AddEdge(12, 7); myGraph.AddEdge(3, 11); myGraph.AddEdge(0, 12); myGraph.AddEdge(3, 13); myGraph.AddEdge(12, 13); myGraph.AddEdge(0, 13); myGraph.AddEdge(9, 13); }