示例#1
0
        //tested method]_[expected input]_[expected behavior]
        public void GetPath_BetweenTwoPoints_ShouldReturnCorrectPath(IntVector2 startPoint, IntVector2 endPoint, List <IntVector2> expectedPath)
        {
            // Arrange
            IGrid grid = CreateZigzagGrid();
            IPathFinderController pathFinderController = new PathFinderController(grid);
            // Act
            var actualPath = pathFinderController.GetPath(startPoint, endPoint, null);

            // Assert
            Assert.True(expectedPath.SequenceEqual(actualPath));
        }
示例#2
0
        public void GetPath_BetweenTwoPoints_ShouldReturnDestinationPointBusy(IntVector2 startPoint, IntVector2 endPoint)
        {
            // Arrange
            bool  destinationBusyCalled = false;
            IGrid grid = CreateWallGrid();
            IPathFinderController pathFinderController = new PathFinderController(grid);

            pathFinderController.DestinationPointIsNotEmpty += v => destinationBusyCalled = true;

            // Act
            pathFinderController.GetPath(startPoint, endPoint, null);

            // Assert
            Assert.True(destinationBusyCalled);
        }
示例#3
0
        public void GetPath_BetweenTwoPoints_ShouldReturnNoWayToPoint(IntVector2 startPoint, IntVector2 endPoint)
        {
            // Arrange
            bool  noWayCalled = false;
            IGrid grid        = CreateWallGrid();
            IPathFinderController pathFinderController = new PathFinderController(grid);

            pathFinderController.NoWayToDestinationPoint += v => noWayCalled = true;

            // Act
            pathFinderController.GetPath(startPoint, endPoint, null);

            // Assert
            Assert.True(noWayCalled);
        }
示例#4
0
        public void GetPath_BetweenTwoPointsRepeatedly_ShouldReturnCorrectPath()
        {
            // Arrange
            int   findPathCorrectXTimes = 0;
            int   XTimes       = 5;
            var   expectedPath = PathFinderTestData.GetList0_0_5_5();
            IGrid grid         = CreateZigzagGrid();
            IPathFinderController pathFinderController = new PathFinderController(grid);

            // Act
            for (int i = 0; i < XTimes; i++)
            {
                var actualPath = pathFinderController.GetPath(GetPoint(0, 0), GetPoint(5, 5), null);
                if (expectedPath.SequenceEqual(actualPath))
                {
                    findPathCorrectXTimes++;
                }
            }
            // Assert
            Assert.Equal(findPathCorrectXTimes, XTimes);
        }