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
|
# Copyright (c) 2020, Manfred Moitzi
# License: MIT License
# Test only basic features of Cython implementation,
# Full testing and compatibility check with Python implementation
# is located in test suite 602.
import pytest
cyvec = pytest.importorskip("ezdxf.acc.vector")
Vec3 = cyvec.Vec3
def test_default_constructor():
v = Vec3()
assert v.x == 0
assert v.y == 0
assert v.z == 0
def test_is_immutable():
v = Vec3()
with pytest.raises(AttributeError):
v.x = 1
with pytest.raises(AttributeError):
v.y = 1
with pytest.raises(AttributeError):
v.z = 1
def test_init_x_y():
v = Vec3(1, 2, 3)
assert v.x == 1
assert v.y == 2
assert v.z == 3
def test_init_2_tuple():
v = Vec3((1, 2))
assert v.x == 1
assert v.y == 2
assert v.z == 0
def test_init_vec2():
v = Vec3(cyvec.Vec2(1, 2))
assert v.x == 1
assert v.y == 2
assert v.z == 0
def test_init_3_tuple():
v = Vec3((1, 2, 3))
assert v.x == 1
assert v.y == 2
assert v.z == 3
def test_init_vec3():
v = Vec3(Vec3(1, 2, 3))
assert v.x == 1
assert v.y == 2
assert v.z == 3
def test_init_type_error():
with pytest.raises(TypeError):
Vec3(1)
with pytest.raises(TypeError):
Vec3(1, 2, 3, 4)
with pytest.raises(TypeError):
Vec3("xyz")
with pytest.raises(TypeError):
Vec3("xyz", "abc")
def test_is_null():
assert Vec3().is_null is True
def test_bool():
assert bool(Vec3(1, 0)) is True
def test_compare():
assert Vec3(1, 2, 3) == Vec3(1, 2, 3)
assert Vec3(1, 2, 3) == (1, 2, 3)
assert (1, 2) == Vec3(1, 2)
assert Vec3(1, 2, 3) != (
1,
2.0000000000001,
3,
), "__eq__() should use the full floating point precision"
assert Vec3(1, 2) != (2, 1)
def test_lower_than():
assert Vec3(1, 2) < Vec3(2, 2)
assert Vec3(2, 2) > Vec3(1, 2)
def test_does_not_support_slicing():
with pytest.raises(TypeError):
_ = Vec3(2, 1)[:]
if __name__ == "__main__":
pytest.main([__file__])
|