public void Command_Manager_should_return_place_command_when_place_0_1_north_is_given()
        {
            var          coordinateValidator = new SurfaceCoordinateValidator();
            var          directionValidator  = new DirectionValidator();
            var          paramValidator      = new CommandParamValidator(coordinateValidator, directionValidator);
            var          mgr = new CommandManager(paramValidator, null);
            PlaceCommand cmd = (PlaceCommand)mgr.ChooseCommand("PLACE 0,1 NORTH");

            var coordinate = new SurfaceCoordinate {
                X_Position = 0, Y_Position = 1
            };

            PlaceCommandParam actualParam = (PlaceCommandParam)cmd.CommandParam;

            Assert.AreEqual <CommandType>(CommandType.PLACE, actualParam.CommandParamType);
            Assert.AreEqual <Direction>(Direction.NORTH, actualParam.Direction);
            Assert.AreEqual <SurfaceCoordinate>(coordinate, actualParam.SurfaceCoordinate);

            RobotPosition actualPosition = null;
            var           actual         = cmd.GetCommandResult(null, out actualPosition);

            Assert.AreEqual <bool>(true, actual);

            Assert.AreEqual <Direction>(Direction.NORTH, actualPosition.Direction);
            Assert.AreEqual <SurfaceCoordinate>(coordinate, actualPosition.Coordinate);
        }
Example #2
0
        public void Command_Param_Validator_should_not_return_place_command_param_for_input_PLACE_0_dot_5_EAST()
        {
            var coordinateValidator   = new SurfaceCoordinateValidator();
            var directionValidator    = new DirectionValidator();
            var commandParamValidator = new CommandParamValidator(coordinateValidator, directionValidator);
            var result = commandParamValidator.ValidateCommand("PLACE 0.5 EAST");

            Assert.AreEqual <ICommandParam>(null, result);
        }
Example #3
0
        public void Command_Param_Validator_should_return_place_command_param_for_input_PLACE_0_1_EAST()
        {
            var coordinateValidator   = new SurfaceCoordinateValidator();
            var directionValidator    = new DirectionValidator();
            var commandParamValidator = new CommandParamValidator(coordinateValidator, directionValidator);
            var result = (PlaceCommandParam)commandParamValidator.ValidateCommand("PLACE 0,1 EAST");

            var expectedCoordniate = new SurfaceCoordinate {
                X_Position = 0, Y_Position = 1
            };

            Assert.AreEqual <CommandType>(CommandType.PLACE, result.CommandParamType);
            Assert.AreEqual <Direction>(Direction.EAST, result.Direction);
            Assert.AreEqual <int>(expectedCoordniate.X_Position, result.SurfaceCoordinate.X_Position);
            Assert.AreEqual <int>(expectedCoordniate.Y_Position, result.SurfaceCoordinate.Y_Position);
        }
        public void Command_Manager_should_return_move_command_when_move_is_given()
        {
            var coordinateValidator = new SurfaceCoordinateValidator();
            var directionValidator  = new DirectionValidator();
            var paramValidator      = new CommandParamValidator(coordinateValidator, directionValidator);

            var originalPos = new SurfaceCoordinate {
                X_Position = 0, Y_Position = 0
            };
            var robotPosition = new RobotPosition(Direction.EAST, originalPos);

            var mgr = new CommandManager(paramValidator, null);

            var cmd = (MoveCommand)mgr.ChooseCommand("MOVE");

            RobotPosition actualPosition     = null;
            var           actual             = cmd.GetCommandResult(robotPosition, out actualPosition);
            var           expectedCoordinate = new SurfaceCoordinate {
                X_Position = 1, Y_Position = 0
            };

            Assert.AreEqual <Direction>(Direction.EAST, actualPosition.Direction);
            Assert.AreEqual <SurfaceCoordinate>(expectedCoordinate, actualPosition.Coordinate);
        }