Mercurial > hg > tvii
changeset 77:20a2970d4510
add test for centroid calculations
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 17 Dec 2017 13:35:45 -0800 |
parents | 02f586a9defe |
children | 4f197c057e26 |
files | tests/test_centroid.py |
diffstat | 1 files changed, 38 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_centroid.py Sun Dec 17 13:35:45 2017 -0800 @@ -0,0 +1,38 @@ +#!/usr/bin/env python + +""" +test centroid calculations +""" + +import common +import os +import unittest +from tvii import centroid + + +class CentroidTest(unittest.TestCase): + + def test_square(self): + """find the centroids of these boring squares""" + + # a boring square centered about the origin + points = [(5., 0.), + (0., 5.), + (-5., 0.), + (0., -5)] + center = centroid.centroid(*points) + + tolerance = 1e-6 + assert len(center) == 2 # dimensions + assert all([abs(dim) < tolerance + for dim in center]) + + def test_main(self): + """smoketest for console-script entry point""" + + datafile = common.datafile('circles.csv') + assert os.path.exists(datafile) + centroid.main([datafile]) + +if __name__ == '__main__': + unittest.main()