コード例 #1
0
        public void ThrowException_WhenSizeHaveNegativeNumber()
        {
            var    rectangleSize = new Size(-1, 100);
            Action act           = () => circularCloud.PutNextRectangle(rectangleSize);

            act.Should().Throw <ArgumentException>();
        }
コード例 #2
0
        public void PlaceRectanglesNotFarFromEachOtherThan10Px()
        {
            var center = new Point(200, 200);
            var size   = new Size(10, 10);

            cloudLayouter = new CircularCloudLayouter(center);
            var centerRectangle = cloudLayouter.PutNextRectangle(size);
            var rectangles      = new List <Rectangle>();

            for (int i = 0; i < 490; i += 1)
            {
                rectangles.Add(cloudLayouter.PutNextRectangle(size));
            }
            cloudLayouter.GetVisualization();
            var orderedRectangles = rectangles
                                    .OrderBy(r => r.X)
                                    .ToArray();

            orderedRectangles
            .Where((r, i) => i < orderedRectangles.Length - 1)
            .Select((r, i) => new { First = r, Second = orderedRectangles[i + 1] })
            .All(rp => Math.Abs(rp.First.X - rp.Second.X) < 10)
            .Should()
            .BeTrue();
            orderedRectangles = rectangles
                                .OrderBy(r => r.Y)
                                .ToArray();
            orderedRectangles
            .Where((r, i) => i < orderedRectangles.Length - 1)
            .Select((r, i) => new { First = r, Second = orderedRectangles[i + 1] })
            .All(rp => Math.Abs(rp.First.Y - rp.Second.Y) < 10)
            .Should()
            .BeTrue();
        }
コード例 #3
0
 public void SetUp()
 {
     center   = new Point(300, 300);
     layouter = new CircularCloudLayouter(center);
     layouter.PutNextRectangle(new Size(20, 10));
     layouter.PutNextRectangle(new Size(20, 10));
 }
コード例 #4
0
        public void placedInCloudCenter_FirstRectangle()
        {
            var rectangleSize     = new Size(10, 10);
            var resultedRectangle = cloudLayouter.PutNextRectangle(rectangleSize);

            Assert.AreEqual(center, resultedRectangle.Center);
        }
コード例 #5
0
        public void RectangleInCenter_WhenOneInputRectangle()
        {
            var size = new Size(100, 100);

            var rectangle = layouter.PutNextRectangle(size);

            rectangle.Should().Be(new Rectangle(new Point(center.X - 50, center.Y - 50), size));
        }
コード例 #6
0
ファイル: LayouterShould.cs プロジェクト: shurik236/tdd
            public void PlaceTwoRects_WithoutIntersections(int centerX, int centerY, int w1, int h1, int w2, int h2)
            {
                _layouter = new CircularCloudLayouter(new Point(centerX, centerY));
                var firstRectangle  = _layouter.PutNextRectangle(new Size(w1, h1));
                var secondRectangle = _layouter.PutNextRectangle(new Size(w2, h2));

                firstRectangle.IntersectsWith(secondRectangle).Should().BeFalse();
            }
コード例 #7
0
        public void ReturnRectangle_WhenPassedSize()
        {
            var size = new Size(20, 20);

            var supposedlyRect = layouter.PutNextRectangle(size);

            Assert.IsInstanceOf <Rectangle>(supposedlyRect);
        }
コード例 #8
0
        public void PutNextRectangle_WhenSizeIncorrect_ThrowArgumentException(int width, int height)
        {
            Action action = () =>
            {
                // ReSharper disable once ObjectCreationAsStatement
                layouter.PutNextRectangle(new Size(width, height));
            };

            action.ShouldThrow <ArgumentException>();
        }
コード例 #9
0
        public void PutNextRectangle_ShouldPutRectangleWithSameSizeAsInArgument_IfFirstRectangle()
        {
            var rectangleSize = new Size(10, 10);

            layouter.PutNextRectangle(rectangleSize);
            var rectangle = layouter.Rectangles[0];
            var size      = rectangle.Size;

            size.Should().Be(rectangleSize);
        }
