Exemplo n.º 1
0
        public void TestShouldTurnAndMoveInTheRightDirection()
        {
            Tractor tractor = new Tractor(new Field()
            {
                Height = 5, Width = 5
            });
            var moveCommand = new MoveForwardCommand(tractor);
            var turnCommand = new TurnClockwiseCommand(tractor);

            turnCommand.Execute();
            moveCommand.Execute();
            Assert.AreEqual(1, tractor.UnitPosition.X);
            Assert.AreEqual(0, tractor.UnitPosition.Y);

            turnCommand.Execute();
            moveCommand.Execute();
            Assert.AreEqual(1, tractor.UnitPosition.X);
            Assert.AreEqual(-1, tractor.UnitPosition.Y);

            turnCommand.Execute();
            moveCommand.Execute();
            Assert.AreEqual(0, tractor.UnitPosition.X);
            Assert.AreEqual(-1, tractor.UnitPosition.Y);

            turnCommand.Execute();
            moveCommand.Execute();
            Assert.AreEqual(0, tractor.UnitPosition.X);
            Assert.AreEqual(0, tractor.UnitPosition.Y);
        }
Exemplo n.º 2
0
        public void Move_TableTop5Into5Placed3Into3RobotMovedFiveTimesForward()
        {
            //arrange
            TableTop     tt = new TableTop(5, 5);
            ToyRobot     tr = new ToyRobot();
            CommandModel cm = new CommandModel()
            {
                Command    = Command.PLACE,
                Coordinate = new Coordinate(3, 3),
                Facing     = Facing.NORTH
            };
            ICommandInterface placeCommand = new PlaceRobotCommand(cm, tr, tt);

            placeCommand.Execute();

            ICommandInterface moveCommand = new MoveForwardCommand(tr, tt);

            //act
            moveCommand.Execute();
            moveCommand.Execute();
            moveCommand.Execute();
            moveCommand.Execute();
            moveCommand.Execute();


            //assert: actual/expected
            Assert.IsTrue(tr.RobotStillOnTableTop(tt));
        }
Exemplo n.º 3
0
        public void Move_TableTopFiveIntoFiveAlreadyPlacedMovedTwiceForward()
        {
            //arrange
            TableTop     tt = new TableTop(5, 5);
            ToyRobot     tr = new ToyRobot();
            CommandModel cm = new CommandModel()
            {
                Command    = Command.PLACE,
                Coordinate = new Coordinate(3, 3),
                Facing     = Facing.NORTH
            };
            ICommandInterface placeCommand = new PlaceRobotCommand(cm, tr, tt);

            placeCommand.Execute();

            ICommandInterface moveCommand = new MoveForwardCommand(tr, tt);

            //act
            moveCommand.Execute();
            moveCommand.Execute();


            //assert: actual/expected
            Assert.AreEqual(tr.GetCurrentRobotPosition(), new ToyRobot(new Coordinate(3, 5), Facing.NORTH).GetCurrentRobotPosition());
        }
Exemplo n.º 4
0
        public void TestShouldTurnAndMoveInTheRightDirection()
        {
            var     mf      = new MoveForwardCommand();
            var     tc      = new TurnClockwiseCommand();
            Tractor tractor = new Tractor();

            tc.Execute(tractor);
            mf.Execute(tractor);
            Assert.AreEqual(1, tractor.GetPositionX());
            Assert.AreEqual(0, tractor.GetPositionY());

            tc.Execute(tractor);
            mf.Execute(tractor);
            Assert.AreEqual(1, tractor.GetPositionX());
            Assert.AreEqual(-1, tractor.GetPositionY());

            tc.Execute(tractor);
            mf.Execute(tractor);
            Assert.AreEqual(0, tractor.GetPositionX());
            Assert.AreEqual(-1, tractor.GetPositionY());

            tc.Execute(tractor);
            mf.Execute(tractor);
            Assert.AreEqual(0, tractor.GetPositionX());
            Assert.AreEqual(0, tractor.GetPositionY());
        }
Exemplo n.º 5
0
        public void Move(Orientation testOrientation, int expectedXPosition, int expectedYPosition)
        {
            const int testX        = 2;
            const int testY        = 2;
            var       testPosition = new Position(testX, testY, testOrientation);

            const int testGridSizeX      = 3;
            const int testGridSizeY      = 3;
            var       testTrackingModule = new TrackingModule
            {
                GridMaximumX = testGridSizeX,
                GridMaximumY = testGridSizeY,
                Position     = testPosition
            };

            var spyCommand  = new SpyCommand();
            var moveCommand = new MoveForwardCommand(spyCommand);

            moveCommand.Execute(testTrackingModule);

            var actualTrackingModule = spyCommand.TrackingModule;

            actualTrackingModule.Position.Y.Should().Be(expectedYPosition);
            actualTrackingModule.Position.X.Should().Be(expectedXPosition);
        }
