# HG changeset patch # User Jeff Hammel # Date 1513546545 28800 # Node ID 20a2970d4510a5a25b893af8466ec4e7164833c4 # Parent 02f586a9defe0b4b8225f10d4cd48189c47c7a00 add test for centroid calculations diff -r 02f586a9defe -r 20a2970d4510 tests/test_centroid.py --- /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()