private IEnumerable <Point> GetNextPointManyTimes(EternityGeneratorCirclePoints generatorCirclePoints, int countPoints)
 {
     for (var index = 0; index < countPoints; index++)
     {
         yield return(generatorCirclePoints.GetNextPoint());
     }
 }
        public void GetCenterPoint_ReturnsCorrectPoint_WhenGeneratorIsCreated()
        {
            var centerPoint     = new Point(10, 10);
            var generatorPoints = new EternityGeneratorCirclePoints(centerPoint);

            generatorPoints.GetCenterPoint()
            .ShouldBeEquivalentTo(centerPoint);
        }
Exemple #3
0
        public void PutNextRectangle_ShouldThrowArgumentException_WhenGetsIncorrectSize(int width, int height)
        {
            var generatorCirclePoints = new EternityGeneratorCirclePoints(0, 0);
            var cloudLayouter         = new CircularCloudLayouter(generatorCirclePoints);
            var size = new Size(width, height);

            Assert.Throws <ArgumentException>(() => cloudLayouter.PutNextRectangle(size));
        }
        public void GetNextPoint_ReturnsCorrectPointOnSecondGenerator_WhenTwoGeneratorsAreCreated()
        {
            var firstGenerator  = new EternityGeneratorCirclePoints(0, 0);
            var secondGenerator = new EternityGeneratorCirclePoints(1, 1);

            secondGenerator.GetNextPoint()
            .ShouldBeEquivalentTo(secondGenerator.GetCenterPoint());
        }
        public void GetNextPoint_ShouldReturnCenterPoint_WhenExecutesAtFirst(int x, int y)
        {
            var centerPoint             = new Point(x, y);
            var eternityGeneratorPoints = new EternityGeneratorCirclePoints(centerPoint);

            eternityGeneratorPoints.GetNextPoint()
            .ShouldBeEquivalentTo(centerPoint);
        }
        public void GetNextPoint_ShouldWorksFast_WhenExecutesManyTimes()
        {
            var eternityGeneratorPoints = new EternityGeneratorCirclePoints(0, 0);

            for (var index = 0; index < 1000000; index++)
            {
                eternityGeneratorPoints.GetNextPoint();
            }
        }
Exemple #7
0
        public void PutNextRectangle_WorksFast_WhenAddedALotOfRectangles()
        {
            var generatorCirclePoints = new EternityGeneratorCirclePoints(0, 0);
            var cloudLayouter         = new CircularCloudLayouter(generatorCirclePoints);

            for (int iterationIndex = 0; iterationIndex < 2000; iterationIndex++)
            {
                cloudLayouter.PutNextRectangle(new Size(10 + iterationIndex % 10, 10 + 3 * iterationIndex % 10));
            }
        }
        public void GetNextPoint_ShouldNotReturnSamePointsInARow_WhenExecutesManyTimes()
        {
            var eternityGeneratorPoints = new EternityGeneratorCirclePoints(0, 0);

            var points = GetNextPointManyTimes(eternityGeneratorPoints, 100000).ToList();

            for (var index = 1; index < points.Count; index++)
            {
                Assert.AreNotEqual(points[index - 1], points[index]);
            }
        }
        public void GetNextPoint_ShouldReturnDifferentPoints_WhenExecutesManyTimes()
        {
            var eternityGeneratorPoints = new EternityGeneratorCirclePoints(0, 0);
            var countItems = 10000;

            var differentPointsCount = GetNextPointManyTimes(eternityGeneratorPoints, countItems)
                                       .Distinct()
                                       .Count();

            differentPointsCount.Should().Be(countItems);
        }
