Пример #1
0
        public void Question_4_1_InvalidCases()
        {
            var tree = new GraphNode <int>(0, null);

            TestHelpers.AssertExceptionThrown(() => { Question_4_1.AreConnectedBFS(null, tree); }, typeof(ArgumentNullException));
            TestHelpers.AssertExceptionThrown(() => { Question_4_1.AreConnectedBFS(tree, null); }, typeof(ArgumentNullException));
        }
Пример #2
0
        private void Validate <T>(GraphNode <T> node1, GraphNode <T> node2, bool expected, bool expectedBiDirectional)
            where T : IEquatable <T>
        {
            var result = Question_4_1.AreConnectedBFS(node1, node2);

            Assert.AreEqual(expected, result, "Result did not equal expected.");
            result = Question_4_1.AreConnectedBiDirectionalBFS(node1, node2);
            Assert.AreEqual(expectedBiDirectional, result, "BiDirectional result was not expected.");
        }
Пример #3
0
        public void ExistsRouteTest_2()
        {
            var node0 = new GraphNode <int>(0);
            var node1 = new GraphNode <int>(1);
            var node2 = new GraphNode <int>(2);
            var node3 = new GraphNode <int>(3);
            var node4 = new GraphNode <int>(4);
            var node5 = new GraphNode <int>(5);

            node0.Children.Add(node1);
            node0.Children.Add(node4);
            node0.Children.Add(node5);
            node1.Children.Add(node3);
            node1.Children.Add(node4);
            node2.Children.Add(node1);
            node3.Children.Add(node2);
            node3.Children.Add(node4);

            var testGraph = new Graph <int>();

            testGraph.Nodes.Add(node0);
            testGraph.Nodes.Add(node1);
            testGraph.Nodes.Add(node2);
            testGraph.Nodes.Add(node3);
            testGraph.Nodes.Add(node4);
            testGraph.Nodes.Add(node5);

            Assert.IsTrue(Question_4_1.ExistsRoute(testGraph, node0, node1), "Path does not exist between Node 0 and 1.");
            Assert.IsTrue(Question_4_1.ExistsRoute(testGraph, node0, node2), "Path does not exist between Node 0 and 2.");
            Assert.IsTrue(Question_4_1.ExistsRoute(testGraph, node0, node3), "Path does not exist between Node 0 and 3.");
            Assert.IsTrue(Question_4_1.ExistsRoute(testGraph, node0, node4), "Path does not exist between Node 0 and 4.");
            Assert.IsTrue(Question_4_1.ExistsRoute(testGraph, node0, node5), "Path does not exist between Node 0 and 5.");
            Assert.IsTrue(Question_4_1.ExistsRoute(testGraph, node1, node2), "Path does not exist between Node 1 and 2.");
            Assert.IsTrue(Question_4_1.ExistsRoute(testGraph, node1, node3), "Path does not exist between Node 1 and 3.");
            Assert.IsTrue(Question_4_1.ExistsRoute(testGraph, node1, node4), "Path does not exist between Node 1 and 4.");
            Assert.IsTrue(Question_4_1.ExistsRoute(testGraph, node2, node3), "Path does not exist between Node 2 and 3.");
            Assert.IsTrue(Question_4_1.ExistsRoute(testGraph, node2, node4), "Path does not exist between Node 2 and 4.");
            Assert.IsTrue(Question_4_1.ExistsRoute(testGraph, node3, node4), "Path does not exist between Node 3 and 4.");

            Assert.IsFalse(Question_4_1.ExistsRoute(testGraph, node1, node5), "Path exists between Node 1 and 5.");
            Assert.IsFalse(Question_4_1.ExistsRoute(testGraph, node2, node5), "Path exists between Node 2 and 5.");
            Assert.IsFalse(Question_4_1.ExistsRoute(testGraph, node3, node5), "Path exists between Node 3 and 5.");
            Assert.IsFalse(Question_4_1.ExistsRoute(testGraph, node4, node5), "Path exists between Node 4 and 5.");
        }