[libchamplain] Test filling a polygon



commit a298cf145b9eb9ece4d658ba13c5f63a9680679c
Author: Emmanuel Rodriguez <emmanuel rodriguez gmail com>
Date:   Sun Jun 14 18:31:19 2009 +0200

    Test filling a polygon

 bindings/perl/Champlain/t/ChamplainPolygon.t |  112 +++++++++++++++++++++++++-
 1 files changed, 110 insertions(+), 2 deletions(-)
---
diff --git a/bindings/perl/Champlain/t/ChamplainPolygon.t b/bindings/perl/Champlain/t/ChamplainPolygon.t
index 48aac76..3109c0a 100644
--- a/bindings/perl/Champlain/t/ChamplainPolygon.t
+++ b/bindings/perl/Champlain/t/ChamplainPolygon.t
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Clutter::TestHelper tests => 34;
+use Clutter::TestHelper tests => 42;
 
 use Champlain;
 
@@ -15,7 +15,7 @@ exit tests();
 sub tests {
 	test_empty();
 	test_setters();
-#	test_points();
+	test_points();
 	return 0;
 }
 
@@ -78,6 +78,114 @@ sub test_setters {
 }
 
 
+sub test_points {
+	my $polygon = Champlain::Polygon->new();
+	isa_ok($polygon, 'Champlain::Polygon');
+
+	$polygon->append_point(8, 4);
+	is_polygon(
+		$polygon,
+		[
+			8, 4,
+		],
+		"append_point()"
+	);
+
+	$polygon->append_point(4, 9);
+	is_polygon(
+		$polygon,
+		[
+			8, 4,
+			4, 9,
+		],
+		"append_point()"
+	);
+
+	$polygon->insert_point(7, 10, 1);
+	is_polygon(
+		$polygon,
+		[
+			8, 4,
+			7, 10,
+			4, 9,
+		],
+		"insert_point() in the middle"
+	);
+
+	$polygon->append_point(5, 3);
+	is_polygon(
+		$polygon,
+		[
+			8, 4,
+			7, 10,
+			4, 9,
+			5, 3,
+		],
+		"polygon: 4 points"
+	);
+
+	$polygon->insert_point(1, 2, 0);
+	is_polygon(
+		$polygon,
+		[
+			1, 2,
+			8, 4,
+			7, 10,
+			4, 9,
+			5, 3,
+		],
+		"insert_point() at the beginning"
+	);
+
+	$polygon->insert_point(10, 20, 5);
+	is_polygon(
+		$polygon,
+		[
+			1, 2,
+			8, 4,
+			7, 10,
+			4, 9,
+			5, 3,
+			10, 20,
+		],
+		"insert_point() at the end"
+	);
+
+	$polygon->insert_point(30, 240, 17);
+	is_polygon(
+		$polygon,
+		[
+			1, 2,
+			8, 4,
+			7, 10,
+			4, 9,
+			5, 3,
+			10, 20,
+			30, 240,
+		],
+		"insert_point() past the end"
+	);
+
+	# Clear the polygon (it should be empty after)
+	$polygon->clear_points();
+	is_polygon($polygon, [], "clear_points()");
+	
+	$polygon->append_point(100, 200);
+	is_polygon($polygon, [100, 200], "add_point on a cleared polygon");
+}
+
+
+#
+# Assert that two colors are identical.
+#
+sub is_polygon {
+	my ($polygon, $expected, $message) = @_;
+
+	my @points = map { ($_->lat, $_->lon) } $polygon->get_points;
+	is_deeply(\ points, $expected, $message);
+}
+
+
 #
 # Assert that two colors are identical.
 #



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]