Clone in a terminal:
Commit 9b8b25f
Johan Mattsson - 2012-05-29T09:44:56+00:00
9b8b25fdb5d92847a2dc04d9f565f7aaea5c6160johan.mattsson.m@gmail.com

moving reverse path test case

Changed files (3)

Diff

diff --git a/src/MergeTool.vala b/src/MergeTool.valaindex a0ac9c3..9200ffd 100644--- a/src/MergeTool.vala+++ b/src/MergeTool.vala@@ -264,226 +264,7 @@ class MergeTool : Tool { 		this.yield (); 		 		test_select_action ();-	}-	-	private void test_last_is_counter_clockwise (string name) {-		bool d = ((!)MainWindow.get_current_glyph ().get_last_path ()).is_clockwise ();-		-		if (d) {-				critical (@"\nPath $name is clockwise, in test_last_is_counter_clockwise");-		}		-	}-	-	private void test_last_is_clockwise (string name) {-		bool d = ((!)MainWindow.get_current_glyph ().get_last_path ()).is_clockwise ();-		-		if (!d) {-				critical (@"\nPath $name is counter clockwise, in test_last_is_clockwise");-		}--	}-	-	private bool test_reverse_last (string name) -		requires (MainWindow.get_current_glyph ().get_last_path () != null)-	{-		Glyph g = MainWindow.get_current_glyph ();-		Path p = (!) g.get_last_path ();-		bool direction = p.is_clockwise ();--		p.reverse ();-		-		if (direction == p.is_clockwise ()) {-			critical (@"Direction did not change after reverseing path \"$name\"\n");-			stderr.printf (@"Path length: $(p.points.length ()) \n");-			return false;-		}--		this.yield ();-		return true;-	}-	-	-	class Point {-		-		public int x;-		public int y;-		-		public Point (int x, int y) {-			this.x = x;-			this.y = y;-		}-	}-	-	private Point p (int x, int y) {-		return new Point (x, y);-	}-	-	private void test_triangle (Point a, Point b, Point c, string name = "") {-		Tool pen_tool = MainWindow.get_toolbox ().get_tool ("pen_tool");-		-		this.yield ();-		MainWindow.get_tab_bar ().select_overview ();--		this.yield ();-		MainWindow.get_overview ().open_current_glyph ();-		-		pen_tool.test_select_action ();-				-		pen_tool.test_click_action (1, a.x, a.y);-		pen_tool.test_click_action (1, b.x, b.y);-		pen_tool.test_click_action (1, c.x, c.y);-		pen_tool.test_click_action (3, 0, 0);-		-		test_reverse_last (@"Triangle reverse \"$name\" ($(a.x), $(a.y)), ($(b.x), $(b.y)), ($(c.x), $(c.y)) failed.");-		-		this.yield ();-	}-	-	private void test_various_triangles () {-		test_triangle (p (287, 261), p (155, 81), p (200, 104), "First");-		test_triangle (p (65, 100), p (168, 100), p (196, 177), "Second");-		test_triangle (p (132, 68), p (195, 283), p (195, 222), "Third");-		test_triangle (p (144, 267), p (147, 27), p (296, 267), "Fourth");-	}-	-	public bool test_reverse_path () {-		// open a new glyph-		Tool pen_tool = MainWindow.get_toolbox ().get_tool ("pen_tool");--		this.yield ();-		MainWindow.get_tab_bar ().select_overview ();--		this.yield ();-		MainWindow.get_overview ().open_current_glyph ();-		-		pen_tool.test_select_action ();-		-		// paint-		int x_offset = 10;-		int y_offset = 10;-		-		test_open_next_glyph ();-		test_various_triangles ();-		-		test_open_next_glyph ();-		// draw clockwise and check direction		--		y_offset += 160;-		pen_tool.test_click_action (1, 10 + x_offset, 20 + y_offset);-		pen_tool.test_click_action (1, 17 + x_offset, 17 + y_offset);-		pen_tool.test_click_action (1, 20 + x_offset, 0 + y_offset);-		pen_tool.test_click_action (3, 0, 0);-		test_last_is_clockwise ("Clockwise triangle 1.2");--		// draw paths clockwise / counter clockwise and reverse them-		-		pen_tool.test_click_action (1, 115, 137);-		pen_tool.test_click_action (1, 89, 74);-		pen_tool.test_click_action (1, 188, 232);-		pen_tool.test_click_action (3, 0, 0);-		test_reverse_last ("Triangle 0");--		// draw incomplete paths-		y_offset += 20;-		pen_tool.test_click_action (1, 10 + x_offset, 20 + y_offset);-		pen_tool.test_click_action (3, 0, 0);-		test_reverse_last ("Point");--		y_offset += 20;-		pen_tool.test_click_action (1, 10 + x_offset, 20 + y_offset);-		pen_tool.test_click_action (1, 10 + x_offset, 20 + y_offset);-		pen_tool.test_click_action (3, 0, 0);-		test_reverse_last ("Double point");--		y_offset += 20;-		pen_tool.test_click_action (1, 10 + x_offset, 30 + y_offset);-		pen_tool.test_click_action (1, 10 + x_offset, 20 + y_offset);-		pen_tool.test_click_action (3, 0, 0);-		test_reverse_last ("Vertical line");--		y_offset += 20;-		pen_tool.test_click_action (1, 30 + x_offset, 20 + y_offset);-		pen_tool.test_click_action (1, 10 + x_offset, 20 + y_offset);-		pen_tool.test_click_action (3, 0, 0);-		test_reverse_last ("Horisontal line");--		// triangle 1-		y_offset += 20;-		pen_tool.test_click_action (1, 10 + x_offset, -10 + y_offset);-		pen_tool.test_click_action (1, 20 + x_offset, 20 + y_offset);-		pen_tool.test_click_action (1, 30 + x_offset, 0 + y_offset);-		pen_tool.test_click_action (3, 0, 0);-		test_reverse_last ("Triangle reverse 1");--		// box-		y_offset += 20;-		pen_tool.test_click_action (1, 100 + x_offset, 150 + y_offset);-		pen_tool.test_click_action (1, 150 + x_offset, 150 + y_offset);-		pen_tool.test_click_action (1, 150 + x_offset, 100 + y_offset);-		pen_tool.test_click_action (1, 100 + x_offset, 100 + y_offset); -		pen_tool.test_click_action (3, 0, 0); // close-		test_reverse_last ("Box 1");-		-		return true;-	}-	-	private Tool select_pen () {-		Tool pen_tool = MainWindow.get_toolbox ().get_tool ("pen_tool");-		pen_tool.test_select_action ();-		return pen_tool;-	}-	-	public bool test_reverse_random_triangles () {-		Tool pen;-		-		int ax, bx, cx;-		int ay, by, cy;--		bool r = true;--		test_open_next_glyph ();-		pen = select_pen ();--		int skip = 0;-		for (int i = 0; i < 10; i++) {-			this.yield ();-			-			ax = Random.int_range (0, 300);-			bx = Random.int_range (0, 300);-			cx = Random.int_range (0, 300);--			ay = Random.int_range (0, 300);-			by = Random.int_range (0, 300);-			cy = Random.int_range (0, 300);--			pen.test_click_action (1, ax, ay);-			pen.test_click_action (1, bx, by);-			pen.test_click_action (1, cx, cy);-			pen.test_click_action (3, 0, 0);-		-			r = test_reverse_last (@"Random triangle № $(i + 1) ($ax, $ay), ($bx, $by), ($cx, $cy)");-			if (!r) {-				test_open_next_glyph ();-				pen = select_pen ();--				pen.test_click_action (1, ax, ay);-				pen.test_click_action (1, bx, by);-				pen.test_click_action (1, cx, cy);-		-				return false;-			}-			-			if (++skip == 5) {-				test_open_next_glyph ();-				skip = 0;-			}-		}-		-		if (r) test_open_next_glyph ();-		-		return true;-	}-	+	}	 }  }diff --git a/src/PenTool.vala b/src/PenTool.valaindex 1733a3c..9a2e269 100644--- a/src/PenTool.vala+++ b/src/PenTool.vala@@ -610,7 +610,223 @@ class PenTool : Tool { 		} 	} +	private void test_last_is_counter_clockwise (string name) {+		bool d = ((!)MainWindow.get_current_glyph ().get_last_path ()).is_clockwise ();+		+		if (d) {+				critical (@"\nPath $name is clockwise, in test_last_is_counter_clockwise");+		}		+	}+	+	private void test_last_is_clockwise (string name) {+		bool d = ((!)MainWindow.get_current_glyph ().get_last_path ()).is_clockwise ();+		+		if (!d) {+				critical (@"\nPath $name is counter clockwise, in test_last_is_clockwise");+		}++	}+	+	private bool test_reverse_last (string name) +		requires (MainWindow.get_current_glyph ().get_last_path () != null)+	{+		Glyph g = MainWindow.get_current_glyph ();+		Path p = (!) g.get_last_path ();+		bool direction = p.is_clockwise ();++		p.reverse ();+		+		if (direction == p.is_clockwise ()) {+			critical (@"Direction did not change after reverseing path \"$name\"\n");+			stderr.printf (@"Path length: $(p.points.length ()) \n");+			return false;+		}++		this.yield ();+		return true;+	}+	+	+	class Point {+		+		public int x;+		public int y;+		+		public Point (int x, int y) {+			this.x = x;+			this.y = y;+		}+	}+	+	private Point p (int x, int y) {+		return new Point (x, y);+	}+	+	private void test_triangle (Point a, Point b, Point c, string name = "") {+		Tool pen_tool = MainWindow.get_toolbox ().get_tool ("pen_tool");+		+		this.yield ();+		MainWindow.get_tab_bar ().select_overview (); +		this.yield ();+		MainWindow.get_overview ().open_current_glyph ();+		+		pen_tool.test_select_action ();+				+		pen_tool.test_click_action (1, a.x, a.y);+		pen_tool.test_click_action (1, b.x, b.y);+		pen_tool.test_click_action (1, c.x, c.y);+		pen_tool.test_click_action (3, 0, 0);+		+		test_reverse_last (@"Triangle reverse \"$name\" ($(a.x), $(a.y)), ($(b.x), $(b.y)), ($(c.x), $(c.y)) failed.");+		+		this.yield ();+	}+	+	private void test_various_triangles () {+		test_triangle (p (287, 261), p (155, 81), p (200, 104), "First");+		test_triangle (p (65, 100), p (168, 100), p (196, 177), "Second");+		test_triangle (p (132, 68), p (195, 283), p (195, 222), "Third");+		test_triangle (p (144, 267), p (147, 27), p (296, 267), "Fourth");+	}+	+	public bool test_reverse_path () {+		// open a new glyph+		Tool pen_tool = MainWindow.get_toolbox ().get_tool ("pen_tool");++		this.yield ();+		MainWindow.get_tab_bar ().select_overview ();++		this.yield ();+		MainWindow.get_overview ().open_current_glyph ();+		+		pen_tool.test_select_action ();+		+		// paint+		int x_offset = 10;+		int y_offset = 10;+		+		test_open_next_glyph ();+		test_various_triangles ();+		+		test_open_next_glyph ();+		// draw clockwise and check direction		++		y_offset += 160;+		pen_tool.test_click_action (1, 10 + x_offset, 20 + y_offset);+		pen_tool.test_click_action (1, 17 + x_offset, 17 + y_offset);+		pen_tool.test_click_action (1, 20 + x_offset, 0 + y_offset);+		pen_tool.test_click_action (3, 0, 0);+		test_last_is_clockwise ("Clockwise triangle 1.2");++		// draw paths clockwise / counter clockwise and reverse them+		+		pen_tool.test_click_action (1, 115, 137);+		pen_tool.test_click_action (1, 89, 74);+		pen_tool.test_click_action (1, 188, 232);+		pen_tool.test_click_action (3, 0, 0);+		test_reverse_last ("Triangle 0");++		// draw incomplete paths+		y_offset += 20;+		pen_tool.test_click_action (1, 10 + x_offset, 20 + y_offset);+		pen_tool.test_click_action (3, 0, 0);+		test_reverse_last ("Point");++		y_offset += 20;+		pen_tool.test_click_action (1, 10 + x_offset, 20 + y_offset);+		pen_tool.test_click_action (1, 10 + x_offset, 20 + y_offset);+		pen_tool.test_click_action (3, 0, 0);+		test_reverse_last ("Double point");++		y_offset += 20;+		pen_tool.test_click_action (1, 10 + x_offset, 30 + y_offset);+		pen_tool.test_click_action (1, 10 + x_offset, 20 + y_offset);+		pen_tool.test_click_action (3, 0, 0);+		test_reverse_last ("Vertical line");++		y_offset += 20;+		pen_tool.test_click_action (1, 30 + x_offset, 20 + y_offset);+		pen_tool.test_click_action (1, 10 + x_offset, 20 + y_offset);+		pen_tool.test_click_action (3, 0, 0);+		test_reverse_last ("Horisontal line");++		// triangle 1+		y_offset += 20;+		pen_tool.test_click_action (1, 10 + x_offset, -10 + y_offset);+		pen_tool.test_click_action (1, 20 + x_offset, 20 + y_offset);+		pen_tool.test_click_action (1, 30 + x_offset, 0 + y_offset);+		pen_tool.test_click_action (3, 0, 0);+		test_reverse_last ("Triangle reverse 1");++		// box+		y_offset += 20;+		pen_tool.test_click_action (1, 100 + x_offset, 150 + y_offset);+		pen_tool.test_click_action (1, 150 + x_offset, 150 + y_offset);+		pen_tool.test_click_action (1, 150 + x_offset, 100 + y_offset);+		pen_tool.test_click_action (1, 100 + x_offset, 100 + y_offset); +		pen_tool.test_click_action (3, 0, 0); // close+		test_reverse_last ("Box 1");+		+		return true;+	}+	+	private Tool select_pen () {+		Tool pen_tool = MainWindow.get_toolbox ().get_tool ("pen_tool");+		pen_tool.test_select_action ();+		return pen_tool;+	}+	+	public bool test_reverse_random_triangles () {+		Tool pen;+		+		int ax, bx, cx;+		int ay, by, cy;++		bool r = true;++		test_open_next_glyph ();+		pen = select_pen ();++		int skip = 0;+		for (int i = 0; i < 10; i++) {+			this.yield ();+			+			ax = Random.int_range (0, 300);+			bx = Random.int_range (0, 300);+			cx = Random.int_range (0, 300);++			ay = Random.int_range (0, 300);+			by = Random.int_range (0, 300);+			cy = Random.int_range (0, 300);++			pen.test_click_action (1, ax, ay);+			pen.test_click_action (1, bx, by);+			pen.test_click_action (1, cx, cy);+			pen.test_click_action (3, 0, 0);+		+			r = test_reverse_last (@"Random triangle № $(i + 1) ($ax, $ay), ($bx, $by), ($cx, $cy)");+			if (!r) {+				test_open_next_glyph ();+				pen = select_pen ();++				pen.test_click_action (1, ax, ay);+				pen.test_click_action (1, bx, by);+				pen.test_click_action (1, cx, cy);+		+				return false;+			}+			+			if (++skip == 5) {+				test_open_next_glyph ();+				skip = 0;+			}+		}+		+		if (r) test_open_next_glyph ();+		+		return true;+	} }  }diff --git a/src/TestSupplement.vala b/src/TestSupplement.valaindex 75e2a54..209622f 100644--- a/src/TestSupplement.vala+++ b/src/TestSupplement.vala@@ -79,12 +79,12 @@ class TestCases { 	}
 
 	public static void test_reverse_random_paths () {
-		MergeTool tool = (MergeTool) MainWindow.get_toolbox ().get_tool ("union_paths");
+		PenTool tool = (PenTool) MainWindow.get_toolbox ().get_tool ("pen_tool");
 		tool.test_reverse_random_triangles ();		
 	}
 
 	public static void test_reverse_path () {
-		MergeTool tool = (MergeTool) MainWindow.get_toolbox ().get_tool ("union_paths");
+		PenTool tool = (PenTool) MainWindow.get_toolbox ().get_tool ("pen_tool");
 		tool.test_reverse_path ();
 	}
 

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112