# HG changeset patch # User Jeff Hammel # Date 1513543686 28800 # Node ID 9f1324a59cc1641b1bc3414735198549776787c3 # Parent 16bd13cd58bc63e295ea9f181d53f79da857739f add bounding box + tests diff -r 16bd13cd58bc -r 9f1324a59cc1 tests/test_bb.py --- /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()