コード例 #10
0
        public void PutNextRectangle_ShouldNotInterfere_NewRectangleWithAnyExisting()
        {
            var cloudCentre = new Point(0, 0);
            var target      = new CircularCloudLayouter(cloudCentre);

            var rectangle1 = target.PutNextRectangle(new Size(4, 2));
            var rectangle2 = target.PutNextRectangle(new Size(3, 1));

            rectangle2.IntersectsWith(rectangle1).Should().BeFalse();
        }
コード例 #11
0
        public void FirstRectangle_PlacedInsideCloud_IsPlacedInCenter(int width, int height)
        {
            var rectangleSize = new Size(width, height);

            var resultedRectangle = cloudLayouter.PutNextRectangle(rectangleSize);

            Assert.IsTrue(resultedRectangle.GetCenter().Equals(center));
        }
コード例 #12
0
        public void PutTwoRectangles_AndTheyAreNotIntersected()
        {
            cloudCenter           = new Point(50, 50);
            circularCloudLayouter = new CircularCloudLayouter(cloudCenter);
            rectangleSizes.Add(new Size(10, 20));
            rectangleSizes.Add(new Size(50, 50));

            var rectangle1 = circularCloudLayouter.PutNextRectangle(rectangleSizes[0]);
            var rectangle2 = circularCloudLayouter.PutNextRectangle(rectangleSizes[1]);

            rectangle1.IntersectsWith(rectangle2).Should().Be(false);
        }
コード例 #13
0
        public void PutNextRectangle_SavesPutRectangles()
        {
            const int expectedRectanglesCount = 5;

            for (var i = 0; i < expectedRectanglesCount; i++)
            {
                _circularCloudLayouter.PutNextRectangle(new Size());
            }
            var actualRectangles = _circularCloudLayouter.Rectangles;

            actualRectangles.Count.Should().Be(expectedRectanglesCount);
        }
コード例 #14
0
        public void GetPlacedRectangles_WhenPutMultipleRectangles_ListShouldBeCorrect(Size[] rectangleSizes)
        {
            foreach (var size in rectangleSizes)
            {
                layouter.PutNextRectangle(size);
            }

            layouter.GetPlacedRectangles()
            .Count()
            .Should()
            .Be(rectangleSizes.Length);
        }
コード例 #15
0
        public void СheckThatStylingIsInTheFormOfCircle()
        {
            layouter.PutNextRectangle(new Size(30, 30));
            layouter.PutNextRectangle(new Size(20, 40));
            var expectedRadius = 30;

            foreach (var rect in layouter.RectCloud.Rectangles)
            {
                var actualRadius =
                    Math.Sqrt(Math.Pow(center.X - rect.X, 2) + Math.Pow(center.Y - rect.Y, 2));
                actualRadius.Should().BeLessOrEqualTo(expectedRadius);
            }
        }
コード例 #16
0
        public void NotIntersectRectangles()
        {
            var center     = new Point(10, 10);
            var firstSize  = new Size(4, 4);
            var secondSize = new Size(6, 8);

            cloudLayouter = new CircularCloudLayouter(center);
            var firstRectangle  = cloudLayouter.PutNextRectangle(firstSize);
            var secondRectangle = cloudLayouter.PutNextRectangle(secondSize);

            firstRectangle.Intersect(secondRectangle);
            firstRectangle.Width.Should().Be(0);
            firstRectangle.Height.Should().Be(0);
        }
コード例 #17
0
        public void PutNextRectangle_WithoutIntersectionsWithPastRectangles()
        {
            var firstRectangleSize  = new Size(100, 100);
            var secondRectangleSize = new Size(100, 100);

            var firstRectangleLocation = circularCloudLayouter
                                         .PutNextRectangle(firstRectangleSize);
            var secondRectangleLocation = circularCloudLayouter
                                          .PutNextRectangle(secondRectangleSize);

            firstRectangleLocation
            .IntersectsWith(secondRectangleLocation)
            .Should().BeFalse();
        }
