public void Movement_Service_Start_With_Initialize_Should_Return_Correct_Result2() { var moveAreaMock = new Mock <IMoveArea <int> >(); moveAreaMock.SetupGet(s => s.Width).Returns(10); moveAreaMock.SetupGet(s => s.Height).Returns(10); var robo = new Robo <int, int>(moveAreaMock.Object); var service = new MovementService <int, int>(robo); robo.Step = 1; service.Initialize("PLACE 1,2,EAST"); service.ProcessCommand("MOVE"); service.ProcessCommand("MOVE"); service.ProcessCommand("LEFT"); service.ProcessCommand("MOVE"); var expectedDirection = DirectionFactory <int, int> .Create("NORTH"); robo.Direction.GetType().Should().BeSameAs(expectedDirection.GetType()); robo.Position.X.Should().Be(3); robo.Position.Y.Should().Be(3); service.ProcessCommand("MOVE"); robo.Position.X.Should().Be(3); robo.Position.Y.Should().Be(4); }
public void getDirectionByInt() { DirectionFactory myFactory = new DirectionFactory(); Assert.AreEqual(Direction.CW, DirectionFactory.getDirectionByInt(0)); Assert.AreEqual(Direction.CCW, DirectionFactory.getDirectionByInt(1)); }
public void PositionToStringFormat(int xCoordinate, int yCoordinate, char faceDirection, string expected) { CompassDirection?direction = new DirectionFactory().Get(faceDirection); IPosition position = new Position(xCoordinate, yCoordinate, direction); Assert.AreEqual(expected, position.ToString()); }
public void ReturnDirectionAccordingly(char directionInfo, Type expectedType) { var result = DirectionFactory.GetDirection(directionInfo); Assert.NotNull(result); Assert.Equal(expectedType, result.GetType()); }
public void Move(string input) { foreach (var move in input) { _position = DirectionFactory.GetInstance(_position.FaceDirection).Move(_position, move); } }
public void Right() { if (IsPlaced) { directionCalculator = DirectionFactory.GetDirectionCalculator(facingDirection); facingDirection = directionCalculator.TurnRight(); } }
public void Move() { if (IsPlaced) { directionCalculator = DirectionFactory.GetDirectionCalculator(facingDirection); coordinates = directionCalculator.GoForward(coordinates); } }
public void ThrowInvalidDirectionExceptionWhenDirectionInfoIsInvalid() { char directionInfo = 'X'; var result = Record.Exception(() => DirectionFactory.GetDirection(directionInfo)); Assert.NotNull(result); Assert.IsType <InvalidDirectionException>(result); }
public void ThrowOutOfPlateauExceptionWhenMoveToNewCoordinatesExceedsBorders() { DirectionClass direction = DirectionFactory.GetDirection('S'); var result = Record.Exception(() => borderStrategy.MoveToNewCoordinates(coordinates, direction)); Assert.NotNull(result); Assert.IsType <OutOfPlateauException>(result); }
public static Rover CreateRover(string initialState) { var states = initialState.Split(":"); var x = int.Parse(states[0]); var y = int.Parse(states[1]); var position = new Position(x, y); var directionAsString = states[2]; var direction = DirectionFactory.CreateDirection(directionAsString); return(new Rover(position, direction)); }
public void RotateLeft(int xCoordinate, int yCoordinate, char direction, string expected) { CompassDirection?compassDirection = new DirectionFactory().Get(direction); IPosition robotStartPosition = new Position(xCoordinate, yCoordinate, compassDirection); IRobotController robotController = new RobotController(robotStartPosition, pluto); IRotate robotCommand = new RotateLeft(); IPosition robotEndPosition = robotController.Move(robotCommand); Assert.AreEqual(expected, robotEndPosition.ToString()); }
public void ReverseByOne(int startingXCoordinate, int startingYCoordinate, char direction, string expected) { CompassDirection?compassDirection = new DirectionFactory().Get(direction); IPosition robotStartPosition = new Position(startingXCoordinate, startingYCoordinate, compassDirection); ICommand robotCommand = new Reverse(); IRobotController robotController = new RobotController(robotStartPosition, pluto); IPosition robotEndPosition = robotController.Move(robotCommand); Assert.AreEqual(expected, robotEndPosition.ToString()); }
public void FollowEachCommandInCommandQueue(int startXcoordinate, int startYCoordiate, char startFacingDirectionFirstLetter, string queueOfCommands, string expectedEndPosition) { CompassDirection?startFacingDirection = new DirectionFactory().Get(startFacingDirectionFirstLetter); IPosition startPosition = new Position(startXcoordinate, startYCoordiate, startFacingDirection); IRobotController controller = new RobotController(startPosition, pluto); IRobotQueueCommandRunner queueOfCommandsRunner = new RobotQueueCommandRunner(controller); IEnumerable <IPosition> robotPath = queueOfCommandsRunner.Run(queueOfCommands); Assert.AreEqual(expectedEndPosition, robotPath.LastOrDefault().ToString()); }
public void Action_Compute_Cordinate_Should_Return_Same_Cordinate(string currentDirection, string command, string expectedDirection) { var currDirection = DirectionFactory <int, int> .Create(currentDirection); var action = ActionFactory <int, int> .Create(command); var expectDirection = DirectionFactory <int, int> .Create(expectedDirection); var result = currDirection.NextFacing(action); result.GetType().Should().BeSameAs(expectDirection.GetType()); }
public void MoveToCoordinatesWhenMoveToNewCoordinatesStaysInBorders() { DirectionClass direction = DirectionFactory.GetDirection('N'); var result = borderStrategy.MoveToNewCoordinates(coordinates, direction); int expectedCoordX = 0; int expectedCoordY = 1; Assert.NotNull(result); Assert.Equal(expectedCoordX, result.coordX); Assert.Equal(expectedCoordY, result.coordY); }
public static Particle GenerateParticle(Emitter e, Texture2D texture, params Color[] c) { var ttl = TimeSpan.FromMilliseconds(BaseGame.Random.Next(3000, 7000)); var cl = new List <Color>(c); if (cl.Count == 0) { cl.Add(new Color((float)BaseGame.Random.NextDouble(), (float)BaseGame.Random.NextDouble(), (float)BaseGame.Random.NextDouble())); } return(new Particle(texture, e.EmissionPoint, DirectionFactory.RandomDirection(1f), 0.25f, 0.1f * (float)(BaseGame.Random.NextDouble() * 2 - 1), Color.White, 1, 1, ttl, new FountainModifier(0.001f), new ColorFader(ttl, 1f, 0f), new ColorRotator(ttl, cl.ToArray()), new ColorSparkler())); }
public void WaitAtTheBorderWhenMoveToNewCoordinatesExceedsBorders() { DirectionClass direction = DirectionFactory.GetDirection('S'); var result = borderStrategy.MoveToNewCoordinates(coordinates, direction); int expectedCoordX = 0; int expectedCoordY = 0; Assert.NotNull(result); Assert.Equal(expectedCoordX, result.coordX); Assert.Equal(expectedCoordY, result.coordY); }
public Robot Parse(string inputString) { Match match = regex.Match(inputString); if (!match.Success) { throw new ArgumentException("The robot position should be '<X> <Y> <direction>' (ex: '1 2 N')"); } Robot initRobot = new Robot(generateId(), new Coordinate(int.Parse(match.Groups["x"].Value), int.Parse(match.Groups["y"].Value)), DirectionFactory.Create(match.Groups["direction"].Value), getArena(), true); return(initRobot); }
public void ForwardByOne(int startingXCoordinate, int startingYCoordinate, char direction, string expected) { CompassDirection?compassDirection = new DirectionFactory().Get(direction); IPosition robotStartPosition = new Position(startingXCoordinate, startingYCoordinate, compassDirection); ICommand robotCommand = new Forward(); IRobotController robotController = new RobotController(robotStartPosition); IPosition robotEndPosition = robotController.Move(robotCommand); Assert.That(robotEndPosition.ToString(), Is.EqualTo(expected)); }
public void Movement_Service_Initialize_Should_Initialize_Correctly(string command, int x, int y, string direction) { var moveAreaMock = new Mock <IMoveArea <int> >(); moveAreaMock.SetupGet(s => s.Width).Returns(10); moveAreaMock.SetupGet(s => s.Height).Returns(10); var robo = new Robo <int, int>(moveAreaMock.Object); var service = new MovementService <int, int>(robo); var expectedDirection = DirectionFactory <int, int> .Create(direction); service.Initialize(command); robo.Direction.GetType().Should().BeSameAs(expectedDirection.GetType()); robo.Position.X.Should().Be(x); robo.Position.Y.Should().Be(y); }
/// <summary> /// Returns new instance of a Rover object /// </summary> /// <param name="coordX">Rover's starting coordinate on the X axis</param> /// <param name="coordY">Rover's starting coordinate on the Y axis</param> /// <param name="directionInfo">Rover's facing direction</param> /// <param name="chosenBorderStrategy">Chosen BorderStrategy for the Rover</param> /// <returns>New instance of a Rover object</returns> public static Rover GetNewRover(int coordX, int coordY, char directionInfo, BorderStrategy chosenBorderStrategy) { if (coordX < chosenBorderStrategy.lowerBoundryBorderCoordinates.coordX || coordY < chosenBorderStrategy.lowerBoundryBorderCoordinates.coordY || coordX > chosenBorderStrategy.upperBoundryBorderCoordinates.coordX || coordY > chosenBorderStrategy.upperBoundryBorderCoordinates.coordY) { throw new OutOfPlateauException(); } Rover NewRover = new Rover { currentDirection = DirectionFactory.GetDirection(directionInfo), chosenBorderStrategy = chosenBorderStrategy, currentCoordinates = new Coordinates(coordX, coordY) }; return(NewRover); }
public void Robo_Process_Action_Should_Return_Correct_Result(string command, int x, int y, string direction) { var moveAreaMock = new Mock <IMoveArea <int> >(); moveAreaMock.SetupGet(s => s.Width).Returns(10); moveAreaMock.SetupGet(s => s.Height).Returns(10); var robo = new Robo <int, int>(moveAreaMock.Object); robo.ProcessAction(command); var expetedDirection = DirectionFactory <int, int> .Create(direction); robo.Direction.GetType().Should().BeSameAs(expetedDirection.GetType()); robo.Position.X.Should().Be(x); robo.Position.Y.Should().Be(y); }
public void MovePlayer(Direction direction) { Tuple <int, int> currentPlayerLocation = this.GetElementLocation(_player.Host); MoveResult moveResult = DirectionFactory.GetNextLocation(currentPlayerLocation, direction, _mapSize); if (moveResult.IsValid) { _player.Visit(_gameElements[moveResult.FutureLocation.Item1, moveResult.FutureLocation.Item2]); } else { Console.WriteLine($"Invalid move: {direction}"); } }
private void ProcessInitialPlacement(string command) { var commandSegments = RoboHelper.GetCommandSegments(command); //this will throw exception if the commads are invalid //This is done this way so that the detail error messages are captured for ease of user RoboHelper.IsCommandLineArgumentsValid(commandSegments); //Check if the original cordinate is valid RoboHelper.IsCordinateValid <T>(commandSegments, MoveArea); //set the initial position Position = new Cordinate <T> { X = (T)Convert.ChangeType(commandSegments.X, typeof(T)), Y = (T)Convert.ChangeType(commandSegments.Y, typeof(T)) }; //set the initial direction Direction = DirectionFactory <T, U> .Create(commandSegments.Direction); }
public void Horizontal_East_Move_Action_Compute_Cordinate_Should_Return_Correct_New_Cordinate(string command, string directi, int x, int y, int exX, int exY, int step) { var moveAreaMock = new Mock <IMoveArea <int> >(); moveAreaMock.SetupGet(s => s.Width).Returns(10); moveAreaMock.SetupGet(s => s.Height).Returns(10); var direction = DirectionFactory <int, int> .Create(directi); var action = ActionFactory <int, int> .Create(command); var cordinate = new Cordinate <int> { X = x, Y = y }; var result = action.ComputeNewCordinate(cordinate, step, moveAreaMock.Object, direction); result.X.Should().Be(exX); result.Y.Should().Be(exY); }
public void Direction_Factory_Should_Throw_ArgumentException_Exception(string command, string exceptionMessage) { Action act = () => DirectionFactory <int, int> .Create(command); act.Should().Throw <ArgumentException>().WithMessage(exceptionMessage); }
public void Direction_Factory_Should_Create_Correct_Direction_Object(string command, Type type) { var direction = DirectionFactory <int, int> .Create(command); direction.Should().BeOfType(type); }
public void Create_should_create_the_right_Direction(string direction, Type expectedType) { DirectionFactory.Create(direction).GetType() .Should().Be.EqualTo(expectedType); }
public void Create_should_throw_ArgumentException_when_directions_is_unknown() { Assert.Throws <ArgumentException>(() => DirectionFactory.Create("k")); }
public string ProcessAction(string command) { var commandSegments = RoboHelper.GetCommandSegments(command); //check if (commandSegments != null) { //this will throw exception if the commads are invalid //This is done this way so that the detail error messages are captured for ease of user RoboHelper.IsCommandLineArgumentsValid(commandSegments); //Check if the original cordinate is valid RoboHelper.IsCordinateValid <T>(commandSegments, MoveArea); //set the new position Position = new Cordinate <T> { X = (T)Convert.ChangeType(commandSegments.X, typeof(T)), Y = (T)Convert.ChangeType(commandSegments.Y, typeof(T)) }; //set the new direction Direction = DirectionFactory <T, U> .Create(commandSegments.Direction); } else { if (RoboHelper.IsValidReportAction(command)) { return(new Report <T, U>().GetOutput(Position, Direction)); } if (RoboHelper.IsPlaceExist(new string[] { command })) { throw new ArgumentException($"PLACE command missing arguments"); } if (!RoboHelper.IsValidMoveAction(command)) { throw new ArgumentException($"Invalid command line arguments"); } if (Direction == null) { throw new InvalidOperationException("Robo unable to perform this command without initial direction"); } if (Position == null) { throw new InvalidOperationException("Robo unable to perform this command without initial position"); } //create the action var action = ActionFactory <T, U> .Create(command); //get the new direction Direction = Direction.NextFacing(action); //calculate the new position Position = action.ComputeNewCordinate(Position, Step, MoveArea, Direction); } return(string.Empty); }