Ejemplo n.º 1
0
        public SearchOrientation(GridToLinearStrategy gridToLinearStrategy)
        {
            if (gridToLinearStrategy is null)
            {
                throw new ArgumentException("gridToLinearStrategy parameter is null.");
            }

            _gridToLinearStrategy = gridToLinearStrategy;

            _linearView = _gridToLinearStrategy.GridToLinear();
        }
        public void GridToLinearLeftRightStrategy_NxNGrid_ReturnsLeftToRightString(string gridSource, string expected)
        {
            //arrange
            IGridManager gridManager = new GridManager(_testUtilities.StringToGrid(gridSource));

            //act
            var         gridToLinearStrategy = new GridToLinearHorizontalStrategy(gridManager);
            ILinearView linearView           = gridToLinearStrategy.GridToLinear();

            //assert
            Assert.True(expected == linearView.Value);
        }
        public void GridToLinearVerticalStrategy_NxNStringGrid_ReversedValueReturnsBottomToTopString(string gridSource, string expected)
        {
            //arrange
            IGridManager gridManager = new GridManager(_testUtilities.StringToGrid(gridSource));

            //act
            var         gridToLinearStrategy = new GridToLinearVerticalStrategy(gridManager);
            ILinearView linearView           = gridToLinearStrategy.GridToLinear();

            //assert
            Assert.True(expected == linearView.ReversedValue);
        }
        public void GridToLinearDiagonalNESWStrategy_NxNGrid_ReturnsTopRightToBottomLeftString(string gridSource, string expected)
        {
            //arrange
            IGridManager gridManager = new GridManager(_testUtilities.StringToGrid(gridSource));

            //act
            var         gridToLinearStrategy = new GridToLinearDiagonalNESWStrategy(gridManager);
            ILinearView linearView           = gridToLinearStrategy.GridToLinear();

            //assert
            Assert.True(expected == linearView.Value);
        }
        public void GetCoordinatesOfSearchTarget_PassNullSearchTarget_ReturnsNull()
        {
            //arrange
            ILinearView linearView        = null;
            var         serachOrientation = new SearchOrientation(linearView);

            //act
            PointList actual = serachOrientation.GetCoordinatesOfSearchTarget(null);

            //assert
            Assert.True(actual == null);
        }
        public void IsSearchTargetFound_PassEmptySearchTarget_ReturnsFalse()
        {
            //arrange
            ILinearView linearView        = null;
            var         serachOrientation = new SearchOrientation(linearView);

            //act
            bool actual = serachOrientation.IsSearchTargetFound("");

            //assert
            Assert.False(actual);
        }
        public void GridToLinearLeftRightStrategy_NxNStringGrid_ReturnsLeftToRightString()
        {
            //arrange
            string[,] grid =
            {
                { "A", "B", "C" },
                { "D", "E", "F" },
                { "G", "H", "I" }
            };
            IGridManager gridManager = new GridManager(grid);


            string expected = "ABC|DEF|GHI";

            //act
            var         gridToLinearStrategy = new GridToLinearHorizontalStrategy(gridManager);
            ILinearView linearView           = gridToLinearStrategy.GridToLinear();

            //assert
            Assert.True(expected == linearView.Value);
        }
        public void GridToLinearDiagonalNWSEStrategy_NxNStringGrid_ReturnsReversedIndexToGridDictionary()
        {
            //arrange
            string[,] grid =
            {
                { "A", "B" },
                { "C", "D" }
            };
            IGridManager gridManager = new GridManager(grid);

            var expected = new Dictionary <int, Point>()
            {
                { 0, new Point(0, 1) }, { 1, new Point(1, 1) }, { 2, new Point(0, 0) }, { 3, new Point(1, 0) }
            };

            //act
            var         gridToLinearStrategy = new GridToLinearDiagonalNWSEStrategy(gridManager);
            ILinearView linearView           = gridToLinearStrategy.GridToLinear();

            //assert
            Assert.Equal(expected, linearView.ReversedIndexToGridPosition);
        }
Ejemplo n.º 9
0
 public SearchOrientation(ILinearView linearView)
 {
     _linearView = linearView;
 }