コード例 #1
0
 public PositionCreateHandler(GlobalSolusindoDb db, tblM_User user, PositionValidator positionValidator, PositionFactory positionFactory, PositionQuery positionQuery, AccessControl accessControl) : base(db, user)
 {
     this.positionValidator         = positionValidator;
     this.positionFactory           = positionFactory;
     this.positionQuery             = positionQuery;
     this.positionEntryDataProvider = new PositionEntryDataProvider(db, user, accessControl, positionQuery);
 }
コード例 #2
0
 public DesignationType(string name, PositionValidator validator, string job, string spriteName)
 {
     NAME        = name;
     VALIDATOR   = validator;
     JOB         = job;
     SPRITE_NAME = spriteName;
 }
コード例 #3
0
        public void AcceptValidPostions(string input)
        {
            var positionValidator = new PositionValidator();
            var result            = positionValidator.IsValid(input);

            Assert.True(result);
        }
コード例 #4
0
        public void DeclineInvalidPostions(string input)
        {
            var positionValidator = new PositionValidator();
            var result            = positionValidator.IsValid(input);

            Assert.False(result);
        }
コード例 #5
0
        public void TestFromBoardCoordinatesBounds(int inputX, int inputY, bool expected)
        {
            var converter = new PositionValidator();
            var board     = new Board("test", 5, 5);

            var newCoords = converter.IsPositionValid(board, new Vector2(inputX, inputY));

            Assert.Equal(expected, newCoords);
        }
コード例 #6
0
        public void GetValidMoveFromUser()
        {
            InputReader    inputReader    = new TestUserInputReader("1,1");
            InputValidator inputValidator = new PositionValidator();

            var inputHandler = new UserInputHandler();
            var result       = inputHandler.GetInput(inputReader, inputValidator);

            Assert.Equal("1,1", result);
        }
コード例 #7
0
        public void RightCommand_WithoutSetCurrentPosition_Returns_UnchangedPosition()
        {
            ICommand           rightCommand      = new RightCommand(new string[] { });
            Position           currentPosition   = null;
            IPositionValidator positionValidator = new PositionValidator(5, 5);

            Position newPosition = rightCommand.Execute(currentPosition, positionValidator);

            Assert.IsNull(newPosition);
        }
コード例 #8
0
        internal ChessBoardPosition(char horizontal, int vertical)
        {
            if (PositionValidator.ValidatePosition(horizontal, vertical) == false)
            {
                throw new PositionOutOfBoardException($"Positions are out of the board! Horiontal : {horizontal} Vertical : {vertical}");
            }

            this.Horizontal = horizontal;
            this.Vertical   = vertical;
        }
コード例 #9
0
        public void PlaceCommand_WithoutSetCurrentPosition_AndInvalidNewPositon_Returns_Null()
        {
            ICommand           placeCommand      = new PlaceCommand(new string[] { "5", "1", "NORTH" });
            Position           currentPosition   = null;
            IPositionValidator positionValidator = new PositionValidator(5, 5);

            Position newPosition = placeCommand.Execute(currentPosition, positionValidator);

            Assert.IsNull(newPosition);
        }
コード例 #10
0
        public void Null_Position_Return_False()
        {
            int                tableLength       = 5;
            int                tableWidth        = 5;
            Position           currentPosition   = null;
            IPositionValidator positionValidator = new PositionValidator(tableLength, tableWidth);

            bool isValid = positionValidator.Validate(currentPosition);

            Assert.That(!isValid);
        }
コード例 #11
0
        public void NulliShootPosition()
        {
            var positionValidator = new PositionValidator();
            var player            = new Player();
            var columnSize        = 10;
            var rowSize           = 10;

            bool result = positionValidator.IsShootOk(null, columnSize, rowSize, player);

            result.Should().BeFalse();
        }
コード例 #12
0
        public void PlaceCommand_WithoutSetCurrentPosition_AndValidNewPositon_Returns_PlacedPosition()
        {
            ICommand           placeCommand      = new PlaceCommand(new string[] { "1", "1", "NORTH" });
            Position           currentPosition   = null;
            IPositionValidator positionValidator = new PositionValidator(5, 5);

            Position newPosition = placeCommand.Execute(currentPosition, positionValidator);

            Assert.That(newPosition.X == 1);
            Assert.That(newPosition.Y == 1);
            Assert.That(newPosition.Facing == Direction.NORTH);
        }
