/
Vector_test.py
51 lines (44 loc) · 1.48 KB
/
Vector_test.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from Vector import Vector
import math
"""
Tests for the mapping from cartesian to GUI-space coordinates
"""
def test_coodinate_conversion():
#Testing quadrant 1 coordinate conversion
vec = Vector(vector=(1,1))
guiCoord = vec.getGUIVector1()
assert guiCoord[0] == 261
assert guiCoord[1] == 259
#Testing quadrant 2 coordinate conversion
vec = Vector(vector=(-3,10))
guiCoord = vec.getGUIVector1()
assert guiCoord[0] == 257
assert guiCoord[1] == 250
#Testing quadrant 3 coordinate conversion
vec = Vector(vector=(-5,-10))
guiCoord = vec.getGUIVector1()
assert guiCoord[0] == 255
assert guiCoord[1] == 270
#Testing quadrant 4 coordinate conversion
vec = Vector(vector=(5, -10))
guiCoord = vec.getGUIVector1()
assert guiCoord[0] == 265
assert guiCoord[1] == 270
"""
Tests for vector rotation
"""
def test_rotation():
#Testing rotation by 45 degrees; using rounding since rotated vectors
#return 0 as a approximation
vec = Vector(vector=(1,1))
vec.rotateBy(45)
rotatedVector = vec.getCartesianVector()
assert round(rotatedVector[0]) == 0
assert round(rotatedVector[1]) == 1
#Testing rotation by 30 degrees; Rounding because rotation matrix
#returns rotated vector with truncated sig figs
vec.rotateBy(30)
rotatedVector = vec.getCartesianVector()
print(rotatedVector)
assert round(rotatedVector[0]) == round(-0.5)
assert round(rotatedVector[1]) == round(math.sqrt(3)/2.0)