Skip to content

Commit 7a480f8

Browse files
committed
Polygon more constructor tests
Add tests for the various times polygons should raise an exception. * pygorithm/geometry/polygon2.py - minor documentation changes * tests/test_geometry.py - more polygon constructor tests
1 parent b3b16d5 commit 7a480f8

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

pygorithm/geometry/polygon2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class Polygon2(object):
3737
3838
.. caution::
3939
40-
The normals in the :py:attr:`~pygorithm.geometry.polygon2.Polygon2.normals`
41-
are not necessarily the same length as
40+
The length of :py:attr:`~pygorithm.geometry.polygon2.Polygon2.normals`
41+
is not necessarily the same as
4242
:py:attr:`~pygorithm.geometry.polygon2.Polygon2.points` or
4343
:py:attr:`~pygorithm.geometry.polygon2.Polygon2.lines`. It is only
4444
guarranteed to have no two vectors that are the same or opposite

tests/test_geometry.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,22 @@ def test_constructor_standard(self):
581581

582582
with self.assertRaises(StopIteration):
583583
next(i for i in range(4) if poly.points[i].x != poly2.points[i].x or poly.points[i].y != poly2.points[i].y)
584+
585+
def test_constructor_repeated(self):
586+
with self.assertRaises(ValueError):
587+
poly = polygon2.Polygon2([ (0, 1), (1, 1), (1, 0), (0, 0), (0, 1) ])
588+
589+
def test_constructor_two_points(self):
590+
with self.assertRaises(ValueError):
591+
poly = polygon2.Polygon2([ (0, 1), (1, 1) ])
584592

593+
def test_constructor_not_convex(self):
594+
with self.assertRaises(ValueError):
595+
poly = polygon2.Polygon2([ (0, 1), (0.5, 0.8), (1, 1), (1, 0), (0, 0) ])
596+
597+
def test_cosntructor_not_clockwise(self):
598+
with self.assertRaises(ValueError):
599+
poly = polygon2.Polygon2([ (0, 0), (1, 0), (1, 1), (0, 1) ])
585600

586601
def test_from_regular(self):
587602
diamond = polygon2.Polygon2.from_regular(4, 1)

0 commit comments

Comments
 (0)