-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_cartesian_coordinates.py
30 lines (20 loc) · 1.01 KB
/
test_cartesian_coordinates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# A set of tests for the cartesian coordinates functions.
import cartesian_coordinates as cc
import unittest
from math import sqrt
class TestCartesianCoordinates(unittest.TestCase):
def test_translation(self):
self.assertEqual(cc.translation([2.0, 3.0], [10.0, 11.0]), [12.0, 14.0])
def test_scale(self):
self.assertEqual(cc.scale([2.0, 3.0], 5), [10.0, 15.0])
def test_rotate_around_origin(self):
new_position = cc.rotate_around_origin([1.0, 0.0], 90)
self.assertAlmostEqual(new_position[0], 0.0) # X
self.assertAlmostEqual(new_position[1], -1.0) # Y
new_position = cc.rotate_around_origin([1.0, 0.0], -45)
self.assertAlmostEqual(new_position[0], sqrt(2) / 2) # X
self.assertAlmostEqual(new_position[1], sqrt(2) / 2) # Y
def test_rotate_around_a_point(self):
self.assertEqual(cc.rotate_around_a_point([2.0, 3.0], [2.0, 2.0], 90.0), [3.0, 2.0])
if __name__ == '__main__':
unittest.main()