public void Test_Maze_generate() { /** * 1. Éú³ÉSquareGridͼ * * */ var graph = new SquireGridGraph(row, col, false); DisjSet ds = new DisjSet(graph.VerticesNum()); Random r = new Random(Environment.TickCount); while (ds.Find(0) != ds.Find(graph.VerticesNum() - 1)) { int v1 = r.Next(0, graph.VerticesNum()); if (graph.GetDegree(v1) >= 3) { continue; } Direction direction = getRandomDirection(); int v2 = graph.GetNeighborVertex(v1, direction); if (v2 != -1) { graph.SetEdge(v1, v2, 1); ds.UnionSets(v1, v2); } } Assert.IsTrue(graph.EdgeNum() > 1); Assert.IsTrue(ds.GetConnectedComponentNumber() > 1); }
public void Test_SGG_Creation() { var g = new SquireGridGraph(ROW, COL, false); for (int i = 0; i < g.VerticesNum(); i++) { int row, col; g.GetRowAndColFromVertex(i, out row, out col); g.SetNeighbor(row, col, Direction.East, 1); g.SetNeighbor(row, col, Direction.South, 1); g.SetNeighbor(row, col, Direction.West, 1); g.SetNeighbor(row, col, Direction.North, 1); } ITravel dfs = new Bfs(g, preVisit); dfs.Travel(16); Assert.AreEqual(6280, g.EdgeNum()); }