annotate tests/test_bb.py @ 75:a17d43d7bf1b

add simple CLI abstraction
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Dec 2017 13:32:24 -0800
parents 9f1324a59cc1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
66
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 """
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 test bounding box
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 """
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 import unittest
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 from tvii.bb import bounding_box
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 from tvii.bb import overlap
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11 class TestBoundingBox(unittest.TestCase):
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 def test_integers(self):
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 """basic bounding box test case"""
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 # We'll test with integers for ease
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 points = [(-1, 0),
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18 (0, 1),
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 (1, 2),
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 (-1, 2),
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21 (0, 0)]
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
22
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23 box = bounding_box(*points)
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
24 assert box == [(-1, 1), # x
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25 (0, 2)] # y
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
26
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27 def test_overlap(self):
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
28 """tests if bounding boxes overlap"""
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
29
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
30 square1 = [(0.,0.),
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
31 (1.,1.)]
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
32 bb1 = bounding_box(*square1)
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
33 assert bb1 == [(0., 1.),
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
34 (0., 1.)]
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
35
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
36 # this doesn't overlap
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
37 square_right = [(2.,0.),
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
38 (3.,1)]
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
39 bb_right = bounding_box(*square_right)
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
40 # ((0.0, 1.0), (2.0, 3.0))
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
41 # ((0.0, 1.0), (0.0, 1))
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
42 assert not overlap(bb1, bb_right)
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
43
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
44 # nor does this
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
45 square_up = [(0., 1.5),
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
46 (1., 1.9)]
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
47 assert not overlap(bb1,
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
48 bounding_box(*square_up))
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
49
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
50 # but this does
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
51 square_overlap = [(0.5, 0.5),
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
52 (1.5, 1.5)]
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
53 assert overlap(bb1,
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
54 bounding_box(*square_overlap))
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
55
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
56 if __name__ == '__main__':
9f1324a59cc1 add bounding box + tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
57 unittest.main()