File: test_rectangle.py

package info (click to toggle)
pyrr 0.10.3-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 956 kB
  • sloc: python: 5,865; makefile: 132; sh: 23
file content (134 lines) | stat: -rw-r--r-- 4,754 bytes parent folder | download
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
try:
    import unittest2 as unittest
except:
    import unittest
import numpy as np
from pyrr import rectangle


class test_rectangle(unittest.TestCase):
    def test_import(self):
        import pyrr
        pyrr.rectangle
        from pyrr import rectangle

    def test_create(self):
        result = rectangle.create()
        np.testing.assert_almost_equal(result, [[0,0],[1,1]], decimal=5)

    def test_create_dtype(self):
        result = rectangle.create(dtype=np.float64)
        np.testing.assert_almost_equal(result, [[0.,0.],[1.,1.]], decimal=5)

    def test_create_zeros(self):
        result = rectangle.create_zeros()
        np.testing.assert_almost_equal(result, [[0,0],[0,0]], decimal=5)

    def test_create_from_bounds(self):
        result = rectangle.create_from_bounds(-1, 1, -2, 2)
        np.testing.assert_almost_equal(result, [[-1,-2],[2,4]], decimal=5)

    def test_bounds(self):
        rect = rectangle.create_from_bounds(-1, 1, -2, 2)
        result = rectangle.bounds(rect)
        np.testing.assert_almost_equal(result, (-1,1,-2,2), decimal=5)

    def test_scale_by_vector(self):
        result = rectangle.scale_by_vector([[-1.,-2.],[2.,4.]], [2.,3.])
        np.testing.assert_almost_equal(result, [[-2.,-6.],[4.,12.]], decimal=5)

    def test_scale_by_vector3(self):
        result = rectangle.scale_by_vector([[-1.,-2.],[2.,4.]], [2.,3.,4.])
        np.testing.assert_almost_equal(result, [[-2.,-6.],[4.,12.]], decimal=5)

    def test_right(self):
        result = rectangle.right([[1.,2.],[3.,4.]])
        np.testing.assert_almost_equal(result, 4., decimal=5)

    def test_right_negative(self):
        result = rectangle.right([[1.,2.],[-3.,-4.]])
        np.testing.assert_almost_equal(result, 1., decimal=5)

    def test_left(self):
        result = rectangle.left([[1.,2.],[3.,4.]])
        np.testing.assert_almost_equal(result, 1., decimal=5)

    def test_left_negative(self):
        result = rectangle.left([[1.,2.],[-3.,-4.]])
        np.testing.assert_almost_equal(result, -2., decimal=5)

    def test_top(self):
        result = rectangle.top([[1.,2.],[3.,4.]])
        np.testing.assert_almost_equal(result, 6., decimal=5)

    def test_top_negative(self):
        result = rectangle.top([[1.,2.],[-3.,-4.]])
        np.testing.assert_almost_equal(result, 2., decimal=5)

    def test_bottom(self):
        result = rectangle.bottom([[1.,2.],[3.,4.]])
        np.testing.assert_almost_equal(result, 2., decimal=5)

    def test_bottom_negative(self):
        result = rectangle.bottom([[1.,2.],[-3.,-4.]])
        np.testing.assert_almost_equal(result, -2., decimal=5)

    def test_x(self):
        result = rectangle.x([[1.,2.],[3.,4.]])
        np.testing.assert_almost_equal(result, 1., decimal=5)

    def test_x_negative(self):
        result = rectangle.x([[1.,2.],[-3.,-4.]])
        np.testing.assert_almost_equal(result, 1., decimal=5)

    def test_y(self):
        result = rectangle.y([[1.,2.],[3.,4.]])
        np.testing.assert_almost_equal(result, 2., decimal=5)

    def test_y_negative(self):
        result = rectangle.y([[1.,2.],[-3.,-4.]])
        np.testing.assert_almost_equal(result, 2., decimal=5)

    def test_width(self):
        result = rectangle.width([[1.,2.],[3.,4.]])
        np.testing.assert_almost_equal(result, 3., decimal=5)

    def test_width_negative(self):
        result = rectangle.width([[1.,2.],[-3.,-4.]])
        np.testing.assert_almost_equal(result, -3., decimal=5)

    def test_height(self):
        result = rectangle.height([[1.,2.],[3.,4.]])
        np.testing.assert_almost_equal(result, 4., decimal=5)

    def test_height_negative(self):
        result = rectangle.height([[1.,2.],[-3.,-4.]])
        np.testing.assert_almost_equal(result, -4., decimal=5)

    def test_abs_height(self):
        result = rectangle.abs_height([[1.,2.],[3.,4.]])
        np.testing.assert_almost_equal(result, 4., decimal=5)

    def test_abs_height_negative(self):
        result = rectangle.abs_height([[1.,2.],[-3.,-4.]])
        np.testing.assert_almost_equal(result, 4., decimal=5)

    def test_abs_width(self):
        result = rectangle.abs_width([[1.,2.],[3.,4.]])
        np.testing.assert_almost_equal(result, 3., decimal=5)

    def test_abs_width_negative(self):
        result = rectangle.abs_width([[1.,2.],[-3.,-4.]])
        np.testing.assert_almost_equal(result, 3., decimal=5)

    def test_position(self):
        result = rectangle.position([[1.,2.],[-3.,-4.]])
        np.testing.assert_almost_equal(result, [1.,2.], decimal=5)

    def test_size(self):
        result = rectangle.size([[1.,2.],[-3.,-4.]])
        np.testing.assert_almost_equal(result, [-3.,-4.], decimal=5)

    
if __name__ == '__main__':
    unittest.main()