Esempio n. 1
0
        public void When_rover_is_set_to_move_to_single_direction_test(int x, int y, Direction direction, Command command,
                int expectedX, int expectedY, Direction expectedDirection)
        {
            // act
            var currentPosition = new Position
            {
                X = x,
                Y = y,
                Direction = direction
            };

            var rover = new Rover
            {
                Position = currentPosition,
                Command = command
            };

            _mockIRoverManager.Setup(m => m.Move(rover)).Returns(new Position
            {
                X = expectedX,
                Y = expectedY,
                Direction = expectedDirection
            });

            // actual
            var actual = _mockIRoverManager.Object.Move(rover);

            // assert
            Assert.AreEqual(expectedX, actual.X);
            Assert.AreEqual(expectedY, actual.Y);
            Assert.AreEqual(expectedDirection, actual.Direction);
        }
Esempio n. 2
0
        public Position ExecuteCommand(Rover rover)
        {
            if (rover == null)
            {
                throw new NullReferenceException("Rover cannot be null");
            }

            return LoadPosition(rover.Position);
        }
Esempio n. 3
0
        public Position ExecuteCommand(Rover rover)
        {
            if (rover == null)
            {
                throw new NullReferenceException("Rover cannot be null");
            }

            return new Position
            {
                X = rover.Position.X,
                Y = rover.Position.Y,
                Direction = GetDirection(rover.Position.Direction)
            };
        }
Esempio n. 4
0
        public void When_command_is_backward_and_direction_south_decrease_by_one_test()
        {
            // act
            var commandR = new CommandB();
            var rover = new Rover
            {
                Command = Command.B,
                Position = new Position
                {
                    Direction = Direction.S,
                    X = 0,
                    Y = 0
                }
            };

            // actual
            rover.Position = commandR.ExecuteCommand(rover);

            // assert
            Assert.AreEqual(1, rover.Position.Y);
        }
Esempio n. 5
0
        public Position ExecuteCommands(Position position, string commands)
        {
            try
            {
                char[] cmds = commands.ToCharArray();

                foreach (char command in cmds)
                {
                    var rover = new Rover
                    {
                        Position = position,
                        Command = (Command)Enum.Parse(typeof(Command), command.ToString().ToUpper())
                    };

                    position = _roverManager.Move(rover);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("failed to execute command: " + commands, ex);
            }

            return position;
        }
Esempio n. 6
0
        public void When_command_is_right_rotate_90_degrees_test()
        {
            // act
            var commandR = new CommandR();
            var rover = new Rover
            {
                Command = Command.R,
                Position = new Position
                {
                    Direction = Direction.N,
                    X = 0,
                    Y = 0
                }
            };

            // actual and Assert
            rover.Position = commandR.ExecuteCommand(rover);
            Assert.AreEqual(Direction.E, rover.Position.Direction);

            rover.Position = commandR.ExecuteCommand(rover);
            Assert.AreEqual(Direction.S, rover.Position.Direction);

            rover.Position = commandR.ExecuteCommand(rover);
            Assert.AreEqual(Direction.W, rover.Position.Direction);

            rover.Position = commandR.ExecuteCommand(rover);
            Assert.AreEqual(Direction.N, rover.Position.Direction);
        }
Esempio n. 7
0
        public void When_command_is_forward_and_direction_west_decrease_by_one_test()
        {
            // act
            var commandR = new CommandF();
            var rover = new Rover
            {
                Command = Command.F,
                Position = new Position
                {
                    Direction = Direction.W,
                    X = 0,
                    Y = 0
                }
            };

            // actual
            rover.Position = commandR.ExecuteCommand(rover);

            // assert
            Assert.AreEqual(-1, rover.Position.X);
        }
Esempio n. 8
0
        public void When_command_is_forward_and_direction_north_increase_by_one_test()
        {
            // act
            var commandR = new CommandF();
            var rover = new Rover
            {
                Command = Command.F,
                Position = new Position
                {
                    Direction = Direction.N,
                    X = 0,
                    Y = 0
                }
            };

            // actual and Assert
            rover.Position = commandR.ExecuteCommand(rover);
            Assert.AreEqual(1, rover.Position.Y);

            rover.Position = commandR.ExecuteCommand(rover);
            Assert.AreEqual(2, rover.Position.Y);
        }
Esempio n. 9
0
        public Position Move(Rover rover)
        {
            _commandExecute = _commandFactory.GetCommandHandler(rover.Command.ToString());

            return _commandExecute.ExecuteCommand(rover);
        }