コード例 #18
0
        public void PutTwoRectangles_OnFreePlane()
        {
            cloudCenter           = new Point(50, 50);
            circularCloudLayouter = new CircularCloudLayouter(cloudCenter);
            rectangleSizes.Add(new Size(10, 20));
            rectangleSizes.Add(new Size(13, 6));

            var rectangle1 = circularCloudLayouter.PutNextRectangle(rectangleSizes[0]);
            var rectangle2 = circularCloudLayouter.PutNextRectangle(rectangleSizes[1]);

            rectangle1.Should().NotBe(null);
            rectangle2.Should().NotBe(null);
            rectangle1.Should().NotBeEquivalentTo(rectangle2);
        }
コード例 #19
0
ファイル: Layouter_Should.cs プロジェクト: FacelessLord/tdd
        public void TestRectanglesDoNotIntersectEachOther(int rectCount, int minWidth, int maxWidth, int minHeight,
                                                          int maxHeight)
        {
            var random = new Random();

            for (int i = 0; i < rectCount; i++)
            {
                var size = new Size(random.Next(minWidth, maxWidth), random.Next(minHeight, maxHeight));
                layouter.PutNextRectangle(size);
            }

            layouter.Layout.Any(r => layouter.Layout.Any(s => r != s && s.IntersectsWith(r)))
            .Should().BeFalse();
        }
コード例 #20
0
        public static void Main(string[] args)
        {
            var c = new CircularCloudLayouter(new Point(500, 500));

            c.PutNextRectangle(new Size(20, 20));
            c.PutNextRectangle(new Size(200, 300));
            c.PutNextRectangle(new Size(300, 100));

            var imageSize = new Size(1000, 1000);

            Drawer.Drawer.Draw(imageSize, c.Rectangles);

            //Console.WriteLine("Press enter...");
            //Console.ReadLine();
        }
コード例 #21
0
        public void MustPositioningAsDenseCircle()
        {
            var origin = new Point(0, 0);

            currentCircularCloudLayouter = new CircularCloudLayouter(origin);
            var size       = new Size(3, 3);
            var rectangles = new List <Rectangle>();

            for (var i = 0; i < 360; i++)
            {
                var rectangle = currentCircularCloudLayouter.PutNextRectangle(size);
                rectangles.Add(rectangle);
            }

            var width        = rectangles.GetWidth();
            var height       = rectangles.GetHeight();
            var radius       = Math.Max(width, height);
            var circleSquare = Math.PI * Math.Pow(radius, 2);
            var rectsSquare  = rectangles.Select(r => r.Size.Square).Sum();

            var areRectsWithinCircle = rectangles
                                       .Select(r => r.Center)
                                       .Select(rectCenter => Vector.GetLength(origin, rectCenter))
                                       .All(radiusVector => radiusVector <= radius);
            var isCircleDense = circleSquare - rectsSquare < circleSquare * 0.5;
            var result        = areRectsWithinCircle && isCircleDense;

            result.Should().BeTrue();
        }
コード例 #22
0
ファイル: TagsCloud.cs プロジェクト: Lyapa96/tdd
        public void PutWord(string word, WordSize size)
        {
            var wordInformation = new WordInformation(word, size);
            var rectangle       = Cloud.PutNextRectangle(wordInformation.RectangleSize);

            WordToRectangle.Add(wordInformation, rectangle);
        }
コード例 #23
0
        public void DrawString(string str, Font font)
        {
            var stringSize      = (graphics.MeasureString(str, font) + new SizeF(1, 1)).ToSize();
            var stringRectangle = layouter.PutNextRectangle(stringSize);

            graphics.DrawString(str, font, brush, stringRectangle, stringFormat);
        }
コード例 #24
0
        public void PutNextRectangle_ThrowArgumentException_WhenIncorrectDirectionsOfRectangle(int width, int height)
        {
            cloudLayouter = new CircularCloudLayouter(new Point(0, 0));
            Action action = () => cloudLayouter.PutNextRectangle(new Size(width, height));

            action.Should().Throw <ArgumentException>();
        }
コード例 #25
0
 public void ThrowsArgumentException_IfNotPositiveSizeOfRectangle(int width, int height)
 {
     cloudCenter           = new Point(50, 50);
     circularCloudLayouter = new CircularCloudLayouter(cloudCenter);
     rectangleSizes.Add(new Size(width, height));
     Assert.Throws <ArgumentException>(() => circularCloudLayouter.PutNextRectangle(rectangleSizes[0]));
 }
