-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_delaunay.py
43 lines (34 loc) · 1.19 KB
/
test_delaunay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
try:
import unittest2 as unittest
except ImportError:
import unittest
from shapely.geometry import Polygon, LineString, Point
from shapely.ops import triangulate
from shapely.geos import geos_version
@unittest.skipIf(geos_version < (3, 4, 0),
"Delaunay triangulation not supported")
class DelaunayTriangulation(unittest.TestCase):
"""
Only testing the number of triangles and their type here.
This doesn't actually test the points in the resulting geometries.
"""
def setUp(self):
self.p = Polygon([(0,0), (1,0), (1,1), (0,1)])
def test_polys(self):
polys = triangulate(self.p)
self.assertEqual(len(polys), 2)
for p in polys:
self.assert_(isinstance(p, Polygon))
def test_lines(self):
polys = triangulate(self.p, edges=True)
self.assertEqual(len(polys), 5)
for p in polys:
self.assert_(isinstance(p, LineString))
def test_point(self):
p = Point(1,1)
polys = triangulate(p)
self.assertEqual(len(polys), 0)
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(DelaunayTriangulation)
if __name__ == '__main__':
unittest.main()