Ejemplo n.º 1
0
        public void RouteBetweenNodesTest()
        {
            int n = 10;

            Func <bool[, ], int, int, bool>[] functions = new Func <bool[, ], int, int, bool>[]
            {
                RouteBetweenNodes.BFS,
                RouteBetweenNodes.DFS
            };

            for (int i = 0; i < 10; i++)
            {
                bool[,] graph = new bool[n, n];

                for (int j = 0; j < n * n; j++)
                {
                    GraphUtilities.SetRandomEdge(graph, n);
                    Tests.TestFunctions(graph, 0, n - 1, functions);
                }
            }
        }
Ejemplo n.º 2
0
        public void DepthFirstSearchTest()
        {
            Func <Vertex[], int, bool[]>[] functions = new Func <Vertex[], int, bool[]>[]
            {
                DepthFirstSearchTestClass.RunDepthFirstSearch,
                DepthFirstSearchTestClass.RunBreadthFirstSearch,
                DepthFirstSearchTestClass.RunBellmanFord,
                DepthFirstSearchTestClass.RunDjikstra,
                DepthFirstSearchTestClass.RunFloydWarshall,
            };

            Vertex[] vertices = new Vertex[10];
            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i] = new Vertex();
            }

            for (int i = 0; i <= vertices.Length * (vertices.Length - 1); i++)
            {
                for (int j = 0; j < vertices.Length; j++)
                {
                    bool[][] results = new bool[vertices.Length][];

                    for (int k = 0; k < functions.Length; k++)
                    {
                        foreach (Vertex vertex in vertices)
                        {
                            vertex.Reset();
                        }

                        results[k] = functions[k](vertices, j);
                        Assert.IsTrue(ArrayUtilities.AreEqual(results[0], results[k]));
                    }
                }

                GraphUtilities.SetRandomEdge(vertices);
            }
        }
Ejemplo n.º 3
0
        public void ShortestPathTest()
        {
            Func <Vertex[], int[, ]>[] functions = new Func <Vertex[], int[, ]>[]
            {
                ShortestPathTestClass.RunBellmanFord,
                ShortestPathTestClass.RunDjikstra,
                ShortestPathTestClass.RunFloydWarshall,
            };

            Vertex[] vertices = new Vertex[10];
            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i] = new Vertex();
            }

            for (int i = 0; i <= vertices.Length * (vertices.Length - 1); i++)
            {
                for (int j = 0; j < vertices.Length; j++)
                {
                    int[][,] results = new int[vertices.Length][, ];

                    for (int k = 0; k < functions.Length; k++)
                    {
                        foreach (Vertex vertex in vertices)
                        {
                            vertex.Reset();
                        }

                        results[k] = functions[k](vertices);
                        Assert.IsTrue(ArrayUtilities.AreEqual(results[0], results[k]));
                    }
                }

                GraphUtilities.SetRandomEdge(vertices);
            }
        }