Exemplo n.º 1
0
 public void TearDown()
 {
     if (TestContext.CurrentContext.Result.Outcome.Equals(ResultState.Success))
     {
         string   testName      = TestContext.CurrentContext.Test.Name;
         DateTime now           = DateTime.Now;
         string   workDirectory = TestContext.CurrentContext.TestDirectory;
         string   path          = Path.Combine(workDirectory, ImageSubDir);
         Directory.CreateDirectory(path);
         string fileName =
             $"{now.Year}-{now.Month}-{now.Day} {now.Hour}-{now.Minute}-{now.Second} {now.Millisecond}ms - {testName}.png";
         LayoutVisualizer.Visualize(layouter.WordRectangles).Save(Path.Combine(path, fileName), ImageFormat.Gif);
     }
 }
Exemplo n.º 2
0
        double GetCircularity()
        {
            Rectangle boundingBox = LayoutVisualizer.GetBoundingBox(layouter.WordRectangles);
            double    circularity = 1;

            if (boundingBox.Height != 0 && boundingBox.Width != 0)
            {
                if (boundingBox.Width > boundingBox.Height)
                {
                    circularity = (double)boundingBox.Height / boundingBox.Width;
                }
                else
                {
                    circularity = (double)boundingBox.Width / boundingBox.Height;
                }
            }
            return(circularity);
        }
Exemplo n.º 3
0
        public void WordRectangles_ShouldBeCompact(Point center, Size minSize, Size maxSize, int sampleCount, double fillThreshold, bool shouldSucceed)
        {
            PrepareTestLayout(center, minSize, maxSize, sampleCount);
            Rectangle boundingBox    = LayoutVisualizer.GetBoundingBox(layouter.WordRectangles);
            double    circleRadius   = (double)Math.Max(boundingBox.Width, boundingBox.Height) / 2;
            double    circleArea     = Math.PI * circleRadius * circleRadius;
            double    rectanglesArea = layouter.WordRectangles.Select(r => r.Height * r.Width).Sum();
            double    fillRate       = rectanglesArea / circleArea;

            if (shouldSucceed)
            {
                fillRate.Should().BeGreaterOrEqualTo(fillThreshold);
            }
            else
            {
                fillRate.Should().BeLessThan(fillThreshold);
            }
        }