コード例 #13
0
        public void NotOverRange()
        {
            var positionValidator = new PositionValidator();
            var ships             = InitializeShips();

            var userPosition = new Position(9, 0);
            var columnSize   = 10;
            var rowSize      = 10;

            bool output = positionValidator.IsValidPosition(userPosition, columnSize, rowSize, ships);

            output.Should().Be(true);
        }
コード例 #14
0
        public void GetInvalidMoveFromUser()
        {
            var orderedInputList = new List <string> {
                "j", ",2,2", "2,2", "1,1"
            };
            InputReader    inputReader    = new TestUserInputReader(orderedInputList);
            InputValidator inputValidator = new PositionValidator();

            var inputHandler = new UserInputHandler();
            var result       = inputHandler.GetInput(inputReader, inputValidator);

            Assert.Equal("2,2", result);
        }
コード例 #15
0
        public void OutOfBoundX()
        {
            var positionValidator = new PositionValidator();

            var player         = new Player();
            var iShootPosition = new Position(11, 0);
            var columnSize     = 10;
            var rowSize        = 10;

            bool result = positionValidator.IsShootOk(iShootPosition, columnSize, rowSize, player);

            result.Should().BeFalse();
        }
コード例 #16
0
        public void NegativeYPosition()
        {
            var positionValidator = new PositionValidator();

            var player         = new Player();
            var iShootPosition = new Position(0, -1);
            var columnSize     = 10;
            var rowSize        = 10;

            bool result = positionValidator.IsShootOk(iShootPosition, columnSize, rowSize, player);

            result.Should().BeFalse();
        }
コード例 #17
0
        public void ReportCommand_WithoutSetCurrentPosition_Reports_NotPlacedMessage()
        {
            Position           currentPosition   = null;
            IPositionValidator positionValidator = new PositionValidator(5, 5);
            ICommand           reportCommand     = new ReportCommand(new string[] { });
            StringWriter       reportOutput      = new StringWriter();

            Console.SetOut(reportOutput);

            Position newPosition = reportCommand.Execute(currentPosition, positionValidator);

            Assert.That(reportOutput.ToString() == $"Output: {ErrorMessages.NotPlaced}\r\n");
        }
コード例 #18
0
        public void NegativeXResturnsfalse()
        {
            var positionValidator = new PositionValidator();
            var ships             = InitializeShips();

            var userPosition = new Position(-2, 3);
            var columnSize   = 10;
            var rowSize      = 10;

            var actual = positionValidator.IsValidPosition(userPosition, columnSize, rowSize, ships);

            actual.Should().Be(false);
        }
コード例 #19
0
        public void OutOfPlayFieldResturnsFalse()
        {
            var positionValidator = new PositionValidator();
            var ships             = InitializeShips();

            var userPosition = new Position(0, 10);
            var columnSize   = 10;
            var rowSize      = 10;

            var actual = positionValidator.IsValidPosition(userPosition, columnSize, rowSize, ships);

            actual.Should().Be(false);
        }
コード例 #20
0
        public void Overlap()
        {
            var positionValidator = new PositionValidator();

            var ships = InitializeShips();

            var userPosition = new Position(5, 10);
            var columnSize   = 10;
            var rowSize      = 10;

            bool output = positionValidator.IsValidPosition(userPosition, columnSize, rowSize, ships);

            output.Should().Be(false);
        }
コード例 #21
0
        public void Move(int[,] galaxyMatrix, int rows, int cols)
        {
            var positionValidator = new PositionValidator();

            while (Row >= 0 && Col >= 0)
            {
                if (positionValidator.Validate(Row, Col, rows, cols))
                {
                    galaxyMatrix[Row, Col] = 0;
                }

                Row--;
                Col--;
            }
        }
コード例 #22
0
        public void RightCommand_CurrentPositionSouth_SetPositionToWest()
        {
            Position currentPosition = new Position
            {
                Facing = Direction.SOUTH,
                X      = 0,
                Y      = 0
            };
            IPositionValidator positionValidator = new PositionValidator(5, 5);
            ICommand           RightCommand      = new RightCommand(new string[] { });

            Position newPosition = RightCommand.Execute(currentPosition, positionValidator);

            Assert.That(newPosition.Facing == Direction.WEST);
        }
