Exemplo n.º 1
0
        public void CreateAction_GivenValidCommandCandidate_ReturnsType(string candidate, Type expectedType)
        {
            var commandParser = new CommandParser(candidate);
            var strategy      = commandParser.CreateAction();

            Assert.That(strategy.GetType(), Is.EqualTo(expectedType));
        }
        public bool TryExecuteCommand(Rover rover, string instruction)
        {
            var commandParser = new CommandParser(instruction);
            var action        = commandParser.CreateAction();

            rover.SetAction(action);
            return(rover.TryMove());
        }
Exemplo n.º 3
0
        public void Translate_GivenCommandCandidate_ChangesPositionTo(
            string candidate, CardinalDirection startFacing, int endX, int endY)
        {
            var startingPosition = new Position(1, 0, startFacing, new Grid());
            var translateCommand = new CommandParser(candidate);
            var translation      = translateCommand.CreateAction();
            var endingPosition   = translation.Act(startingPosition);

            Assert.That(endingPosition.Coordinates, Is.EqualTo(new int[] { endX, endY }));
        }
Exemplo n.º 4
0
        public void Rotate_GivenCommandCandidate_ChangesOrientationTo(
            string candidate, CardinalDirection startFacing, CardinalDirection endFacing)
        {
            var startingPosition = new Position(0, 0, startFacing, new Grid());
            var rotateCommand    = new CommandParser(candidate);
            var rotation         = rotateCommand.CreateAction();
            var endingPosition   = rotation.Act(startingPosition);

            Assert.That(endingPosition.Orientation, Is.EqualTo(endFacing));
        }
Exemplo n.º 5
0
        public void CreateAction_GivenValidCommandCandidate_ThrowsException(string candidate, string exceptionMessage)
        {
            var commandParser = new CommandParser(candidate);

            Assert.Throws <ArgumentException>(() => { commandParser.CreateAction(); }, exceptionMessage);
        }