python_arango_ogm.utils.test_math_util

 1import pytest
 2
 3from python_arango_ogm.utils.math_util import Vector2d, Rect2d, lerp
 4
 5
 6def test_vector():
 7    v1 = Vector2d(3, 4)
 8    v2 = Vector2d((3, 4,))
 9    assert v1 == v2
10
11
12def test_vector_decomposition():
13    x, y = Vector2d(21, 12)
14    assert x == 21
15    assert y == 12
16
17
18def test_rect():
19    size = Vector2d(21, 12)
20    origin = Vector2d(2, 1)
21    rect = Rect2d(origin, size)
22    assert rect == Rect2d(2, 1, 21, 12)
23    assert rect.origin == Vector2d(2, 1)
24    assert rect.size == Vector2d(21, 12)
25    assert rect.right == 23
26    assert rect.bottom == 13
27
28
29def test_rect_decomposition():
30    rect = Rect2d(2, 1, 21, 12)
31    x, y, w, h = rect
32    assert x == 2
33    assert y == 1
34    assert w == 21
35    assert h == 12
36
37
38def test_lerp():
39    r = lerp(.5, 7.5, 8.0)
40    assert r == 7.75
41    with pytest.raises(ValueError):
42        r = lerp(.5, 2112, 2021)
def test_vector():
 7def test_vector():
 8    v1 = Vector2d(3, 4)
 9    v2 = Vector2d((3, 4,))
10    assert v1 == v2
def test_vector_decomposition():
13def test_vector_decomposition():
14    x, y = Vector2d(21, 12)
15    assert x == 21
16    assert y == 12
def test_rect():
19def test_rect():
20    size = Vector2d(21, 12)
21    origin = Vector2d(2, 1)
22    rect = Rect2d(origin, size)
23    assert rect == Rect2d(2, 1, 21, 12)
24    assert rect.origin == Vector2d(2, 1)
25    assert rect.size == Vector2d(21, 12)
26    assert rect.right == 23
27    assert rect.bottom == 13
def test_rect_decomposition():
30def test_rect_decomposition():
31    rect = Rect2d(2, 1, 21, 12)
32    x, y, w, h = rect
33    assert x == 2
34    assert y == 1
35    assert w == 21
36    assert h == 12
def test_lerp():
39def test_lerp():
40    r = lerp(.5, 7.5, 8.0)
41    assert r == 7.75
42    with pytest.raises(ValueError):
43        r = lerp(.5, 2112, 2021)