diff tests/test_bb.py @ 66:9f1324a59cc1

add bounding box + tests
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Dec 2017 12:48:06 -0800
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_bb.py	Sun Dec 17 12:48:06 2017 -0800
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+
+"""
+test bounding box
+"""
+
+import unittest
+from tvii.bb import bounding_box
+from tvii.bb import overlap
+
+class TestBoundingBox(unittest.TestCase):
+
+    def test_integers(self):
+        """basic bounding box test case"""
+
+        # We'll test with integers for ease
+        points = [(-1, 0),
+                  (0, 1),
+                  (1, 2),
+                  (-1, 2),
+                  (0, 0)]
+
+        box = bounding_box(*points)
+        assert box == [(-1, 1),  # x
+                       (0, 2)]   # y
+
+    def test_overlap(self):
+        """tests if bounding boxes overlap"""
+
+        square1 = [(0.,0.),
+                   (1.,1.)]
+        bb1 = bounding_box(*square1)
+        assert bb1 == [(0., 1.),
+                       (0., 1.)]
+
+        # this doesn't overlap
+        square_right = [(2.,0.),
+                        (3.,1)]
+        bb_right = bounding_box(*square_right)
+        # ((0.0, 1.0), (2.0, 3.0))
+        # ((0.0, 1.0), (0.0, 1))
+        assert not overlap(bb1, bb_right)
+
+        # nor does this
+        square_up = [(0., 1.5),
+                     (1., 1.9)]
+        assert not overlap(bb1,
+                           bounding_box(*square_up))
+
+        # but this does
+        square_overlap = [(0.5, 0.5),
+                          (1.5, 1.5)]
+        assert overlap(bb1,
+                       bounding_box(*square_overlap))
+
+if __name__ == '__main__':
+    unittest.main()