Exemple #1
0
        public void AnotherRectangle_ShouldBeClose_WithSomeRectanglesPlaced()
        {
            layouter.PutNextRectangle(new Size(50, 50));
            layouter.PutNextRectangle(new Size(50, 50));
            layouter.PutNextRectangle(new Size(50, 50));
            layouter.PutNextRectangle(new Size(50, 50));

            var rectangle        = layouter.PutNextRectangle(new Size(50, 50));
            var distanceToCenter =
                RectanglesLayouter.CalculateDistance(imageCenter,
                                                     RectanglesLayouter.CalculateCenterPosition(rectangle));

            distanceToCenter.Should().Be(50, "because last closest position is near the central rectangle");
        }
Exemple #2
0
        public void RectanglesLayouter_ShouldFormCircle_FromManyRectangles()
        {
            var rand           = new Random();
            var letterSize     = new Size(3, 4);
            var maxRadius      = 0d;
            var rectanglesArea = 0d;

            for (var i = 0; i < 500; i++)
            {
                var wordSize = new Size(rand.Next(1, 100), rand.Next(1, 100));
                rectanglesArea += wordSize.Width * wordSize.Height;
                var newRect = layouter.PutNextRectangle(wordSize);
                maxRadius = Math.Max(maxRadius,
                                     RectanglesLayouter.CalculateDistance(imageCenter,
                                                                          RectanglesLayouter.CalculateCenterPosition(newRect)));
            }

            var circleArea = Math.PI * maxRadius * maxRadius;

            rectanglesArea.Should().BeGreaterOrEqualTo(circleArea * 0.8f);
        }