예제 #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);
        }
예제 #2
0
        private Position LoadPosition(Position position)
        {
            switch (position.Direction)
            {
                case Direction.N:
                    position.Y = position.Y - 1;
                    break;
                case Direction.S:
                    position.Y = position.Y + 1;
                    break;
                case Direction.E:
                    position.X = position.X - 1;
                    break;
                case Direction.W:
                    position.X = position.X + 1;
                    break;
            }

            return position;
        }
예제 #3
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;
        }