コード例 #26
0
        static void Main(string[] args)
        {
            var allSizes = new List <Size>();
            var rnd      = new Random();

            for (var i = 0; i < 100; i++)
            {
                var nextHeight = rnd.Next(20, 25);
                //var nextHeight = 40;
                var nextWidth = rnd.Next(nextHeight * 2, nextHeight * 6);
                //var nextWidth = 160;
                allSizes.Add(new Size(nextWidth, nextHeight));
            }

            var circularCloudLayouter = new CircularCloudLayouter(new Point(0, 5));

            foreach (var r in allSizes)
            {
                circularCloudLayouter.PutNextRectangle(r);
            }

            var render = new TagsCloudRenderer();

            render.RenderIntoFile("img.png", circularCloudLayouter.TagsCloud);
        }
コード例 #27
0
        public void PlaceRectanglesWithinCircle()
        {
            var center = new Point(200, 200);
            var size   = new Size(10, 10);

            cloudLayouter = new CircularCloudLayouter(center);
            var centerRectangle = cloudLayouter.PutNextRectangle(size);
            var rectangles      = new List <Rectangle>();

            for (int i = 0; i < 490; i += 1)
            {
                rectangles.Add(cloudLayouter.PutNextRectangle(size));
            }
            cloudLayouter.GetVisualization();
            rectangles.All(r => Math.Pow(r.X - center.X, 2) + Math.Pow(r.Y - center.Y, 2) < 490000).Should().BeTrue();
        }
コード例 #28
0
        public MainForm()
        {
            var center         = new Point(Width / 2, Height / 2);
            var cloudLoyouter2 = new CircularCloudLayouter(center);
            var pb             = new PictureBox
            {
                Width  = this.Width,
                Height = this.Height,
            };

            drawArea = new Bitmap(pb.Size.Width, pb.Size.Height);
            Controls.Add(pb);
            using (var g = Graphics.FromImage(drawArea))
            {
                var rnd           = new Random(1);
                var allRectangles = new List <Rectangle>();

                for (var i = 0; i < 30; i++)
                {
                    var rect = cloudLoyouter2.PutNextRectangle(new Size(30, 30));
                    g.DrawRectangle(Pens.Green, rect);
                    allRectangles.Add(rect);
                }
                for (var i = 0; i < 30; i++)
                {
                    var rect = cloudLoyouter2.PutNextRectangle(new Size(20, 20));
                    g.DrawRectangle(Pens.Green, rect);
                    allRectangles.Add(rect);
                }

                //for (var i = 0; i < 100; i++)
                //{
                //    //var rect = cloudLoyouter2.PutNextRectangle(new Size(rnd.Next(4, 30), rnd.Next(5, 10)));
                //    var rect = cloudLoyouter2.PutNextRectangle(new Size(10, 10));
                //    allRectangles.Add(rect);
                //    if (rect == default(Rectangle))
                //        break;
                //    //g.FillRectangle(Brushes.Green, new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height));
                //    g.DrawRectangle(Pens.Green, new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height));
                //}
                var totalArea             = allRectangles.Select(x => x.Width * x.Height).Sum();
                var currentCircularRadius = (int)(1.2 * Math.Sqrt(totalArea / Math.PI));
                g.DrawEllipse(Pens.Green, center.X - currentCircularRadius, center.Y - currentCircularRadius, 2 * currentCircularRadius, 2 * currentCircularRadius);
            }
            pb.Image = drawArea;
            pb.Invalidate();
        }
コード例 #29
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));
        }
コード例 #30
0
ファイル: TagLayouter.cs プロジェクト: akulin/tdd
 private Tag GetNextTag(WeightedWord weightedWord, int minWeight, int maxWeight)
 {
     var fontSize = GetFontSize(weightedWord.Weight, minWeight, maxWeight);
     var font = new Font(FontFamily.GenericSerif, fontSize);
     var frameSize = TextRenderer.MeasureText(weightedWord.Word, font);
     var frame = cloudLayouter.PutNextRectangle(frameSize);
     return new Tag(weightedWord.Word, frame, font);
 }