view tests/test_centroid.py @ 90:3ff05538259c

mnist example
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Dec 2017 14:23:35 -0800
parents 20a2970d4510
children
line wrap: on
line source

#!/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()