# HG changeset patch # User Jeff Hammel # Date 1513548653 28800 # Node ID 800f3938ebaa5dda55f80b28d1f6c8a803f3c6c1 # Parent 596dac7f3e98f9e343a6826c2a4f700255a99bbe test our pet datasets diff -r 596dac7f3e98 -r 800f3938ebaa tests/test_datasets.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_datasets.py Sun Dec 17 14:10:53 2017 -0800 @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +""" +test dataset generation +""" + +import math +import unittest +from tvii.dataset import circle +from tvii.dataset import line + +class DatasetGenerationTest(unittest.TestCase): + """test our dataset generation""" + + def test_random_circle(self): + """test generating points in a circle""" + + # test variables + center = (2.5, 3.5) + radius = 10. + number = 100000 + + # generate points + c = circle.CircularRandom(center, radius) + points = c(number) + + # validate + assert len(points) == number + offsets = [(point[0] - center[0], point[1] - center[1]) + for point in points] + distances = [math.hypot(*offset) for offset in offsets] + assert max(distances) <= radius + # TODO: ensure the distribution is fair (it's not) + + def test_x_range(self): + + x = line.x_range(0., 10., 11) + for expected, actual in enumerate(x): + self.assertAlmostEqual(actual, float(expected)) + + def test_line(self): + + # make a line + l = line.Line(1., 1.) + + self.assertAlmostEquals(l.y(1.), 2.) + self.assertAlmostEquals(l(2.)[0], 3.) + + +if __name__ == '__main__': + unittest.main()