Exemple #1
0
 public void TearDown()
 {
     if (TestContext.CurrentContext.Result.Outcome.Status != TestStatus.Passed)
     {
         var testName = TestContext.CurrentContext.Test.Name;
         SavePicture(Layouter.GetRectangles(), testName);
         WriteLog(Layouter.GetRectangles(), testName);
     }
 }
Exemple #2
0
        public void AllocateRectanglesWithoutIntersects()
        {
            var rectangles = layouter.GetRectangles().ToList();

            Enumerable.Range(0, rectangles.Count - 1)
            .SelectMany(i => Enumerable.Range(i + 1, rectangles.Count - i - 1)
                        .Select(j => (i, j)))
            .Any(k => rectangles[k.i].IntersectsWith(rectangles[k.j]))
            .Should().BeFalse();
        }
        public void MakeImageOfFailedTests()
        {
            if (TestContext.CurrentContext.Result.Outcome.Status != TestStatus.Failed)
            {
                return;
            }

            TagCloudVisualizatior.DrawAndSaveAtDocumentFolder(cloudLayouter.GetRectangles(),
                                                              TestContext.CurrentContext.Test.Name, 1000, 1000);

            Console.WriteLine($"Tag cloud visualization saved to file <{Directory.GetCurrentDirectory()}>");
        }
        public void TearDown()
        {
            if (!Equals(TestContext.CurrentContext.Result.Outcome, ResultState.Failure))
            {
                return;
            }
            var visualiser = new CloudVisualizer(cloudLayouter.CloudBorder.Size);
            var data       = cloudLayouter.GetRectangles();
            var name       = TestContext.CurrentContext.Test.Name + ".png";
            var path       = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, name);

            visualiser.Visualise(data, path);
            Console.WriteLine($"Tag cloud visualization saved to file {name}");
        }
        public void HaveCorrectTime_OnManyRectangles(int count)
        {
            layouter = new CircularCloudLayouter(new Point(500, 500));
            for (var i = 0; i < count; i++)
            {
                layouter.PutNextRectangle(new Size(40, 20));
            }

            layouter.GetRectangles().Count.Should().Be(count);
        }
        public void newRectangle_doesNotIntersectWithOthers()
        {
            var rectangleSize = new Size(10, 10);

            cloudLayouter.PutNextRectangle(rectangleSize);
            cloudLayouter.PutNextRectangle(rectangleSize);
            var rectangles = cloudLayouter.GetRectangles();
            var rectanlge  = cloudLayouter.PutNextRectangle(rectangleSize);

            Assert.IsFalse(rectangles.Any(x => x.DoesIntersect(rectanlge)));
        }
Exemple #7
0
        public static Rectangle[] CreateLayout(CircularCloudLayouter layouter, int count)
        {
            const int bias = 5;
            var       rnd  = new Random();

            for (var i = bias; i < count + bias; i++)
            {
                layouter.PutNextRectangle(new Size(rnd.Next(10, 50), rnd.Next(10, 50)));
            }
            return(layouter.GetRectangles());
        }
Exemple #8
0
        private static List <Rectangle> GenerateRectangles(CircularCloudLayouter layouter)
        {
            var rnd = new Random();

            for (int i = 0; i < 10000; ++i)
            {
                var size = new Size(rnd.Next(10, 100), rnd.Next(10, 100));
                layouter.PutNextRectangle(size);
            }
            return(layouter.GetRectangles());
        }
Exemple #9
0
        private static void Main(string[] _)
        {
            var rnd      = new Random();
            var center   = rnd.NextPoint(-100, 100, -100, 100);
            var layouter = new CircularCloudLayouter(center);

            layouter.PutRectangles(rnd.NextSizes(10, 30, 2, 5, 10, 50));

            var filename = $"{Path.GetTempPath()}CCL {DateTime.Now:yyyy-MM-dd HH-mm-ss}.png";

            Utils.SaveRectanglesToPngFile(layouter.GetRectangles(), filename);
        }
Exemple #10
0
        public Bitmap VisualizeLayout(CircularCloudLayouter layouter)
        {
            var rectangles = layouter.GetRectangles();
            var imageSize  = GetImageSize(rectangles);

            if (imageSize.Width == 0 && imageSize.Height == 0)
            {
                return(null);
            }

            return(GetImage(imageSize, rectangles));
        }
