comparison tests/test_datasets.py @ 89:800f3938ebaa

test our pet datasets
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Dec 2017 14:10:53 -0800
parents
children
comparison
equal deleted inserted replaced
88:596dac7f3e98 89:800f3938ebaa
1 #!/usr/bin/env python
2
3 """
4 test dataset generation
5 """
6
7 import math
8 import unittest
9 from tvii.dataset import circle
10 from tvii.dataset import line
11
12 class DatasetGenerationTest(unittest.TestCase):
13 """test our dataset generation"""
14
15 def test_random_circle(self):
16 """test generating points in a circle"""
17
18 # test variables
19 center = (2.5, 3.5)
20 radius = 10.
21 number = 100000
22
23 # generate points
24 c = circle.CircularRandom(center, radius)
25 points = c(number)
26
27 # validate
28 assert len(points) == number
29 offsets = [(point[0] - center[0], point[1] - center[1])
30 for point in points]
31 distances = [math.hypot(*offset) for offset in offsets]
32 assert max(distances) <= radius
33 # TODO: ensure the distribution is fair (it's not)
34
35 def test_x_range(self):
36
37 x = line.x_range(0., 10., 11)
38 for expected, actual in enumerate(x):
39 self.assertAlmostEqual(actual, float(expected))
40
41 def test_line(self):
42
43 # make a line
44 l = line.Line(1., 1.)
45
46 self.assertAlmostEquals(l.y(1.), 2.)
47 self.assertAlmostEquals(l(2.)[0], 3.)
48
49
50 if __name__ == '__main__':
51 unittest.main()