Exemple #10
0
        public void PutNextRectangle_ReturnRectangleWithCorrectSize_WhenSendOneRectangleSize(int startX, int startY,
                                                                                             int width, int height)
        {
            var generatorCirclePoints = new EternityGeneratorCirclePoints(startX, startY);
            var cloudLayouter         = new CircularCloudLayouter(generatorCirclePoints);
            var size = new Size(width, height);

            var rectangle = cloudLayouter.PutNextRectangle(size);

            rectangle.Size
            .ShouldBeEquivalentTo(size);
        }
        public void GetCenterPoint_ReturnsCorrectPoint_WhenGetNextPointExecutedManyTimes()
        {
            var centerPoint     = new Point(10, 10);
            var generatorPoints = new EternityGeneratorCirclePoints(centerPoint);

            for (var index = 0; index < 10000; index++)
            {
                generatorPoints.GetNextPoint();
            }

            generatorPoints.GetCenterPoint()
            .ShouldBeEquivalentTo(centerPoint);
        }
        public void GetNextPoint_IncreasesDistanceToCenterNotTooFast_WhenExecutesManyTimes()
        {
            var generatorPoints = new EternityGeneratorCirclePoints(0, 0);

            var distances = GetNextPointManyTimes(generatorPoints, 100000)
                            .Select(x => Math.Sqrt(x.X * x.X + x.Y * x.Y))
                            .ToList();

            for (var index = 1; index < distances.Count; index++)
            {
                (distances[index] - 1).Should().BeLessOrEqualTo(distances[index - 1]);
            }
        }
Exemple #13
0
        public void PutNextRectangle_ShouldBeCloseToCenterPoint_WhenSendOneRectangleSize(int startX,
                                                                                         int startY,
                                                                                         int width,
                                                                                         int height)
        {
            var centerPoint           = new Point(startX, startY);
            var generatorCirclePoints = new EternityGeneratorCirclePoints(centerPoint);
            var cloudLayouter         = new CircularCloudLayouter(generatorCirclePoints);
            var size = new Size(width, height);

            var square = cloudLayouter.PutNextRectangle(size);

            centerPoint.DistanceTo(square).Should().BeLessOrEqualTo(10);
        }
Exemple #14
0
        public void PutNextRectangle_ShouldReturnDenseRectangles_WhenAddedALotOfRectangles()
        {
            var generatorCirclePoints = new EternityGeneratorCirclePoints(400, 400);
            var cloudLayouter         = new CircularCloudLayouter(generatorCirclePoints);

            var rectangles = Enumerable.Range(0, 200)
                             .Select(x => cloudLayouter.PutNextRectangle(new Size(10 + x % 10, 10 + (3 * x) % 10)))
                             .ToList();

            rectangles.SelectMany(x => rectangles.Select(y => Tuple.Create(x, y)))
            .Select(x => x.Item1.DistanceToRectangle(x.Item2))
            .Max()
            .Should()
            .BeLessThan(300);
        }
Exemple #15
0
        public void PutNextRectangle_ShouldReturnDisjointRectangles_WhenSendManyRectangles()
        {
            var generatorCirclePoints = new EternityGeneratorCirclePoints(0, 0);
            var cloudLayouter         = new CircularCloudLayouter(generatorCirclePoints);

            var rectangles = Enumerable.Range(0, 100)
                             .Select(x => cloudLayouter.PutNextRectangle(new Size(10 + x % 10, 10 + 2 * x % 10)))
                             .ToList();

            rectangles.SelectMany(x => rectangles.Select(y => Tuple.Create(x, y)))
            .Where(x => x.Item1 != x.Item2)
            .Any(x => x.Item1.IntersectsWith(x.Item2))
            .Should()
            .BeFalse();
        }
Exemple #16
0
        public void PutNextRectangle_ReturnRectanglesWithCorrectSize_WhenSendALotOfRectangles()
        {
            var generatorCirclePoints = new EternityGeneratorCirclePoints(400, 400);
            var cloudLayouter         = new CircularCloudLayouter(generatorCirclePoints);
            var countRectangles       = 50;
            var sizes = Enumerable.Range(1, countRectangles)
                        .Select(x => new Size(x * 3, x * 5))
                        .ToList();

            var rectanglesSizes = sizes.Select(x => cloudLayouter.PutNextRectangle(x))
                                  .Select(x => x.Size)
                                  .ToList();

            rectanglesSizes.ShouldBeEquivalentTo(sizes,
                                                 AssertionOptions => AssertionOptions.WithStrictOrdering());
        }
