Example #1
0
 public void Test_ValidRoverPosition()
 {
     position = new Coords(0, 0);
     rover    = new Rover(plateau, position, CardinalDirection.North);
     rover.SetPosition(5, 5, CardinalDirection.East);
     Assert.IsTrue(rover.GetPosition().X == 5, "X must be 5");
     Assert.IsTrue(rover.GetPosition().Y == 5, "Y must be 5");
     Assert.IsTrue(rover.GetDirection() == CardinalDirection.East, "Direction must be E");
 }
        public void Test_Movement_FoundObstacle_Forward()
        {
            plateau.AddObstacle(new Coords(0, 4));
            plateau.AddObstacle(new Coords(1, 4));

            rover = new Rover(plateau, position, CardinalDirection.North);
            try
            {
                rover.RunCommands("FFFF");
            }catch (RoverObstacleException ex)
            {
                Assert.IsTrue(ex.Message == "Found obstacle at position 0 4", "Expected Message Found obstacle at position 0 4");
            }

            Assert.IsTrue(rover.GetPosition().X == 0, "X must be 0");
            Assert.IsTrue(rover.GetPosition().Y == 3, "X must be 3");
        }
Example #3
0
        public void GetPosition_Should_Return_Rovers_Position()
        {
            //arrange
            var rover = new Rover(1, 2, _plateau);

            //act
            //assert
            Assert.Equal(new Vector2(1, 2), rover.GetPosition());
        }
Example #4
0
        public void UpdatePosition_Should_Update_Rovers_Position()
        {
            //arrange
            var rover = new Rover(1, 2, _plateau);

            rover.UpdatePosition(new Vector2(2, 3));
            //act
            //assert
            Assert.Equal(new Vector2(2, 3), rover.GetPosition());
        }
Example #5
0
        public void SetPosition_ValidPositionLetter_GetPosition()
        {
            var plateau            = new Plateau("5 5");
            var mockCommandFactory = new Mock <ICommandFactory>();

            var rover = new Rover(plateau, mockCommandFactory.Object);

            rover.SetPosition(new SetPositionDTO {
                PositionLetter = "1 1 N"
            });
            Assert.Equal("1 1 N", rover.GetPosition());
        }
Example #6
0
        public void Execute_For_MoveTowards_Should_Update_RoverPosition()
        {
            //arrange
            var rover = new Rover(1, 2, new Plateau(5, 5));

            rover.UpdateOrientation(new NOrientation());
            var instruction = new MoveTowardsInstruction();

            //act
            instruction.Execute(rover);
            //assert
            Assert.Equal(new Vector2(1, 3), rover.GetPosition());
        }
Example #7
0
        public void TurnLeft_RoverOrientationWest_BeSouth()
        {
            var plateau            = new Plateau("5 5");
            var mockCommandFactory = new Mock <ICommandFactory>();

            var rover = new Rover(plateau, mockCommandFactory.Object);

            mockCommandFactory.Setup(a => a.GetCommand(It.IsAny <char>())).Returns(new LeftCommand());
            rover.SetPosition(new SetPositionDTO {
                PositionLetter = "1 1 W"
            });
            rover.TurnLeft();

            Assert.Equal("1 1 S", rover.GetPosition());
        }
Example #8
0
        public void RunCommandList_ValidCommandLetters_BeNewPosition()
        {
            var plateau = new Plateau("5 5");

            var rover = new Rover(plateau, new CommandFactory());

            rover.SetPosition(new SetPositionDTO {
                PositionLetter = "1 1 W"
            });
            rover.RunCommandList(new RunCommandListDTO {
                CommandLetters = "LMR"
            });

            Assert.Equal("1 0 W", rover.GetPosition());
        }
Example #9
0
        public void MoveForward_RoverOrientationWest_DecreaseX()
        {
            var plateau            = new Plateau("5 5");
            var mockCommandFactory = new Mock <ICommandFactory>();

            mockCommandFactory.Setup(a => a.GetCommand(It.IsAny <char>())).Returns(new MoveCommand());

            var rover = new Rover(plateau, mockCommandFactory.Object);

            rover.SetPosition(new SetPositionDTO {
                PositionLetter = "1 1 W"
            });
            rover.MoveForward();

            Assert.Equal("0 1 W", rover.GetPosition());
        }
Example #10
0
        public void TurnRight_RoverOrientationNorth_BeEast()
        {
            var plateau            = new Plateau("5 5");
            var mockCommandFactory = new Mock <ICommandFactory>();

            mockCommandFactory.Setup(a => a.GetCommand(It.IsAny <char>())).Returns(new RightCommand());

            var rover = new Rover(plateau, mockCommandFactory.Object);

            rover.SetPosition(new SetPositionDTO {
                PositionLetter = "1 1 N"
            });
            rover.TurnRight();

            Assert.Equal("1 1 E", rover.GetPosition());
        }
Example #11
0
        public void Test_TurnRight_One_Once()
        {
            rover.RunCommands("R");
            Coords            coords    = rover.GetPosition();
            CardinalDirection direction = rover.GetDirection();

            Assert.IsTrue(coords.X == position.X && coords.Y == position.Y, "Position must be 0,0");
            Assert.IsTrue(direction == CardinalDirection.East, "Direction must be E");
        }