public void DirectionFinder_GivenMoveRightCommand_WhenCurrentlyFacingNorth_ReturnsE() { var expected = 'E'; var actual = DirectionFinder.CalculateDirection('N', 'R'); Assert.AreEqual(expected, actual); }
private Tuple <int[, ], char, bool, int[, ]> Move(char[] commands, IPosition mapBoundary, IList <IPosition> obstacles) { Tuple <int[, ], char, bool, int[, ]> result = null; foreach (char command in commands) { int[,] coordinates = new int[, ] { { Position.XCoordinate, Position.YCoordinate } }; char direction = Position.CardinalDirection; if (command == 'F' || command == 'B') //move forward or backward { result = CalculateXYCoordinates(coordinates[0, 0], coordinates[0, 1], direction, command, mapBoundary.XCoordinate, mapBoundary.YCoordinate, obstacles); } else if (command == 'L' || command == 'R') //change direction { result = new Tuple <int[, ], char, bool, int[, ]>(coordinates, DirectionFinder.CalculateDirection(direction, command), false, null); } Position.XCoordinate = result.Item1[0, 0]; Position.YCoordinate = result.Item1[0, 1]; Position.CardinalDirection = result.Item2; if (result.Item3) //if hit an obstacle progress no further { break; } } return(result); }