Exemplo n.º 1
0
        private string ExecuteInstructions(IRover rover, IEnumerable <char> instructions, Point maximumMapCoordinate, Dictionary <string, string> lostCommands)
        {
            foreach (var instruction in instructions)
            {
                var newLocation = rover.ExecuteInstruction(instruction);

                if (lostCommands.ContainsKey(rover.CurrentLocation.Description) && lostCommands[rover.CurrentLocation.Description] == newLocation.Description)
                {
                    continue;
                }

                if (IsLost(newLocation, maximumMapCoordinate))
                {
                    lostCommands[rover.CurrentLocation.Description] = newLocation.Description;
                    return(GetResult(rover.CurrentLocation, true));
                }

                rover.CurrentLocation = newLocation;
            }

            return(GetResult(rover.CurrentLocation, false));
        }
Exemplo n.º 2
0
        public void RoverExecutesInstruction()
        {
            rover.CurrentLocation = new Location(9266, 90210, ORIENTATION.EAST);

            var movedLocation = new Location(42, 600, ORIENTATION.SOUTH);
            var mockMotor     = new Mock <IMotor>();

            mockMotor.Setup(m => m.Move(rover.CurrentLocation)).Returns(movedLocation);
            mockMotorFactory.Setup(f => f.Construct('k')).Returns(mockMotor.Object);

            var newLocation = rover.ExecuteInstruction('k');

            Assert.That(newLocation, Is.EqualTo(movedLocation));
            Assert.That(rover.CurrentLocation, Is.Not.EqualTo(movedLocation));

            Assert.That(newLocation.Coordinate.X, Is.EqualTo(42));
            Assert.That(newLocation.Coordinate.Y, Is.EqualTo(600));
            Assert.That(newLocation.Orientation, Is.EqualTo(ORIENTATION.SOUTH));

            Assert.That(rover.CurrentLocation.Coordinate.X, Is.EqualTo(9266));
            Assert.That(rover.CurrentLocation.Coordinate.Y, Is.EqualTo(90210));
            Assert.That(rover.CurrentLocation.Orientation, Is.EqualTo(ORIENTATION.EAST));
        }