コード例 #1
0
 def test_empty(self):
     a = Box()
     self.assertTrue(a.empty)
     b = Box(x=Interval(3, 1), y=Interval(1, 2))
     self.assertTrue(b.empty)
     c = Box(x=Interval(1, 4), y=Interval(4, 2))
     self.assertTrue(c.empty)
コード例 #2
0
 def test_overlapping(self):
     box1 = Box(x=Interval(min=1, max=5), y=Interval(min=7, max=9))
     box2 = Box(x=Interval(min=3, max=7), y=Interval(min=6, max=8))
     s1 = SpanSet(box1)
     s2 = SpanSet(box2)
     s = s1 | s2
     self.assertEqual(s1 & s2, SpanSet(box1 & box2))
     self.assertEqual(s & s2, s2)
     self.assertEqual(s & s1, s1)
コード例 #3
0
 def test_intersect(self):
     a = Interval(1, 4)
     b = Interval(3, 6)
     c = Interval(3, 4)
     d = Interval(-2, 0)
     self.assertEqual(Box(a, a) & Box(b, a), Box(c, a))
     self.assertTrue((Box(a, a) & Box(d, a)).empty)
     box = Box(a, a)
     box &= Box(b, a)
     self.assertEqual(box, Box(c, a))
     box = Box(a, a)
     box &= Box(d, a)
     self.assertTrue(box.empty)
コード例 #4
0
 def test_overlaps(self):
     a = Interval(1, 4)
     c = Interval(3, 4)
     d = Interval(-2, 0)
     self.assertFalse(Box(c, c).overlaps(Box(d, d)))
     self.assertFalse(Box(c, c).overlaps(Box(a, d)))
     self.assertFalse(Box(c, c).overlaps(Box(d, a)))
     self.assertTrue(Box(c, c).overlaps(Box(a, a)))
コード例 #5
0
 def test_box(self):
     box = Box(x=Interval(min=1, max=5), y=Interval(min=7, max=9))
     s = SpanSet(box)
     self.assertEqual(len(s), box.height)
     self.assertEqual(list(s), [Span(x=box.x, y=y) for y in range(box.y0, box.y1 + 1)])
     e = SpanSet()
     self.assertEqual((s | e), s)
     self.assertEqual((s & e), e)
コード例 #6
0
 def test_standard(self):
     a = Box(x=Interval(3, 5), y=Interval(7, 9))
     self.assertEqual(a.width, 3)
     self.assertEqual(a.x0, 3)
     self.assertEqual(a.x1, 5)
     self.assertEqual(a.x, Interval(3, 5))
     self.assertEqual(a.height, 3)
     self.assertEqual(a.y0, 7)
     self.assertEqual(a.y1, 9)
     self.assertEqual(a.y, Interval(7, 9))
     self.assertFalse(a.empty)
     self.assertEqual(a.area, 9)
コード例 #7
0
 def test_disjoint(self):
     box1 = Box(x=Interval(min=1, max=5), y=Interval(min=7, max=9))
     box2 = Box(x=Interval(min=7, max=9), y=Interval(min=6, max=8))
     s1 = SpanSet(box1)
     s2 = SpanSet(box2)
     s = s1 | s2
     for span in s:
         self.assertTrue(box1.overlaps(span) or box2.overlaps(span))
     self.assertEqual(s & s1, s1)
     self.assertEqual(s & s2, s2)
     s1a, s2a = s.split()
     self.assertTrue((s1 == s1a and s2 == s2a) or (s1 == s2a and s2 == s1a))
コード例 #8
0
 def test_expand_and_overlaps(self):
     a = Interval(1, 4)
     b = Interval(3, 6)
     c = Interval(3, 4)
     d = Interval(1, 3)
     e = Interval(4, 6)
     box1 = Box(x=c, y=c)
     # x, y overload
     self.assertEqual(box1.expanded_to(x=1, y=3), Box(x=a, y=c))
     self.assertEqual(box1.expanded_to(x=3, y=1), Box(x=c, y=a))
     self.assertEqual(box1.expanded_to(x=6, y=3), Box(x=b, y=c))
     self.assertEqual(box1.expanded_to(x=3, y=6), Box(x=c, y=b))
     # Span overload
     self.assertEqual(box1.expanded_to(Span(x=d, y=3)), Box(x=a, y=c))
     self.assertEqual(box1.expanded_to(Span(x=c, y=1)), Box(x=c, y=a))
     self.assertEqual(box1.expanded_to(Span(x=e, y=3)), Box(x=b, y=c))
     self.assertEqual(box1.expanded_to(Span(x=c, y=6)), Box(x=c, y=b))
     # Box overload
     self.assertEqual(box1.expanded_to(Box(x=d, y=c)), Box(x=a, y=c))
     self.assertEqual(box1.expanded_to(Box(x=c, y=d)), Box(x=c, y=a))
     self.assertEqual(box1.expanded_to(Box(x=e, y=c)), Box(x=b, y=c))
     self.assertEqual(box1.expanded_to(Box(x=c, y=e)), Box(x=c, y=b))