/
test_transform.py
51 lines (45 loc) · 1.3 KB
/
test_transform.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
import unittest
import numpy as np
import k3d
from ..transform import Transform
class TestTransform(unittest.TestCase):
def test_recompute_translation(self):
# given
transform = Transform()
# when
transform.translation = [1., 2., 3.]
# then
self.assertTrue((transform.model_matrix == np.array([
[1., 0., 0., 1.],
[0., 1., 0., 2.],
[0., 0., 1., 3.],
[0., 0., 0., 1.]
])).all())
def test_recompute_scaling(self):
# given
transform = Transform()
# when
transform.scaling = [1., 2., 3.]
# then
self.assertTrue((transform.model_matrix == np.array([
[1., 0., 0., 0.],
[0., 2., 0., 0.],
[0., 0., 3., 0.],
[0., 0., 0., 1.]
])).all())
def test_drawable_notification(self):
# given
transform = Transform()
points = k3d.points([0, 0, 1])
transform.add_drawable(points)
# when
transform.scaling = [1., 2., 3.]
# then
self.assertTrue((points.model_matrix == np.array([
[1., 0., 0., 0.],
[0., 2., 0., 0.],
[0., 0., 3., 0.],
[0., 0., 0., 1.]
])).all())
if __name__ == '__main__':
unittest.main()