comparison tests/test_centroid.py @ 77:20a2970d4510

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