Exemple #17
0
        public void PutNextRectangle_ShouldReturnRectanglesWithNonNegativeCoordinates_WhenAddManyRectangles()
        {
            var generatorCirclePoints = new EternityGeneratorCirclePoints(0, 0);
            var cloudLayouter         = new CircularCloudLayouter(generatorCirclePoints);
            var rectangleSize         = new Size(10, 10);
            var maximumSquare         = new Rectangle(new Point(0, 0), new Size(10000000, 10000000));

            var rectangles = Enumerable.Range(0, 1000)
                             .Select(x => cloudLayouter.PutNextRectangle(rectangleSize))
                             .ToList();

            foreach (var rectangle in rectangles)
            {
                maximumSquare.Contains(rectangle).Should().BeTrue();
            }
        }
        public void GetNextPoint_IncreasesAverageDistanceNotSoFast_WhenExecutesManyTimes()
        {
            var firstPartCountPoints = 1000;
            var allCountPoints       = firstPartCountPoints * 2;
            var generator            = new EternityGeneratorCirclePoints(0, 0);

            var distances = GetNextPointManyTimes(generator, allCountPoints)
                            .Select(x => Math.Sqrt(x.X * x.X + x.Y * x.Y))
                            .ToList();

            var firstPartAvetageDistance = distances.Take(firstPartCountPoints).Sum() / firstPartCountPoints;
            var allPointsAverageDistance = distances.Sum() / allCountPoints;

            (firstPartAvetageDistance * 2).Should()
            .BeGreaterOrEqualTo(allPointsAverageDistance);
        }
        public void GetNextPoint_ShouldReturnPointWithLengthToCentreMoreOrEqualThanAverage_WhenExecutesManyTimes()
        {
            var centerPoint             = new Point(0, 0);
            var eternityGeneratorPoints = new EternityGeneratorCirclePoints(0, 0);
            var currentAverageLength    = 0.0;

            var lengthsToCentre = GetNextPointManyTimes(eternityGeneratorPoints, 1000000)
                                  .Select(x => Math.Sqrt(x.X * x.X + x.Y * x.Y))
                                  .ToList();

            for (var index = 0; index < lengthsToCentre.Count; index++)
            {
                var currentLengthToCentre = lengthsToCentre[index];
                currentLengthToCentre.Should().BeGreaterOrEqualTo(currentAverageLength);
                currentAverageLength = (currentAverageLength * index + currentLengthToCentre) / (index + 1);
            }
        }
Exemple #20
0
        private void AddWordLabels(IEnumerable <String> words)
        {
            var generatorCirclePoints = new EternityGeneratorCirclePoints(centerPoint);
            var cloudLayouter         = new CircularCloudLayouter(generatorCirclePoints);
            var fontSize = 35;

            foreach (var word in words)
            {
                var wordLabel = new Label();
                wordLabel.Font = new Font("Arial", fontSize, FontStyle.Bold);
                wordLabel.Text = word;
                var size           = TextRenderer.MeasureText(word, wordLabel.Font);
                var rectangleWords = cloudLayouter.PutNextRectangle(size);
                wordLabel.Location  = rectangleWords.Location;
                wordLabel.Size      = size;
                wordLabel.ForeColor = GetRandomColor();
                Controls.Add(wordLabel);
                fontSize = GetNextFontSize(fontSize);
            }
        }
Exemple #21
0
        public void Creation_ShouldThrowArgumentException_WhenGetsIncorrectCenterPoint(int x, int y)
        {
            var generatorCirclePoints = new EternityGeneratorCirclePoints(x, y);

            Assert.Throws <ArgumentException>(() => new CircularCloudLayouter(generatorCirclePoints));
        }