annotate tests/test_centroid.py @ 88:596dac7f3e98

py3 compat
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Dec 2017 14:08:48 -0800
parents 20a2970d4510
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
77
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 """
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 test centroid calculations
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 """
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 import common
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 import os
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 import unittest
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 from tvii import centroid
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 class CentroidTest(unittest.TestCase):
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15 def test_square(self):
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 """find the centroids of these boring squares"""
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18 # a boring square centered about the origin
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 points = [(5., 0.),
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 (0., 5.),
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21 (-5., 0.),
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
22 (0., -5)]
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23 center = centroid.centroid(*points)
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
24
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25 tolerance = 1e-6
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
26 assert len(center) == 2 # dimensions
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27 assert all([abs(dim) < tolerance
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
28 for dim in center])
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
29
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
30 def test_main(self):
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
31 """smoketest for console-script entry point"""
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
32
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
33 datafile = common.datafile('circles.csv')
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
34 assert os.path.exists(datafile)
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
35 centroid.main([datafile])
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
36
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
37 if __name__ == '__main__':
20a2970d4510 add test for centroid calculations
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
38 unittest.main()