public void Test() { #region Orientovaná kružnice // orientovaný ohodnocený. var graph1 = new DirectedWeightedGraph(false); for (int i = 'a'; i < 'h'; i++) { graph1.AddVertex(Convert.ToString(Convert.ToChar(i))); } graph1.AddEdge("a", "b", 1); graph1.AddEdge("b", "c", 2); graph1.AddEdge("c", "d", 3); graph1.AddEdge("d", "e", -4); graph1.AddEdge("f", "c", 5); graph1.AddEdge("a", "g", 600); graph1.AddEdge("b", "f", 0); graph1.AddEdge("e", "b", 7); Assert.IsTrue(Cycle.ContainsCycle <DirectedWeightedGraph>(graph1)); graph1.Clear(); #endregion #region Orientovaný bez kružnice // orientovaný ohodnocený. var graph3 = new DirectedUnweightedGraph(false); for (int i = 'a'; i < 'h'; i++) { graph3.AddVertex(Convert.ToString(Convert.ToChar(i))); } graph3.AddEdge("a", "b"); graph3.AddEdge("b", "c"); graph3.AddEdge("c", "d"); graph3.AddEdge("a", "g"); graph3.AddEdge("b", "f"); graph3.AddEdge("e", "b"); Assert.IsFalse(Cycle.ContainsCycle <DirectedUnweightedGraph>(graph3)); graph3.Clear(); #endregion }
public void Test() { var graph = new DirectedUnweightedGraph(false); int x = 0; for (int i = 'a'; i < 'h'; i++) { graph.AddVertex(Convert.ToString(Convert.ToChar(i))); graph.GetVertex(Convert.ToString(Convert.ToChar(i))).distance = x; x++; } var heap = new MinHeap <DirectedUnweightedGraph>(graph); for (int i = 'a'; i < 'g'; i++) { heap.Add(graph.GetVertex(Convert.ToString(Convert.ToChar(i)))); } Assert.AreEqual(graph.GetVertex("a"), heap.Peek()); Assert.AreEqual(graph.GetVertex("a"), heap.GetMin()); Assert.AreEqual(graph.GetVertex("b"), heap.GetMin()); graph.GetVertex("g").distance = -2; heap.Add(graph.GetVertex("g")); Assert.AreEqual(graph.GetVertex("g"), heap.GetMin()); Assert.IsFalse(heap.Empty()); graph.GetVertex("d").distance = -20; heap.Update(graph.GetVertex("d")); Assert.AreEqual(graph.GetVertex("d"), heap.GetMin()); Assert.AreEqual(graph.GetVertex("c"), heap.GetMin()); Assert.AreEqual(graph.GetVertex("e"), heap.GetMin()); Assert.AreEqual(graph.GetVertex("f"), heap.GetMin()); Assert.IsTrue(heap.Empty()); }
public void Test() { DirectedUnweightedGraph graph1 = new DirectedUnweightedGraph(false); #region Basic stuff Assert.AreEqual(true, graph1.directed); Assert.AreEqual(false, graph1.weighted); Assert.AreEqual(false, graph1.multigraph); #endregion #region Vertex stuff for (char i = 'a'; i <= 'h'; i++) { graph1.AddVertex(Convert.ToString(i)); } graph1.AddVertex("a"); Assert.AreEqual(8, graph1.verticesCount); graph1.RemoveVertex("h"); graph1.RemoveVertex("z"); Assert.AreEqual(7, graph1.verticesCount); Assert.AreEqual(true, graph1.ExistVertex("a")); Assert.AreEqual(false, graph1.ExistVertex("z")); #endregion #region Edge stuff graph1.AddEdge("a", "b"); graph1.AddEdge("a", "b"); Assert.AreEqual(1, graph1.edgesCount); graph1.AddEdge("a", "a"); Assert.AreEqual(1, graph1.edgesCount); graph1.AddEdge("a", "z"); graph1.AddEdge("z", "a"); graph1.AddEdge("y", "z"); Assert.AreEqual(1, graph1.edgesCount); graph1.AddEdge("b", "c"); graph1.AddEdge("c", "d"); graph1.AddEdge("d", "e"); graph1.AddEdge("e", "f"); graph1.AddEdge("f", "g"); Assert.AreEqual(6, graph1.edgesCount); graph1.RemoveEdge("a", "b"); graph1.RemoveEdge("a", "c"); Assert.AreEqual(5, graph1.edgesCount); Assert.AreEqual(true, graph1.ExistEdge("b", "c")); graph1.RemoveVertex("d"); Assert.AreEqual(3, graph1.edgesCount); Assert.AreEqual(1, graph1.GetEdgeWeight("a", "b")); #endregion graph1.Clear(); Assert.AreEqual(0, graph1.verticesCount); Assert.AreEqual(0, graph1.edgesCount); DirectedUnweightedGraph graph2 = new DirectedUnweightedGraph(true); #region Basic stuff Assert.AreEqual(true, graph2.directed); Assert.AreEqual(false, graph2.weighted); Assert.AreEqual(true, graph2.multigraph); #endregion #region Vertex stuff for (char i = 'a'; i <= 'h'; i++) { graph2.AddVertex(Convert.ToString(i)); } graph2.AddVertex("a"); Assert.AreEqual(8, graph2.verticesCount); graph2.RemoveVertex("h"); graph2.RemoveVertex("z"); Assert.AreEqual(7, graph2.verticesCount); Assert.AreEqual(true, graph2.ExistVertex("a")); Assert.AreEqual(false, graph2.ExistVertex("z")); #endregion #region Edge stuff graph2.AddEdge("a", "b"); graph2.AddEdge("a", "b"); Assert.AreEqual(2, graph2.edgesCount); graph2.AddEdge("a", "a"); Assert.AreEqual(2, graph2.edgesCount); graph2.AddEdge("a", "z"); graph2.AddEdge("z", "a"); graph2.AddEdge("y", "z"); Assert.AreEqual(2, graph2.edgesCount); graph2.AddEdge("b", "c"); graph2.AddEdge("c", "d"); graph2.AddEdge("d", "e"); graph2.AddEdge("e", "f"); graph2.AddEdge("f", "g"); Assert.AreEqual(7, graph2.edgesCount); graph2.RemoveEdge("a", "b"); graph2.RemoveEdge("a", "c"); Assert.AreEqual(6, graph2.edgesCount); Assert.AreEqual(true, graph2.ExistEdge("a", "b")); graph2.RemoveVertex("d"); Assert.AreEqual(4, graph2.edgesCount); Assert.AreEqual(1, graph1.GetEdgeWeight("a", "b")); #endregion graph2.Clear(); Assert.AreEqual(0, graph2.verticesCount); Assert.AreEqual(0, graph2.edgesCount); }