Ejemplo n.º 1
0
        public void UsingPathFinderOnSameNetworkManyTimesAddingNewNodeToNetwork_GivesRightResult()
        {
            //ARRANGE
            Network    dummy = DummyCreator.CreateDummyNetworkOfTenNodesWithConnectionsOption1();
            PathFinder sut   = new PathFinder(dummy);

            //Original quickest path
            sut.FindQuickestPath("A", "J");
            Assert.AreEqual(18d, sut.QuickestPathResults["J"].QuickestTimeFromStart);

            //ACT, Adding new node and connection
            dummy.AddNode("K");
            dummy.AddConnection("K", "A", 1);
            dummy.AddConnection("K", "J", 1);
            sut.FindQuickestPath("K", "J");

            //ASSERT
            Assert.AreEqual(1d, sut.QuickestPathResults["J"].QuickestTimeFromStart);
            sut.FindQuickestPath("A", "J");
            Assert.AreEqual(2d, sut.QuickestPathResults["J"].QuickestTimeFromStart);

            Assert.AreEqual("A", sut.QuickestPathResults["J"].NodesVisited[0]);
            Assert.AreEqual("K", sut.QuickestPathResults["J"].NodesVisited[1]);
            Assert.AreEqual("J", sut.QuickestPathResults["J"].NodesVisited[2]);
        }
Ejemplo n.º 2
0
        public void FindQuickestPath_EndNodeIsNull_ThrowsRightException()
        {
            //ARRANGE
            Network    dummy = DummyCreator.CreateDummyNetworkOfTenNodesWithConnectionsOption1();
            PathFinder sut   = new PathFinder(dummy);

            //ACT/ASSERT
            Assert.Throws <ArgumentNullException>(() => sut.FindQuickestPath("A", null), "Can not preform operation if nodes are null");
        }
Ejemplo n.º 3
0
        public void FindQuickestPath_EndNodeDoesNotExist_ThrowsRightException()
        {
            //ARRANGE
            Network    dummy = DummyCreator.CreateDummyNetworkOfTenNodesWithConnectionsOption1();
            PathFinder sut   = new PathFinder(dummy);

            //ACT/ASSERT
            Assert.Throws <ArgumentException>(() => sut.FindQuickestPath("A", "X"), "Both start and end node must be in network");
        }
Ejemplo n.º 4
0
        public void FindQuickestPath_StartNodeAndEndNodeAreSame_ThrowsRightException()
        {
            //ARRANGE
            Network    dummy = DummyCreator.CreateDummyNetworkOfTenNodesWithConnectionsOption1();
            PathFinder sut   = new PathFinder(dummy);

            //ACT/ASSERT
            Assert.Throws <ArgumentException>(() => sut.FindQuickestPath("A", "A"), "Start node and end node must be different");
        }
Ejemplo n.º 5
0
        public void UsingPathFinderOnSameNetworkManyTimesWithNewPath_GivesRightResult()
        {
            //ARRANGE
            Network    dummy = DummyCreator.CreateDummyNetworkOfTenNodesWithConnectionsOption1();
            PathFinder sut   = new PathFinder(dummy);

            //Original quickest path
            sut.FindQuickestPath("A", "J");
            Assert.AreEqual(18d, sut.QuickestPathResults["J"].QuickestTimeFromStart);
            sut.FindQuickestPath("A", "E");
            //ASSERT that new quickest path has changed
            Assert.AreEqual(6d, sut.QuickestPathResults["E"].QuickestTimeFromStart);
        }
Ejemplo n.º 6
0
        public void ChangingConnectionValuesExampleOne_UpdatesQuickestPathCorrectly()
        {
            //ARRANGE
            Network    dummy = DummyCreator.CreateDummyNetworkOfTenNodesWithConnectionsOption1();
            PathFinder sut   = new PathFinder(dummy);

            //Original quickest path
            sut.FindQuickestPath("A", "J");
            Assert.AreEqual(18d, sut.QuickestPathResults["J"].QuickestTimeFromStart);

            //ACT, Changing quickest path by adding direct connection
            dummy.AddConnection("A", "J", 1);
            sut.FindQuickestPath("A", "J");

            //ASSERT that new quickest path has changed
            Assert.AreEqual(1d, sut.QuickestPathResults["J"].QuickestTimeFromStart);
        }
Ejemplo n.º 7
0
        public void FindQuickestPath_NOTStoppingAtEndNode_NodesVisitedForNodeJAreCorrect()
        {
            //ARRANGE
            Network       dummy = DummyCreator.CreateDummyNetworkOfTenNodesWithConnectionsOption1();
            PathFinder    sut   = new PathFinder(dummy);
            List <string> expectedNodesVisited = new List <string> {
                "A", "C", "F", "E", "D", "J"
            };


            //ACT
            sut.FindQuickestPath("A", "E", false);
            List <string> actualNodesVisited = sut.QuickestPathResults["J"].NodesVisited;

            //ASSERT
            for (int i = 0; i < expectedNodesVisited.Count; i++)
            {
                Assert.AreEqual(expectedNodesVisited[i], actualNodesVisited[i]);
            }
        }
Ejemplo n.º 8
0
        public void FindQuickestPath_HappyDaysScenarioThree_GivesRightResult()
        {
            //ARRANGE
            Network       dummy = DummyCreator.CreateDummyNetworkOfTenNodesWithConnectionsOption1();
            PathFinder    sut   = new PathFinder(dummy);
            double        expectedQuickestPath = 12d;
            List <string> expectedNodesVisited = new List <string> {
                "B", "A", "C"
            };

            //ACT
            sut.FindQuickestPath("B", "C");
            double        actualQuickestPath = sut.QuickestPathResults["C"].QuickestTimeFromStart;
            List <string> actualNodesVisited = sut.QuickestPathResults["C"].NodesVisited;

            //ASSERT
            Assert.AreEqual(expectedQuickestPath, actualQuickestPath);
            for (int i = 0; i < expectedNodesVisited.Count; i++)
            {
                Assert.AreEqual(expectedNodesVisited[i], actualNodesVisited[i]);
            }
        }
Ejemplo n.º 9
0
        public void PathFinderHasBeenUsedPreviously_DoesResetQuickestPathResultsBeforeCalculatingNewQuickestPath()
        {
            //ARRANGE
            Network    network = DummyCreator.CreateDummyNetworkOfTenNodesWithConnectionsOption1();
            PathFinder sut     = new PathFinder(network);

            sut.FindQuickestPath("A", "D");

            //ACT
            sut.InitializeQuickestPathResults("A");

            //ASSERT
            foreach (var path in sut.QuickestPathResults)
            {
                if (path.Key != "A")
                {
                    Assert.IsTrue(double.IsPositiveInfinity(path.Value.QuickestTimeFromStart));
                }
            }
            foreach (var node in network.Nodes)
            {
                Assert.IsTrue(node.Value.visited == false);
            }
        }