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);
        }
示例#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);
        }
        public void Coordinate_x_0_y_0_should_be_valid()
        {
            var validator = new SurfaceCoordinateValidator();
            var pos       = new SurfaceCoordinate()
            {
                X_Position = 0, Y_Position = 0
            };
            var actual = validator.Validate(pos);

            Assert.AreEqual <bool>(true, actual);
        }
        public void Report_console_display_should_report_successfully()
        {
            var reportDisplay = new ReportConsoleDisplay();
            var surfaceCoordinateValidator = new SurfaceCoordinateValidator();
            SurfaceCoordinate coordinate   = new SurfaceCoordinate()
            {
                X_Position = 0, Y_Position = 1
            };
            var pos   = new RobotPosition(Direction.NORTH, coordinate);
            var robot = new Robot(0, "test", surfaceCoordinateValidator);

            robot.UpdatePosition(pos);
            reportDisplay.ShowRobot(robot);
        }
        public void Place_command_throw_arguent_exception_for_incorrect_command_param()
        {
            var originalPos = new SurfaceCoordinate {
                X_Position = 0, Y_Position = 0
            };
            var robotPosition = new RobotPosition(Direction.SOUTH, originalPos);
            var validator     = new SurfaceCoordinateValidator();
            var param         = new MoveCommandParam();
            var cmd           = new PlaceCommand(param, validator);

            RobotPosition actualPosition = null;

            //var actual = cmd.GetCommandResult(out actualPosition);
            Assert.ThrowsException <ArgumentException>(() => cmd.GetCommandResult(null, out actualPosition));
        }
示例#6
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 Place_command_should_not_move_robot_in_0_0_South_to_anywhere()
        {
            var originalPos = new SurfaceCoordinate {
                X_Position = 0, Y_Position = 5
            };
            RobotPosition robotPosition = null;
            var           validator     = new SurfaceCoordinateValidator();
            var           param         = new PlaceCommandParam(Direction.NORTH, originalPos);
            var           cmd           = new PlaceCommand(param, validator);

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

            Assert.AreEqual <bool>(false, actual);
            Assert.AreEqual <RobotPosition>(null, actualPosition);
        }
示例#8
0
        public void Report_command_should_report_robot_position()
        {
            var originalPos = new SurfaceCoordinate {
                X_Position = 0, Y_Position = 0
            };
            var robotPosition = new RobotPosition(Direction.EAST, originalPos);
            var surfaceCoordinateValidator = new SurfaceCoordinateValidator();
            var robot = new Robot(0, "test", surfaceCoordinateValidator);

            robot.UpdatePosition(robotPosition);
            var param         = new ReportCommandParam();
            var reportDisplay = new ReportConsoleDisplay();
            var cmd           = new ReportCommand(param, reportDisplay);

            cmd.Display(robot);
        }
        public void Place_command_should_palce_robot_in_0_0_North()
        {
            var originalPos = new SurfaceCoordinate {
                X_Position = 0, Y_Position = 0
            };
            var validator = new SurfaceCoordinateValidator();
            var param     = new PlaceCommandParam(Direction.NORTH, originalPos);

            var cmd = new PlaceCommand(param, validator);

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

            Assert.AreEqual <bool>(true, actual);
            Assert.AreEqual <Direction>(Direction.NORTH, actualPosition.Direction);
            Assert.AreEqual <SurfaceCoordinate>(expectedCoordinate, actualPosition.Coordinate);
        }
        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);
        }