Mercurial > hg > tvii
view tests/test_bb.py @ 87:9d5a5e9f5c3b
add kmeans + dataset
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 17 Dec 2017 14:05:57 -0800 |
parents | 9f1324a59cc1 |
children |
line wrap: on
line source
#!/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()