From 30455f688485057d864d1acf18b51d13c75dc4a3 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Apr 21 2015 16:59:08 +0000 Subject: Improve tests --- diff --git a/mono/Contours/MainForm.cs b/mono/Contours/MainForm.cs index 04568b2..f8cd4f9 100644 --- a/mono/Contours/MainForm.cs +++ b/mono/Contours/MainForm.cs @@ -50,7 +50,8 @@ namespace Contours { foreach(Test test in Test.tests) cbTests.Items.Add(test.name); - if (!success) MessageBox.Show("Tests failed"); + if (success) MessageBox.Show("Tests passed"); + else MessageBox.Show("Tests failed"); } void cbTestsChanged(object sender, EventArgs e) { diff --git a/mono/Contours/Test.cs b/mono/Contours/Test.cs index 916b37c..5f53ca6 100644 --- a/mono/Contours/Test.cs +++ b/mono/Contours/Test.cs @@ -36,14 +36,13 @@ namespace Contours { } } - delegate Shape CombineShapesFunc(Shape a, Shape b); - Shape tryCombineShapes(CombineShapesFunc func, List>> a, List>> b) { + Shape tryCombineShapes(Shape.CombinationMode mode, List>> a, List>> b) { try { Shape sa = new Shape(); Shape sb = new Shape(); sa.setContours(a); sb.setContours(b); - return func(sa, sb); + return Shape.combine(mode, sa, sb); } catch (System.Exception) { return null; } @@ -66,10 +65,10 @@ namespace Contours { check("b", tryCreateShape(b)); if (a != null && b != null) { - check("add", tryCombineShapes(Shape.add, a, b)); - check("subtract", tryCombineShapes(Shape.subtract, a, b)); - check("xor", tryCombineShapes(Shape.xor, a, b)); - check("intersection", tryCombineShapes(Shape.intersection, a, b)); + check("add", tryCombineShapes(Shape.CombinationMode.Add, a, b)); + check("subtract", tryCombineShapes(Shape.CombinationMode.Subtract, a, b)); + check("intersection", tryCombineShapes(Shape.CombinationMode.Intersection, a, b)); + check("xor", tryCombineShapes(Shape.CombinationMode.Xor, a, b)); } return result; diff --git a/mono/Contours/tests.txt b/mono/Contours/tests.txt index 57c0167..46dedf6 100644 --- a/mono/Contours/tests.txt +++ b/mono/Contours/tests.txt @@ -9,9 +9,9 @@ ((((0, 0), (200, 0), (200, 100), (300, 100), (300, 300), (100, 300), (100, 200), (0, 200)))) subtract: ((((0, 0), (200, 0), (200, 100), (100, 100), (100, 200), (0, 200)))) + intersection: + ((((100, 100), (200, 100), (200, 200), (100, 200)))) xor: ( (((0, 0), (200, 0), (200, 100), (100, 100), (100, 200), (0, 200))), (((200, 200), (200, 100), (300, 100), (300, 300), (100, 300), (100, 200))) ) - intersection: - ((((100, 100), (200, 100), (200, 200), (100, 200)))) }