Exemplo n.º 6
0
        public void TestMoveDifferentUnits()
        {
            // Движение
            _moveCommand.Execute();
            _moveCommand.Execute();
            _moveCommand.Execute();

            // Трактор продвинулся
            Assert.AreEqual(0, _tractor.UnitPosition.X);
            Assert.AreEqual(3, _tractor.UnitPosition.Y);

            // Камень стоит на месте
            Assert.AreEqual(0, _stone.UnitPosition.X);
            Assert.AreEqual(0, _stone.UnitPosition.Y);

            // Ветер не поменял направление (положения нет)
            Assert.AreEqual(Orientation.North, _wind.UnitOrientation);
        }
Exemplo n.º 7
0
        public void TestShouldStatic()
        {
            var   mf    = new MoveForwardCommand();
            Stone stone = new Stone(new int[] { 2, 4 });

            mf.Execute(stone);

            Assert.AreEqual(2, stone.GetPositionX());
            Assert.AreEqual(4, stone.GetPositionY());
        }
Exemplo n.º 8
0
        public void TestShouldMoveForward()
        {
            var     mf      = new MoveForwardCommand();
            Tractor tractor = new Tractor();

            mf.Execute(tractor);

            Assert.AreEqual(0, tractor.GetPositionX());
            Assert.AreEqual(1, tractor.GetPositionY());
        }
Exemplo n.º 9
0
        public void South_boundary_reaching_throws_location_out_of_bound_exception()
        {
            var plateau = new Plateau(new Point(0, 0));
            var rover   = new Rover(plateau, new Location(new Point(0, 0), CardinalDirection.South));
            RoboticRoverCommand command = new MoveForwardCommand(rover);

            Action action = () => command.Execute();

            action.Should().ThrowExactly <LocationOutOfBoundException>();
        }
Exemplo n.º 10
0
        public void West_direction_rover()
        {
            var plateau = new Plateau(new Point(5, 5));
            var rover   = new Rover(plateau, new Location(new Point(1, 2), CardinalDirection.West));
            RoboticRoverCommand command = new MoveForwardCommand(rover);

            command.Execute();

            rover.Location.Point.XCoordinate.Should().Be(0);
            rover.Location.Point.YCoordinate.Should().Be(2);
        }
Exemplo n.º 11
0
        public void HoverCommand_ShouldExecuteClientMoveForward()
        {
            // arrange
            moveForwardCommand = new MoveForwardCommand(DroneClientMock.Object);

            // act
            moveForwardCommand.Execute();

            // assert
            DroneClientMock.Verify(x => x.MoveForward(), Times.Once);
        }
Exemplo n.º 12
0
        public void Rover_FacingWest_AtPosition34_5x5Grid_MovesTo24Position()
        {
            Coordinates startPosition    = new Coordinates(3, 4);
            IDirection  currentDirection = new West();
            Grid        grid             = new Grid(new Coordinates(0, 0), new Coordinates(5, 5));
            IRover      rover            = new MarsRover(currentDirection, startPosition, grid);
            ICommand    moveCommand      = new MoveForwardCommand();

            moveCommand.Execute(rover);
            Assert.That(rover.CurrentDirection, Is.TypeOf <West>());
            Assert.That(rover.CurrentPosition.XCoordinate == 2);
            Assert.That(rover.CurrentPosition.YCoordinate == 4);
        }
Exemplo n.º 13
0
        public void Move_TableTopFiveIntoFiveRobotNotPlacedBeforeMove()
        {
            //arrange
            TableTop          tt          = new TableTop(5, 5);
            ToyRobot          tr          = new ToyRobot();
            ICommandInterface moveCommand = new MoveForwardCommand(tr, tt);

            //act
            moveCommand.Execute();

            //assert
            Assert.IsFalse(tr.isRobotPlaced);
        }
Exemplo n.º 14
0
        public void TestShouldMoveForward()
        {
            Tractor tractor = new Tractor(new Field()
            {
                Height = 5, Width = 5
            });
            var moveCommand = new MoveForwardCommand(tractor);

            moveCommand.Execute();

            Assert.AreEqual(0, tractor.UnitPosition.X);
            Assert.AreEqual(1, tractor.UnitPosition.Y);
        }
        public void MoveForwardCommand_Should_Call_Create_Method_When_Expected_Value()
        {
            //Arrange
            var marsRoverService         = new Mock <IMarsRoverService>();
            var directionManagerStrategy = new Mock <IDirectionManagerStrategy>();

            var moveForwardCommand = new MoveForwardCommand(marsRoverService.Object, directionManagerStrategy.Object);

            //Act
            moveForwardCommand.Execute();

            //Assert
            directionManagerStrategy.Verify(mock => mock.MoveForward(It.IsAny <RoverPositionModel>()), Times.Once);
        }
Exemplo n.º 16
0
        public void TestShouldCorrectCommandExec()
        {
            var     mf      = new MoveForwardCommand();
            var     tc      = new TurnClockwiseCommand();
            Tractor tractor = new Tractor();
            Stone   stone   = new Stone(new int[] { 2, 4 });
            Wind    wind    = new Wind();

            mf.Execute(tractor);
            mf.Execute(wind);
            mf.Execute(stone);
            tc.Execute(tractor);
            tc.Execute(wind);
            tc.Execute(stone);

            Assert.AreEqual(0, tractor.GetPositionX());
            Assert.AreEqual(1, tractor.GetPositionY());
            Assert.AreEqual(Orientation.East, tractor.Orientation);

            Assert.AreEqual(Orientation.East, wind.Orientation);

            Assert.AreEqual(2, stone.GetPositionX());
            Assert.AreEqual(4, stone.GetPositionY());
        }
Exemplo n.º 17
0
        public void Move_TableTopFiveIntoFiveRobotIsPlacedBeforeMove()
        {
            //arrange
            TableTop     tt = new TableTop(5, 5);
            ToyRobot     tr = new ToyRobot();
            CommandModel cm = new CommandModel()
            {
                Command    = Command.PLACE,
                Coordinate = new Coordinate(3, 4),
                Facing     = Facing.NORTH
            };
            ICommandInterface placeCommand = new PlaceRobotCommand(cm, tr, tt);

            placeCommand.Execute();

            ICommandInterface moveCommand = new MoveForwardCommand(tr, tt);

            //act
            moveCommand.Execute();

            //assert
            Assert.IsTrue(tr.isRobotPlaced);
        }
Exemplo n.º 18
0
        public void Move_TableTop5Into5Placed2Into3RobotMovedOnceSameFacing()
        {
            //arrange
            TableTop     tt = new TableTop(5, 5);
            ToyRobot     tr = new ToyRobot();
            CommandModel cm = new CommandModel()
            {
                Command    = Command.PLACE,
                Coordinate = new Coordinate(2, 3),
                Facing     = Facing.NORTH
            };
            ICommandInterface placeCommand = new PlaceRobotCommand(cm, tr, tt);

            placeCommand.Execute();

            ICommandInterface moveCommand = new MoveForwardCommand(tr, tt);

            //act
            moveCommand.Execute();

            //assert: actual/expected
            // Assert.AreEqual(tr.GetCurrentRobotPosition(), new ToyRobot(new Coordinate(3, 5), Facing.NORTH).GetCurrentRobotPosition());
            Assert.AreEqual(tr.robotDirection, Facing.NORTH);
        }
Exemplo n.º 19
0
        public void TestShouldThrowExceptionIfFallsOffPlateau()
        {
            var     mf      = new MoveForwardCommand();
            Tractor tractor = new Tractor();

            mf.Execute(tractor);
            mf.Execute(tractor);
            mf.Execute(tractor);
            mf.Execute(tractor);
            mf.Execute(tractor);

            try
            {
                mf.Execute(tractor);
                Assert.Fail("Tractor was expected to fall off the plateau");
            }
            catch (TractorInDitchException ex)
            {
            }
        }
Exemplo n.º 20
0
        public void TestShouldThrowExceptionIfFallsOffPlateau()
        {
            Tractor tractor = new Tractor(new Field()
            {
                Height = 5, Width = 5
            });
            var moveCommand = new MoveForwardCommand(tractor);

            moveCommand.Execute();
            moveCommand.Execute();
            moveCommand.Execute();
            moveCommand.Execute();
            moveCommand.Execute();

            try
            {
                moveCommand.Execute();
                Assert.Fail("Tractor was expected to fall off the plateau");
            }
            catch (TractorInDitchException)
            {
            }
        }