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); }
private void Print() { for (int y = 0; y < roomSize; y++) { for (int x = 0; x < roomSize; x++) { switch (Map.mapa[x, y]) //tady se vypere prislusny obrazek { case 'X': { PictureBox tile = new PictureBox(); tile.Image = wall; tile.Margin = new Padding(0); tile.Size = new Size(30, 30); tile.Location = new Point(x * 30, (y + 1) * 30); Controls.Add(tile); break; } case 'o': { mapGraph.AddVertex(x + " " + y); PictureBox tile = new PictureBox(); tile.Image = coin; tile.Margin = new Padding(0); tile.Size = new Size(30, 30); tile.Location = new Point(x * 30, (y + 1) * 30); Controls.Add(tile); break; } case 'p': { mapGraph.AddVertex(x + " " + y); PictureBox tile = new PictureBox(); tile.Image = powerUp; tile.Margin = new Padding(0); tile.Size = new Size(30, 30); tile.Location = new Point(x * 30, (y + 1) * 30); Controls.Add(tile); break; } case '>': { mapGraph.AddVertex(x + " " + y); pacman.Image = pacmanRight; pacman.Margin = new Padding(0); pacman.Size = new Size(30, 30); pacman.Location = new Point(x * 30, (y + 1) * 30); Controls.Add(pacman); break; } case 'f': { mapGraph.AddVertex(x + " " + y); purpleMonstrum.Image = purpleM; purpleMonstrum.Margin = new Padding(0); purpleMonstrum.Size = new Size(30, 30); purpleMonstrum.Location = new Point(x * 30, (y + 1) * 30); Controls.Add(purpleMonstrum); break; } case 'm': { mapGraph.AddVertex(x + " " + y); blueMonstrum.Image = blueM; blueMonstrum.Margin = new Padding(0); blueMonstrum.Size = new Size(30, 30); blueMonstrum.Location = new Point(x * 30, (y + 1) * 30); Controls.Add(blueMonstrum); break; } case 'z': { mapGraph.AddVertex(x + " " + y); yellowMonstrum.Image = yellowM; yellowMonstrum.Margin = new Padding(0); yellowMonstrum.Size = new Size(30, 30); yellowMonstrum.Location = new Point(x * 30, (y + 1) * 30); Controls.Add(yellowMonstrum); break; } default: { mapGraph.AddVertex(x + " " + y); PictureBox tile = new PictureBox(); tile.Image = null; tile.Margin = new Padding(0); tile.Size = new Size(30, 30); tile.Location = new Point(x * 30, (y + 1) * 30); Controls.Add(tile); break; } } } } for (int y = 0; y < roomSize; y++) { for (int x = 0; x < roomSize; x++) { if (Map.mapa[x, y] != 'X') { AddEdgesToGraph(x, y); } } } }