示例#1
0
        public void GivenABlockOfColouredPixels_AndPixelPositionInBlockGiven__WhenFloodCalledWithPixelPos_ThenAdjacentPixelsAreReturned()
        {
            _colourGridService = new GridService(4, _startIndexPosition);
            var expectedColour         = "red";
            var expectedNewFloodColour = "white";
            var start = 1;
            var end   = 2;

            _colourGridService.FillRow(expectedColour, 1, start, end);
            _colourGridService.FillRow(expectedColour, 2, start, end);

            _colourGridService.FloodBlockWithColour(expectedNewFloodColour, new PixelPosition {
                X = 1, Y = 1
            });

            Assert.That(_colourGridService.GetPixelColour(new PixelPosition {
                X = 2, Y = 1
            }), Is.EqualTo(expectedNewFloodColour));
            Assert.That(_colourGridService.GetPixelColour(new PixelPosition {
                X = 1, Y = 1
            }), Is.EqualTo(expectedNewFloodColour));
            Assert.That(_colourGridService.GetPixelColour(new PixelPosition {
                X = 1, Y = 2
            }), Is.EqualTo(expectedNewFloodColour));
            Assert.That(_colourGridService.GetPixelColour(new PixelPosition {
                X = 2, Y = 2
            }), Is.EqualTo(expectedNewFloodColour));
        }
示例#2
0
        public void GivenABlockOfColouredPixels_AndPixelPositionIsInValid__WhenFloodCalledWithPixelPos_ThenExceptionThrown()
        {
            _colourGridService = new GridService(4, _startIndexPosition);
            var expectedColour         = "red";
            var expectedNewFloodColour = "white";

            _colourGridService.FillRow(expectedColour, 1, 1, 2);
            _colourGridService.FillRow(expectedColour, 2, 1, 2);

            Assert.Throws <ApplicationException>(() => _colourGridService.FloodBlockWithColour(expectedNewFloodColour, new PixelPosition {
                X = 9, Y = 9
            }));
        }
示例#3
0
        public void GivenAGrid4x1AColourAndStartPositionAndEndPosition_WhenFillRowCalled_ThenPixelsAreColoured()
        {
            _colourGridService = new GridService(4, 1, _startIndexPosition);
            var expectedColour = "red";

            _colourGridService.FillRow(expectedColour, 1, 1, 2);

            var grid = _colourGridService.GetGridContent();

            Assert.That(grid[1, 1].Colour, Is.EqualTo(expectedColour));
            Assert.That(grid[1, 2].Colour, Is.EqualTo(expectedColour));
        }
示例#4
0
        public void GivenABlockOfColouredPixels_AndPixelPositionInBlockGivrn_ThenAdjacentPixelsAreReturned()
        {
            _colourGridService = new GridService(4, _startIndexPosition);
            var expectedColour = "red";

            _colourGridService.FillRow(expectedColour, 1, 1, 2);
            _colourGridService.FillRow(expectedColour, 2, 1, 2);

            var adjecent = _colourGridService.GetAllAdjacentSameColourPixels(new PixelPosition {
                X = 1, Y = 1
            });
            var grid        = _colourGridService.GetGridContent();
            var resultPixel = grid[1, 1];

            Assert.That(resultPixel.Colour, Is.EqualTo(expectedColour));
            var pixelPositions = adjecent as PixelPosition[] ?? adjecent.ToArray();

            Assert.That(pixelPositions.Count(), Is.EqualTo(4));
            Assert.That(pixelPositions.Any(p => p.X == 1 && p.Y == 1));
            Assert.That(pixelPositions.Any(p => p.X == 2 && p.Y == 1));
            Assert.That(pixelPositions.Any(p => p.X == 1 && p.Y == 2));
            Assert.That(pixelPositions.Any(p => p.X == 2 && p.Y == 2));
        }
示例#5
0
        public void GivenAPixelPositionWithAnOutOfBandEnd_WhenFillRowIsCalled_ThenExceptionThrown()
        {
            _colourGridService = new GridService(4, _startIndexPosition);

            Assert.Throws <ApplicationException>(() => _colourGridService.FillRow("red", 0, 0, 9));
        }