Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }