Beispiel #1
0
        public void Scan()
        {
            ISliceValidator validator = new SliceValidatorVOne();

            Slices = new List <int[]>();

            int shapeIndex = 0;

            //Example
            //var shapes = new[]
            //{
            //    new Shape {width = 3, height = 2},
            //    new Shape {width = 2, height = 3},
            //    new Shape {width = 3, height = 1},
            //    new Shape {width = 1, height = 3},
            //};

            var shapes = new[]
            {
                new Shape {
                    width = 7, height = 2
                },
                new Shape {
                    width = 2, height = 7
                }
            };

            int rowStep = 1;

            for (int r = 0; r < RowsMax;)
            {
                for (int c = 0; c < ColsMax;)
                {
                    var xEnd = r + shapes[shapeIndex].height - 1;
                    var yEnd = c + shapes[shapeIndex].width - 1;

                    if (xEnd < RowsMax &&
                        c + shapes[shapeIndex].width - 1 < ColsMax &&
                        validator.SliceIsValid(Pizza, r, xEnd, c,
                                               yEnd,
                                               LowestAmount, HighestAmount, 2))
                    {
                        Slices.Add(new[] { r, c, xEnd, yEnd });
                        c      += shapes[shapeIndex].width;
                        rowStep = shapes[shapeIndex].height;
                    }
                    else
                    {
                        c++;
                    }
                }

                r += rowStep;
            }
        }
        public void InValidSize()
        {
            ISliceValidator sliceValidator = new SliceValidatorVOne();

            var lowestAmount        = 1;
            var highestAmount       = 6;
            var diffrentIngredients = 2;

            sliceValidator.SliceIsValid(new char[4, 3], 0, 3, 0, 2, lowestAmount, highestAmount, diffrentIngredients)
            .Should().Be(false);
            sliceValidator.SliceIsValid(new char[2, 6], 0, 1, 0, 5, lowestAmount, highestAmount, diffrentIngredients)
            .Should().Be(false);
        }
        public void InValidIngredients()
        {
            ISliceValidator sliceValidator      = new SliceValidatorVOne();
            var             lowestAmount        = 1;
            var             highestAmount       = 6;
            var             diffrentIngredients = 2;

            char[,] slice1 = new char[3, 2]
            {
                { 'T', 'T' },
                { 'T', 'T' },
                { 'T', 'T' }
            };

            sliceValidator.SliceIsValid(slice1, 0, 2, 0, 1, lowestAmount, highestAmount, diffrentIngredients).Should()
            .Be(false);
        }
        public void ValidIngredients()
        {
            ISliceValidator sliceValidator      = new SliceValidatorVOne();
            var             lowestAmount        = 1;
            var             highestAmount       = 6;
            var             diffrentIngredients = 2;

            char[,] pizza = new char[3, 5]
            {
                { 'T', 'T', 'T', 'T', 'T' },
                { 'T', 'M', 'M', 'M', 'T' },
                { 'T', 'T', 'T', 'T', 'T' }
            };

            sliceValidator.SliceIsValid(pizza, 0, 2, 0, 1, lowestAmount, highestAmount, diffrentIngredients).Should().Be(true);
            sliceValidator.SliceIsValid(pizza, 0, 2, 3, 4, lowestAmount, highestAmount, diffrentIngredients).Should().Be(true);
        }