File: test_901_acc_vec2.py

package info (click to toggle)
ezdxf 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 104,528 kB
  • sloc: python: 182,341; makefile: 116; lisp: 20; ansic: 4
file content (124 lines) | stat: -rw-r--r-- 2,403 bytes parent folder | download | duplicates (2)
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
#  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 603.

import pytest
import math

cyvec = pytest.importorskip("ezdxf.acc.vector")
Vec2 = cyvec.Vec2


def test_default_constructor():
    v = Vec2()
    assert v.x == 0
    assert v.y == 0


def test_is_immutable():
    v = Vec2()
    with pytest.raises(AttributeError):
        v.x = 1
    with pytest.raises(AttributeError):
        v.y = 1


def test_init_x_y():
    v = Vec2(1, 2)
    assert v.x == 1
    assert v.y == 2


def test_init_2_tuple():
    v = Vec2((1, 2))
    assert v.x == 1
    assert v.y == 2


def test_init_vec2():
    v = Vec2(Vec2(1, 2))
    assert v.x == 1
    assert v.y == 2


def test_init_3_tuple():
    v = Vec2((1, 2, 3))
    assert v.x == 1
    assert v.y == 2


def test_init_vec3():
    v = Vec2(cyvec.Vec3(1, 2, 3))
    assert v.x == 1
    assert v.y == 2


def test_init_type_error():
    with pytest.raises(TypeError):
        Vec2(1)
    with pytest.raises(TypeError):
        Vec2(1, 2, 3, 4)
    with pytest.raises(TypeError):
        Vec2("xyz")
    with pytest.raises(TypeError):
        Vec2("xyz", "abc")


def test_compare():
    assert Vec2(1, 2) == Vec2(1, 2)
    assert Vec2(1, 2) == (1, 2)
    assert (1, 2) == Vec2(1, 2)
    assert Vec2(1, 2) != (
        1,
        2.0000000000001,
    ), "__eq__() should use the full floating point precision"
    assert Vec2(1, 2) != (2, 1)


def test_lower_than():
    assert Vec2(1, 2) < Vec2(2, 2)
    assert Vec2(2, 2) > Vec2(1, 2)


def test_is_null():
    assert Vec2().is_null is True


def test_bool():
    assert bool(Vec2()) is False


def test_does_not_support_slicing():
    with pytest.raises(TypeError):
        _ = Vec2(2, 1)[:]


@pytest.mark.parametrize(
    "angle", [90, -90, 600, -600, 0.0, 360.0, -360.0, 720.0, -720.0]
)
def test_normalize_deg_angle(angle):
    assert cyvec._normalize_deg_angle(angle) == angle % 360.0


@pytest.mark.parametrize(
    "angle",
    [
        3.0,
        -3.0,
        10.0,
        -10.0,
        0.0,
        math.tau,
        -math.tau,
        2 * math.tau,
        -2 * math.tau,
    ],
)
def test_normalize_rad_angle(angle):
    assert cyvec._normalize_rad_angle(angle) == angle % math.tau


if __name__ == "__main__":
    pytest.main([__file__])