Exemple #11
0
        public static Bitmap Visualize(CircularCloudLayouter layouter, Size imageSize)
        {
            var bmp      = new Bitmap(imageSize.Width, imageSize.Height);
            var graphics = Graphics.FromImage(bmp);
            var random   = new Random();

            foreach (var rectangle in layouter.GetRectangles())
            {
                graphics.FillRectangle(new SolidBrush(GetRandomColor(random)), rectangle);
            }
            return(bmp);
        }
Exemple #12
0
 public void CreateImageOnFail()
 {
     if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
     {
         var visualizer = new Visualizer();
         var testName   = TestContext.CurrentContext.Test.Name;
         var directory  = Directory.GetCurrentDirectory();
         var path       = Path.Combine(directory, "TearDownImages", $"{testName}.png");
         var bmp        = visualizer.Visualize(BaseLayouter.GetRectangles(), new Size(200, 200));
         bmp.Save(path, ImageFormat.Png);
         TestContext.WriteLine($"Tag cloud visualization saved to file {path}");
     }
 }
        public void PutRectanglesCorrectly(int centerX, int centerY, int count, int startWidth, int startHeight,
                                           int step)
        {
            var center = new Point(centerX, centerY);

            layouter = new CircularCloudLayouter(center);
            var sizes = CreateSizeList(count, startWidth, startHeight, step);

            foreach (var size in sizes)
            {
                layouter.PutNextRectangle(size);
            }

            layouter.GetRectangles().Count.Should().Be(sizes.Count);
            ContainsIntersectedRectangles(layouter).Should().Be(false);
        }
Exemple #14
0
        static void Main()
        {
            var random        = new Random();
            var cloudLayouter = new CircularCloudLayouter(new Point(ImageHeight / 2, ImageWidth / 2));

            for (var i = 0; i < RectanglesCount; i++)
            {
                cloudLayouter.PutNextRectangle(new Size(
                                                   random.Next(MinimalRectangleWidth, MaximalRectangleWidth),
                                                   random.Next(MinimalRectangleHeight, MaximalRectangleHeight)));
            }

            Console.WriteLine("Enter image file name:");
            var fileName = Console.ReadLine();

            TagCloudVisualizatior.DrawAndSaveAtDocumentFolder(cloudLayouter.GetRectangles(), fileName, ImageHeight, ImageWidth);
        }
        private static bool ContainsIntersectedRectangles(CircularCloudLayouter layouter)
        {
            var rectangles = layouter.GetRectangles();

            foreach (var firstRectangle in rectangles)
            {
                foreach (var secondRectangle in rectangles)
                {
                    if (firstRectangle != secondRectangle && firstRectangle.IntersectsWith(secondRectangle))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #16
0
        public static IEnumerable <System.Drawing.Rectangle> MakeData(CircularCloudLayouter layouter, int count, int width)
        {
            var bias = 5;
            var rnd  = new Random();

            for (var i = bias; i < count + bias; i++)
            {
                layouter.PutNextRectangle(new Size(rnd.Next(20, 30), rnd.Next(10, 15)));
            }
            var result = layouter.GetRectangles();

            return(result.Select(x =>
                                 new System.Drawing.Rectangle(
                                     x.Vertices[0].X + width,
                                     x.Vertices[0].Y + width,
                                     x.Vertices[3].X - x.Vertices[0].X - width,
                                     x.Vertices[3].Y - x.Vertices[0].Y - width)));
        }
        public void TearDown()
        {
            if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
            {
                var path           = TestContext.CurrentContext.TestDirectory;
                var fileName       = $"{TestContext.CurrentContext.Test.Name} failed.png";
                var outputFileName = Path.Combine(path, fileName);
                using (var bitmap = new Bitmap(layouter.Size.Width, layouter.Size.Height))
                {
                    using (var graphics = Graphics.FromImage(bitmap))
                    {
                        foreach (var rectangle in layouter.GetRectangles())
                        {
                            graphics.DrawRectangle(new Pen(Color.Red), rectangle);
                        }
                        bitmap.Save(outputFileName);
                    }
                }

                TestContext.WriteLine($"Tag cloud visualization saved to file {outputFileName}");
            }
        }