Mercurial > hg > tvii
comparison 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 |
comparison
equal
deleted
inserted
replaced
65:16bd13cd58bc | 66:9f1324a59cc1 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 """ | |
4 test bounding box | |
5 """ | |
6 | |
7 import unittest | |
8 from tvii.bb import bounding_box | |
9 from tvii.bb import overlap | |
10 | |
11 class TestBoundingBox(unittest.TestCase): | |
12 | |
13 def test_integers(self): | |
14 """basic bounding box test case""" | |
15 | |
16 # We'll test with integers for ease | |
17 points = [(-1, 0), | |
18 (0, 1), | |
19 (1, 2), | |
20 (-1, 2), | |
21 (0, 0)] | |
22 | |
23 box = bounding_box(*points) | |
24 assert box == [(-1, 1), # x | |
25 (0, 2)] # y | |
26 | |
27 def test_overlap(self): | |
28 """tests if bounding boxes overlap""" | |
29 | |
30 square1 = [(0.,0.), | |
31 (1.,1.)] | |
32 bb1 = bounding_box(*square1) | |
33 assert bb1 == [(0., 1.), | |
34 (0., 1.)] | |
35 | |
36 # this doesn't overlap | |
37 square_right = [(2.,0.), | |
38 (3.,1)] | |
39 bb_right = bounding_box(*square_right) | |
40 # ((0.0, 1.0), (2.0, 3.0)) | |
41 # ((0.0, 1.0), (0.0, 1)) | |
42 assert not overlap(bb1, bb_right) | |
43 | |
44 # nor does this | |
45 square_up = [(0., 1.5), | |
46 (1., 1.9)] | |
47 assert not overlap(bb1, | |
48 bounding_box(*square_up)) | |
49 | |
50 # but this does | |
51 square_overlap = [(0.5, 0.5), | |
52 (1.5, 1.5)] | |
53 assert overlap(bb1, | |
54 bounding_box(*square_overlap)) | |
55 | |
56 if __name__ == '__main__': | |
57 unittest.main() |