Exemple #1
0
        public void ExecuteCommandSequence_InvalidCommand()
        {
            var rover    = new RoverBuilder().Build();
            var commands = new char[] { 'Z' };

            var result = rover.ExecuteCommandSequence(commands);

            Assert.AreEqual(ResultCode.CommandNotRecognized, result.Result);
        }
Exemple #2
0
        public void TurnRight()
        {
            var rover     = new RoverBuilder().Build();
            var position  = rover.Position;
            var direction = rover.Direction;
            var commands  = new char[] { 'r' };

            var result = rover.ExecuteCommandSequence(commands);

            Assert.AreEqual(ResultCode.CommandExecuted, result.Result);
            Assert.AreEqual(position, rover.Position);
            Assert.AreEqual(direction.TurnRight(), rover.Direction);
        }
Exemple #3
0
        public void MoveBackward()
        {
            var rover     = new RoverBuilder().Build();
            var position  = rover.Position;
            var direction = rover.Direction;
            var commands  = new char[] { 'b' };

            var result = rover.ExecuteCommandSequence(commands);

            Assert.AreEqual(ResultCode.CommandExecuted, result.Result);
            Assert.AreEqual(position.GetBackwardMovementCoordinates(direction), rover.Position);
            Assert.AreEqual(direction, rover.Direction);
        }
Exemple #4
0
        public void KnightMovement_InvalidSequence()
        {
            var rover = new RoverBuilder().LandedIn(1, 1)
                        .DirectedTowards("N")
                        .Build();
            var commands          = new char[] { 'f', 'f', 'Z', 'f' };
            var expectedPosition  = Coordinates.Create(1, 3);
            var expectedDirection = DirectionsList.N;

            var result = rover.ExecuteCommandSequence(commands);

            Assert.AreEqual(ResultCode.CommandNotRecognized, result.Result);
            Assert.AreEqual(expectedPosition, rover.Position);
            Assert.AreEqual(expectedDirection, rover.Direction);
        }
Exemple #5
0
        public void KnightMovement_Reversed()
        {
            var rover = new RoverBuilder().LandedIn(2, 3)
                        .DirectedTowards("E")
                        .Build();
            var commands          = new char[] { 'r', 'r', 'f', 'l', 'f', 'f' };
            var expectedPosition  = Coordinates.Create(1, 1);
            var expectedDirection = DirectionsList.S;

            var result = rover.ExecuteCommandSequence(commands);

            Assert.AreEqual(ResultCode.CommandExecuted, result.Result);
            Assert.AreEqual(expectedPosition, rover.Position);
            Assert.AreEqual(expectedDirection, rover.Direction);
        }
Exemple #6
0
        public void MovementWithObstacleOnThePath()
        {
            var obstacleMap = new Dictionary <int, int>()
            {
                { 99, 3 }
            };

            var rover = new RoverBuilder().LandedIn(1, 1)
                        .DirectedTowards("N")
                        .WithObstacleDetectionSystem(obstacleMap)
                        .Build();
            var commands          = new char[] { 'f', 'f', 'r', 'b', 'b' };
            var expectedPosition  = Coordinates.Create(0, 3);
            var expectedDirection = DirectionsList.E;

            var result = rover.ExecuteCommandSequence(commands);

            Assert.AreEqual(ResultCode.ObstacleFound, result.Result);
            Assert.AreEqual(expectedPosition, rover.Position);
            Assert.AreEqual(expectedDirection, rover.Direction);
        }