コード例 #23
0
        public void LeftCommand_CurrentPositionEast_SetPositionToNorth()
        {
            Position currentPosition = new Position
            {
                Facing = Direction.EAST,
                X      = 0,
                Y      = 0
            };
            IPositionValidator positionValidator = new PositionValidator(5, 5);
            ICommand           leftCommand       = new LeftCommand(new string[] { });

            Position newPosition = leftCommand.Execute(currentPosition, positionValidator);

            Assert.That(newPosition.Facing == Direction.NORTH);
        }
コード例 #24
0
ファイル: Ivo.cs プロジェクト: radomirKrastev/OOP
        public void Move(int [,] galaxyMatrix, int rows, int cols)
        {
            var positionValidator = new PositionValidator();

            while (Row >= 0 && Col < galaxyMatrix.GetLength(1))
            {
                if (positionValidator.Validate(Row, Col, rows, cols))
                {
                    CollectedStarsValue += galaxyMatrix[Row, Col];
                }

                Col++;
                Row--;
            }
        }
コード例 #25
0
        public void Invalid_Positions_Return_False(int xPosition, int yPosition)
        {
            int      tableLength     = 5;
            int      tableWidth      = 5;
            Position currentPosition = new Position
            {
                Facing = Direction.NORTH,
                X      = xPosition,
                Y      = yPosition
            };
            IPositionValidator positionValidator = new PositionValidator(tableLength, tableWidth);

            bool isValid = positionValidator.Validate(currentPosition);

            Assert.That(!isValid);
        }
コード例 #26
0
        public void ReportCommand_Returns_UnchangedPosition()
        {
            Position currentPosition = new Position
            {
                Facing = Direction.NORTH,
                X      = 0,
                Y      = 0
            };
            IPositionValidator positionValidator = new PositionValidator(5, 5);
            ICommand           reportCommand     = new ReportCommand(new string[] { });

            Position newPosition = reportCommand.Execute(currentPosition, positionValidator);

            Assert.That(newPosition.X == currentPosition.X);
            Assert.That(newPosition.Y == currentPosition.Y);
            Assert.That(newPosition.Facing == currentPosition.Facing);
        }
コード例 #27
0
        public void MoveCommand_FacingNorth_ReturnsPosition_WillIncreaseY_By1()
        {
            Position currentPosition = new Position
            {
                Facing = Direction.NORTH,
                X      = 1,
                Y      = 1
            };
            IPositionValidator positionValidator = new PositionValidator(5, 5);
            ICommand           moveCommand       = new MoveCommand(new string[] { });

            Position newPosition = moveCommand.Execute(currentPosition, positionValidator);

            Assert.That(newPosition.X == 1);
            Assert.That(newPosition.Y == 2);
            Assert.That(newPosition.Facing == Direction.NORTH);
        }
コード例 #28
0
        public void MoveCommand_FacingWest_ReturnsPosition_WillDecreasedX_By1()
        {
            Position currentPosition = new Position
            {
                Facing = Direction.WEST,
                X      = 1,
                Y      = 1
            };
            IPositionValidator positionValidator = new PositionValidator(5, 5);
            ICommand           moveCommand       = new MoveCommand(new string[] { });

            Position newPosition = moveCommand.Execute(currentPosition, positionValidator);

            Assert.That(newPosition.X == 0);
            Assert.That(newPosition.Y == 1);
            Assert.That(newPosition.Facing == Direction.WEST);
        }
コード例 #29
0
        public void MoveCommand_AttemptToMoveOfEdgeOfTable_ReturnsUnchangedPosition(int xPosition, int yPosition, Direction facing)
        {
            Position currentPosition = new Position
            {
                Facing = facing,
                X      = xPosition,
                Y      = yPosition
            };
            IPositionValidator positionValidator = new PositionValidator(5, 5);
            ICommand           moveCommand       = new MoveCommand(new string[] { });

            Position newPosition = moveCommand.Execute(currentPosition, positionValidator);

            Assert.That(newPosition.X == currentPosition.X);
            Assert.That(newPosition.Y == currentPosition.Y);
            Assert.That(newPosition.Facing == currentPosition.Facing);
        }
コード例 #30
0
        public void CorrectlyPosition()
        {
            var positionValidator = new PositionValidator();

            var player = new Player();

            player.Positions = new List <Position>();
            player.Hits      = new List <Hit>();
            var iShootPosition = new Position(1, 2);

            var columnSize = 10;
            var rowSize    = 10;

            bool result = positionValidator.IsShootOk(iShootPosition, columnSize, rowSize, player);

            result.Should().BeTrue();
        }
コード例 #31
0
 public void OnSetup()
 {
     _validator = new PositionValidator(5, 5);
 }