-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_predicates.py
46 lines (34 loc) · 1.62 KB
/
test_predicates.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
44
45
46
"""Test GEOS predicates
"""
from . import unittest
from shapely.geometry import Point, Polygon
from shapely.geos import TopologicalError
class PredicatesTestCase(unittest.TestCase):
def test_binary_predicates(self):
point = Point(0.0, 0.0)
self.assertTrue(point.disjoint(Point(-1.0, -1.0)))
self.assertFalse(point.touches(Point(-1.0, -1.0)))
self.assertFalse(point.crosses(Point(-1.0, -1.0)))
self.assertFalse(point.within(Point(-1.0, -1.0)))
self.assertFalse(point.contains(Point(-1.0, -1.0)))
self.assertFalse(point.equals(Point(-1.0, -1.0)))
self.assertFalse(point.touches(Point(-1.0, -1.0)))
self.assertTrue(point.equals(Point(0.0, 0.0)))
self.assertTrue(point.covers(Point(0.0, 0.0)))
self.assertFalse(point.covers(Point(-1.0, -1.0)))
def test_unary_predicates(self):
point = Point(0.0, 0.0)
self.assertFalse(point.is_empty)
self.assertTrue(point.is_valid)
self.assertTrue(point.is_simple)
self.assertFalse(point.is_ring)
self.assertFalse(point.has_z)
def test_binary_predicate_exceptions(self):
p1 = [(339, 346), (459,346), (399,311), (340, 277), (399, 173),
(280, 242), (339, 415), (280, 381), (460, 207), (339, 346)]
p2 = [(339, 207), (280, 311), (460, 138), (399, 242), (459, 277),
(459, 415), (399, 381), (519, 311), (520, 242), (519, 173),
(399, 450), (339, 207)]
self.assertRaises(TopologicalError, Polygon(p1).within, Polygon(p2))
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(PredicatesTestCase)