Ejemplo n.º 1
0
        public static TestSet Init(string size)
        {
            var ts = new TestSet
            {
                Path = System.IO.Path.GetFullPath(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $@"..\..\..\Data\images\{size}"))
            };

            ts.Picture      = new Bitmap(System.IO.Path.Combine($"{ts.Path}", "picture.png"));
            ts.RemoveMarkup = new Bitmap(System.IO.Path.Combine($"{ts.Path}", "inpaintarea.bmp"));
            var donors = new List <Bitmap>
            {
                new Bitmap(System.IO.Path.Combine($"{ts.Path}", "donor0.bmp")),
                new Bitmap(System.IO.Path.Combine($"{ts.Path}", "donor1.bmp")),
                new Bitmap(System.IO.Path.Combine($"{ts.Path}", "donor2.bmp")),
                new Bitmap(System.IO.Path.Combine($"{ts.Path}", "donor3.bmp")),
                new Bitmap(System.IO.Path.Combine($"{ts.Path}", "donor4.bmp"))
            };

            ts.Donors = donors;
            return(ts);
        }
Ejemplo n.º 2
0
        //[TestCase("1280x720", "AreaIntersectionTest", ExpectedResult = true)]
        public void Should_Intersect_Areas(string size, string testName, bool result)
        {
            var noDiffs = true;
            var ts      = TestSet.Init(size);

            var areas = new List <Area2D>
            {
                ts.Donors[0].ToArea(),
                ts.Donors[2].ToArea(),
                ts.Donors[3].ToArea(),
                ts.Donors[4].ToArea(),
                ts.RemoveMarkup.ToArea()
            };

            var testCases = areas.GetAllCombinations()
                            .OrderBy(x => x.Count())
                            .ToArray();

            var output = new Dictionary <string, Bitmap>();

            for (var i = 0; i < testCases.Length; i++)
            {
                var resultArea = Area2D.Create(0, 0, ts.Picture.Width, ts.Picture.Height);
                var testCase   = testCases[i].ToArray();

                resultArea = testCase.Aggregate(resultArea, (current, area) => current.Intersect(area));

                if (!resultArea.IsEmpty)
                {
                    SaveToOutput(output, resultArea, $"intersection{i}", testName, ts.Path);
                }
            }

            var reffiles = Directory.GetFiles($"{ts.Path}\\{testName}\\refs", "*.*", SearchOption.TopDirectoryOnly);

            if (reffiles.Length != output.Count)
            {
                noDiffs = false;
            }

            foreach (var refFilePath in reffiles)
            {
                var refFileName = Path.GetFileName(refFilePath);
                var outFilePath = $"{ts.Path}\\{testName}\\output\\{refFileName}";

                if (!output.ContainsKey(outFilePath))
                {
                    noDiffs = false;
                    continue;
                }

                var refArea = new Bitmap(refFilePath).ToArea();
                var outArea = output[outFilePath].ToArea();

                if (!refArea.IsSameAs(outArea))
                {
                    noDiffs = false;
                }
            }

            foreach (var entry in output)
            {
                entry.Value.Dispose();
            }

            noDiffs.ShouldBe(result);
        }
Ejemplo n.º 3
0
        public void Should_Intersect_Areas(string size, string testName, bool result)
        {
            var noDiffs = true;
            var ts      = TestSet.Init(size);

            var areas = new List <Area2D>
            {
                Area2D.Create(0, 0, ts.Picture.Width, ts.Picture.Height),
                ts.Donors[0].ToArea(),
                ts.Donors[3].ToArea(),
                ts.Donors[4].ToArea(),
                ts.RemoveMarkup.ToArea()
            };

            var testCases = areas.GetAllCombinations()
                            .OrderBy(x => x.Count())
                            .ToArray();

            for (int i = 0; i < testCases.Length; i++)
            {
                var testCase   = testCases[i].ToArray();
                var resultArea = testCase[0];
                for (var j = 1; j < testCase.Length; j++)
                {
                    var area = testCase[j];
                    resultArea = resultArea.Substract(area);
                }

                if (!resultArea.IsEmpty)
                {
                    SaveToOutput(resultArea, $"substraction{i}", testName, ts.Path);
                }
            }

            var reffiles = Directory.GetFiles($"{ts.Path}\\{testName}\\refs", "*.*", SearchOption.TopDirectoryOnly);
            var outfiles = Directory.GetFiles($"{ts.Path}\\{testName}\\output", "*.*", SearchOption.TopDirectoryOnly);

            if (reffiles.Length != outfiles.Length)
            {
                noDiffs = false;
            }

            foreach (var refFilePath in reffiles)
            {
                var refFileName = Path.GetFileName(refFilePath);
                var outFilePath = $"{ts.Path}\\{testName}\\output\\{refFileName}";

                if (!File.Exists(outFilePath))
                {
                    noDiffs = false;
                    continue;
                }

                var refArea = new Bitmap(refFilePath).ToArea();
                var outArea = new Bitmap(outFilePath).ToArea();

                if (!refArea.IsSameAs(outArea))
                {
                    noDiffs = false;
                }
            }

            noDiffs.ShouldBe(result);
        }