Пример #1
0
 def test_methods(self, args):
     v = Quat()
     # Don't test methods' validity but bindings one
     field, ret_type, params = args
     assert hasattr(v, field)
     method = getattr(v, field)
     assert callable(method)
     ret = method(*params)
     assert type(ret) == ret_type
Пример #2
0
 def test_properties(self, args):
     v = Quat()
     field, ret_type = args
     assert hasattr(v, field)
     field_val = getattr(v, field)
     assert type(field_val) == ret_type
     for val in (0, 10, 10., 42.5):
         setattr(v, field, val)
         field_val = getattr(v, field)
         assert pytest.approx(field_val) == val
Пример #3
0
 def test_instantiate(self, args):
     # Can build it with int or float or nothing
     msg_tmpl = "%s vs (expected) %s (args=%s)"
     args, expected_x, expected_y, expected_z, expected_w = args
     v = Quat(*args)
     assert pytest.approx(
         v.x) == expected_x, msg_tmpl % (v.x, expected_x, args)
     assert pytest.approx(
         v.y) == expected_y, msg_tmpl % (v.y, expected_y, args)
     assert pytest.approx(
         v.z) == expected_z, msg_tmpl % (v.z, expected_z, args)
     assert pytest.approx(
         v.w) == expected_w, msg_tmpl % (v.w, expected_w, args)
Пример #4
0
 def test_unary(self):
     v = Quat(1, 2, 3, 4)
     v2 = -v
     assert v2.x == -1
     assert v2.y == -2
     assert v2.z == -3
     assert v2.w == -4
     v3 = +v
     assert v3.x == 1
     assert v3.y == 2
     assert v3.z == 3
     assert v3.w == 4
     v = Quat(1.5, 2.5, 3.5, 4.5)
     v2 = -v
     assert v2.x == -1.5
     assert v2.y == -2.5
     assert v2.z == -3.5
     assert v2.w == -4.5
     v3 = +v
     assert v3.x == 1.5
     assert v3.y == 2.5
     assert v2.z == -3.5
     assert v2.w == -4.5
Пример #5
0
 def test_bad_instantiate(self):
     with pytest.raises(TypeError):
         Quat("a", 2, 3, 4)
     with pytest.raises(TypeError):
         Quat(1, "b", 2, 4)
     with pytest.raises(TypeError):
         Quat(1, 2, "c", 4)
     with pytest.raises(TypeError):
         Quat(1, 2, 3, "d")
     with pytest.raises(TypeError):
         Quat(None, 2, 3, 4)
     with pytest.raises(TypeError):
         Quat(1, None, 2, 4)
     with pytest.raises(TypeError):
         Quat(1, 2, None, 4)
     with pytest.raises(TypeError):
         Quat(1, 2, 3, None)
Пример #6
0
 def test_bad_div(self, arg):
     with pytest.raises(TypeError):
         Quat(2, 3, 4, 5) / arg
Пример #7
0
 def test_equal(self):
     arr = Quat(0.1, 1, 2, 3)
     other = Quat(0.1, 1, 2, 3)
     assert arr == other
     bad = Quat(0.1, 1, 2, 4)
     assert not arr == bad  # Force use of __eq__
Пример #8
0
 def test_bad_equal(self, arg):
     arr = Quat(0.1, 1, 2, 3)
     assert arr != arg
Пример #9
0
 def test_div(self, args):
     param, result = args
     calc = Quat(2, 3, 4, 5) / param
     assert calc == result
Пример #10
0
 def test_bad_properties(self, args):
     v = Quat()
     field, bad_value = args
     with pytest.raises(TypeError):
         setattr(v, field, bad_value)
Пример #11
0
class TestBasis:
    def test_equal(self):
        basis1 = Basis.build_from_euler(Vector3(1, 2, 3))
        basis2 = Basis.build_from_euler(Vector3(1, 2, 3))
        assert basis1 == basis2
        basis2.x = Vector3(1, 2, 3)
        assert basis1 != basis2
        basis1.x = Vector3(1, 2, 3)
        assert basis1 == basis2
        bad = Basis.build_from_euler(Vector3(1, 2, 4))
        assert not basis1 == bad  # Force use of __eq__

    @pytest.mark.parametrize('arg', [
        None,
        0,
        'foo',
        Basis.build_from_euler(Vector3(1, 2, 4)),
    ])
    def test_bad_equal(self, arg):
        basis = Basis.build_from_euler(Vector3(1, 2, 3))
        assert basis != arg

    def test_repr(self):
        args = (Vector3(1, 2, 3), Vector3(4, 5, 6), Vector3(7, 8, 9))
        v = Basis.build_from_rows(*args)
        assert repr(
            v) == '<Basis((1.0, 4.0, 7.0), (2.0, 5.0, 8.0), (3.0, 6.0, 9.0))>'

    def test_default_instanciate(self):
        v = Basis()
        assert isinstance(v, Basis)

    def test_build_from_rows(self):
        args = (Vector3(1, 2, 3), Vector3(4, 5, 6), Vector3(7, 8, 9))
        v = Basis.build_from_rows(*args)
        assert isinstance(v, Basis)
        assert (v.x, v.y, v.z) == (Vector3(1, 4,
                                           7), Vector3(2, 5,
                                                       8), Vector3(3, 6, 9))

    @pytest.mark.parametrize('args',
                             [(), (Vector3(), Vector3()),
                              (Vector3(), Vector3(), Vector3(), Vector3()),
                              (1, Vector3(), Vector3()),
                              (Vector3(), 'foo', Vector3())])
    def test_bad_build_from_rows(self, args):
        with pytest.raises(TypeError):
            Basis.build_from_rows(*args)

    def test_build_from_euler_vector3(self):
        v = Basis.build_from_euler(Vector3(1, 2, 3))
        assert isinstance(v, Basis)

    def test_build_from_euler_quat(self):
        v = Basis.build_from_euler(Quat(1, 2, 3, 4))
        assert isinstance(v, Basis)

    @pytest.mark.parametrize('args', [(), (Quat(), Quat()),
                                      (Vector3(), Vector3()), (1, ), (None, )])
    def test_bad_build_from_euler(self, args):
        with pytest.raises(TypeError):
            Basis.build_from_euler(*args)

    @classmethod
    def test_build_from_axis_and_angle(axis, phi):
        v = Basis.build_from_euler(Vector3(1, 2, 3), 0.5)
        assert isinstance(v, Vector3)

    @pytest.mark.parametrize('args', [(), (Vector3(), 0.5, Vector3()),
                                      (Vector3()), (0.5, Vector3()), (1, ),
                                      (None, )])
    def test_bad_build_from_axis_and_angle(self, args):
        with pytest.raises(TypeError):
            Basis.build_from_axis_and_angle(*args)

    @pytest.mark.parametrize('args', [
        ['determinant', float, ()],
        ['get_euler', Vector3, ()],
        ['get_orthogonal_index', int, ()],
        ['get_scale', Vector3, ()],
        ['inverse', Basis, ()],
        ['orthonormalized', Basis, ()],
        ['rotated', Basis, (Vector3(), 0.5)],
        ['scaled', Basis, (Vector3(), )],
        ['tdotx', float, (Vector3(), )],
        ['tdoty', float, (Vector3(), )],
        ['tdotz', float, (Vector3(), )],
        ['transposed', Basis, ()],
        ['xform', Vector3, (Vector3(), )],
        ['xform_inv', Vector3, (Vector3(), )],
    ],
                             ids=lambda x: x[0])
    def test_methods(self, args):
        v = Basis()
        # Don't test methods' validity but bindings one
        field, ret_type, params = args
        assert hasattr(v, field)
        method = getattr(v, field)
        assert callable(method)
        ret = method(*params)
        assert isinstance(ret, ret_type)

    @pytest.mark.parametrize('args', [
        ('x', Vector3),
        ('y', Vector3),
        ('z', Vector3),
    ],
                             ids=lambda x: x[0])
    def test_properties(self, args):
        v = Basis()
        field, ret_type = args
        assert hasattr(v, field)
        field_val = getattr(v, field)
        assert isinstance(field_val, ret_type)
        val = Vector3(1, 2, 3)
        setattr(v, field, val)
        field_val = getattr(v, field)
        assert field_val == val

    @pytest.mark.parametrize('args', [
        ('x', 'Not a Vector3'),
        ('y', 'Not a Vector3'),
        ('z', 'Not a Vector3'),
        ('x', 1),
        ('y', 2),
        ('z', 3),
    ],
                             ids=lambda x: x[0])
    def test_bad_properties(self, args):
        v = Basis()
        field, bad_value = args
        with pytest.raises(TypeError):
            setattr(v, field, bad_value)

    @pytest.mark.parametrize('args', [
        ('AXIS_X', int),
        ('AXIS_Y', int),
        ('AXIS_Z', int),
    ],
                             ids=lambda x: x[0])
    def test_contants(self, args):
        v = Basis()
        field, ret_type = args
        assert hasattr(v, field)
        field_val = getattr(v, field)
        assert isinstance(field_val, ret_type)
Пример #12
0
 def test_repr(self):
     v = Quat(1.0, 2.0, 3.0, 4.0)
     assert repr(v) == '<Quat(x=1.0, y=2.0, z=3.0, w=4.0)>'
Пример #13
0
 def test_add(self, args):
     param, result = args
     calc = Quat(2, 3, 4, 5) + param
     assert calc == result
Пример #14
0
class TestQuat:
    def test_base(self):
        v = Quat()
        assert type(v) == Quat

    def test_repr(self):
        v = Quat(1.0, 2.0, 3.0, 4.0)
        assert repr(v) == '<Quat(x=1.0, y=2.0, z=3.0, w=4.0)>'

    @pytest.mark.parametrize('args', [
        [(), 0, 0, 0, 0],
        [(0.1, 0.2, 0.3, 0.4), 0.1, 0.2, 0.3, 0.4],
        [(1, 2, 3), 1, 2, 3, 0],
        [(1, ), 1, 0, 0, 0],
    ])
    def test_instantiate(self, args):
        # Can build it with int or float or nothing
        msg_tmpl = "%s vs (expected) %s (args=%s)"
        args, expected_x, expected_y, expected_z, expected_w = args
        v = Quat(*args)
        assert pytest.approx(
            v.x) == expected_x, msg_tmpl % (v.x, expected_x, args)
        assert pytest.approx(
            v.y) == expected_y, msg_tmpl % (v.y, expected_y, args)
        assert pytest.approx(
            v.z) == expected_z, msg_tmpl % (v.z, expected_z, args)
        assert pytest.approx(
            v.w) == expected_w, msg_tmpl % (v.w, expected_w, args)

    def test_bad_instantiate(self):
        with pytest.raises(TypeError):
            Quat("a", 2, 3, 4)
        with pytest.raises(TypeError):
            Quat(1, "b", 2, 4)
        with pytest.raises(TypeError):
            Quat(1, 2, "c", 4)
        with pytest.raises(TypeError):
            Quat(1, 2, 3, "d")
        with pytest.raises(TypeError):
            Quat(None, 2, 3, 4)
        with pytest.raises(TypeError):
            Quat(1, None, 2, 4)
        with pytest.raises(TypeError):
            Quat(1, 2, None, 4)
        with pytest.raises(TypeError):
            Quat(1, 2, 3, None)

    @pytest.mark.parametrize('args', [
        ['length', float, ()],
        ['length_squared', float, ()],
        ['normalized', Quat, ()],
        ['is_normalized', bool, ()],
        ['inverse', Quat, ()],
        ['dot', float, (Quat(), )],
        ['xform', Vector3, (Vector3(), )],
        ['slerp', Quat, (Quat(), 1.0)],
        ['slerpni', Quat, (Quat(), 1.0)],
        ['cubic_slerp', Quat, (Quat(), Quat(), Quat(), 1.0)],
    ],
                             ids=lambda x: x[0])
    def test_methods(self, args):
        v = Quat()
        # Don't test methods' validity but bindings one
        field, ret_type, params = args
        assert hasattr(v, field)
        method = getattr(v, field)
        assert callable(method)
        ret = method(*params)
        assert type(ret) == ret_type

    @pytest.mark.parametrize('args', [
        ('x', float),
        ('y', float),
        ('z', float),
        ('w', float),
    ],
                             ids=lambda x: x[0])
    def test_properties(self, args):
        v = Quat()
        field, ret_type = args
        assert hasattr(v, field)
        field_val = getattr(v, field)
        assert type(field_val) == ret_type
        for val in (0, 10, 10., 42.5):
            setattr(v, field, val)
            field_val = getattr(v, field)
            assert pytest.approx(field_val) == val

    @pytest.mark.parametrize('args', [
        ('x', 'NaN'),
        ('y', 'NaN'),
        ('z', 'NaN'),
        ('w', 'NaN'),
    ],
                             ids=lambda x: x[0])
    def test_bad_properties(self, args):
        v = Quat()
        field, bad_value = args
        with pytest.raises(TypeError):
            setattr(v, field, bad_value)

    def test_unary(self):
        v = Quat(1, 2, 3, 4)
        v2 = -v
        assert v2.x == -1
        assert v2.y == -2
        assert v2.z == -3
        assert v2.w == -4
        v3 = +v
        assert v3.x == 1
        assert v3.y == 2
        assert v3.z == 3
        assert v3.w == 4
        v = Quat(1.5, 2.5, 3.5, 4.5)
        v2 = -v
        assert v2.x == -1.5
        assert v2.y == -2.5
        assert v2.z == -3.5
        assert v2.w == -4.5
        v3 = +v
        assert v3.x == 1.5
        assert v3.y == 2.5
        assert v2.z == -3.5
        assert v2.w == -4.5

    @pytest.mark.parametrize('args', [
        (Quat(0, 0, 0, 0), Quat(2, 3, 4, 5)),
        (Quat(4, 3, 2, 1), Quat(6, 6, 6, 6)),
        (Quat(-4, -3, -2, -1), Quat(-2, -0, 2, 4)),
    ],
                             ids=lambda x: x[0])
    def test_add(self, args):
        param, result = args
        calc = Quat(2, 3, 4, 5) + param
        assert calc == result

    @pytest.mark.parametrize('args', [
        (Quat(0, 0, 0, 0), Quat(2, 3, 4, 5)),
        (Quat(5, 4, 3, 2), Quat(-3, -1, 1, 3)),
        (Quat(-1, -1, -1, -1), Quat(3, 4, 5, 6)),
    ],
                             ids=lambda x: x[0])
    def test_sub(self, args):
        param, result = args
        calc = Quat(2, 3, 4, 5) - param
        assert calc == result

    @pytest.mark.parametrize('arg', [None, 1, 'dummy'], ids=lambda x: x[0])
    def test_bad_add(self, arg):
        with pytest.raises(TypeError):
            Quat(2, 3, 4, 5) + arg

    @pytest.mark.parametrize('arg', [None, 1, 'dummy'], ids=lambda x: x[0])
    def test_bad_sub(self, arg):
        with pytest.raises(TypeError):
            Quat(2, 3, 4, 5) - arg

    @pytest.mark.parametrize('arg',
                             [None, 'dummy', Quat(1, 1, 1, 1)],
                             ids=lambda x: x[0])
    def test_bad_div(self, arg):
        with pytest.raises(TypeError):
            Quat(2, 3, 4, 5) / arg

    def test_zero_div(self):
        with pytest.raises(ZeroDivisionError):
            Quat(2, 3, 4, 5) / 0

    @pytest.mark.parametrize('arg', [None, 'dummy'], ids=lambda x: x[0])
    def test_bad_mul(self, arg):
        with pytest.raises(TypeError):
            Quat(2, 3, 4, 5) * arg

    @pytest.mark.parametrize('args', [
        (0, Quat(0, 0, 0, 0)),
        (1, Quat(2, 3, 4, 5)),
        (2.5, Quat(5, 7.5, 10, 12.5)),
    ],
                             ids=lambda x: x[0])
    def test_mul(self, args):
        param, result = args
        calc = Quat(2, 3, 4, 5) * param
        assert calc == result

    @pytest.mark.parametrize('args', [
        (1, Quat(2, 3, 4, 5)),
        (.5, Quat(4, 6, 8, 10)),
        (2, Quat(1, 1.5, 2, 2.5)),
    ],
                             ids=lambda x: x[0])
    def test_div(self, args):
        param, result = args
        calc = Quat(2, 3, 4, 5) / param
        assert calc == result

    def test_equal(self):
        arr = Quat(0.1, 1, 2, 3)
        other = Quat(0.1, 1, 2, 3)
        assert arr == other
        bad = Quat(0.1, 1, 2, 4)
        assert not arr == bad  # Force use of __eq__

    @pytest.mark.parametrize('arg', [
        None,
        0,
        'foo',
        Quat(0.1, 1, 2, 4),
    ])
    def test_bad_equal(self, arg):
        arr = Quat(0.1, 1, 2, 3)
        assert arr != arg

    @pytest.mark.xfail
    def test_build_with_axis_angle(self):
        pass
Пример #15
0
 def test_bad_sub(self, arg):
     with pytest.raises(TypeError):
         Quat(2, 3, 4, 5) - arg
Пример #16
0
 def test_bad_add(self, arg):
     with pytest.raises(TypeError):
         Quat(2, 3, 4, 5) + arg
Пример #17
0
 def test_sub(self, args):
     param, result = args
     calc = Quat(2, 3, 4, 5) - param
     assert calc == result
Пример #18
0
 def test_base(self):
     v = Quat()
     assert type(v) == Quat
Пример #19
0
 def test_zero_div(self):
     with pytest.raises(ZeroDivisionError):
         Quat(2, 3, 4, 5) / 0
Пример #20
0
 def test_bad_mul(self, arg):
     with pytest.raises(TypeError):
         Quat(2, 3, 4, 5) * arg
Пример #21
0
 def test_mul(self, args):
     param, result = args
     calc = Quat(2, 3, 4, 5) * param
     assert calc == result
Пример #22
0
 def test_build_from_euler_quat(self):
     v = Basis.build_from_euler(Quat(1, 2, 3, 4))
     assert isinstance(v, Basis)
Пример #23
0
class TestBasis:
    def test_default(self):
        basis = Basis()
        assert basis.x == Vector3(1, 0, 0)
        assert basis.y == Vector3(0, 1, 0)
        assert basis.z == Vector3(0, 0, 1)

    def test_equal(self):
        basis1 = Basis.build_from_euler(Vector3(1, 2, 3))
        basis2 = Basis.build_from_euler(Vector3(1, 2, 3))
        assert basis1 == basis2
        basis2.x = Vector3(1, 2, 3)
        assert basis1 != basis2
        basis1.x = Vector3(1, 2, 3)
        assert basis1 == basis2
        bad = Basis.build_from_euler(Vector3(1, 2, 4))
        assert not basis1 == bad  # Force use of __eq__

    @pytest.mark.parametrize(
        "arg", [None, 0, "foo", Basis.build_from_euler(Vector3(1, 2, 4))]
    )
    def test_bad_equal(self, arg):
        basis = Basis.build_from_euler(Vector3(1, 2, 3))
        assert basis != arg

    def test_repr(self):
        args = (Vector3(1, 2, 3), Vector3(4, 5, 6), Vector3(7, 8, 9))
        v = Basis.build_from_rows(*args)
        assert repr(v) == "<Basis((1.0, 4.0, 7.0), (2.0, 5.0, 8.0), (3.0, 6.0, 9.0))>"

    def test_default_instanciate(self):
        v = Basis()
        assert isinstance(v, Basis)

    def test_build_from_rows(self):
        args = (Vector3(1, 2, 3), Vector3(4, 5, 6), Vector3(7, 8, 9))
        v = Basis.build_from_rows(*args)
        assert isinstance(v, Basis)
        assert (v.x, v.y, v.z) == (Vector3(1, 4, 7), Vector3(2, 5, 8), Vector3(3, 6, 9))

    @pytest.mark.parametrize(
        "args",
        [
            (),
            (Vector3(), Vector3()),
            (Vector3(), Vector3(), Vector3(), Vector3()),
            (1, Vector3(), Vector3()),
            (Vector3(), "foo", Vector3()),
        ],
    )
    def test_bad_build_from_rows(self, args):
        with pytest.raises(TypeError):
            Basis.build_from_rows(*args)

    def test_build_from_euler_vector3(self):
        v = Basis.build_from_euler(Vector3(1, 2, 3))
        assert isinstance(v, Basis)

    def test_build_from_euler_quat(self):
        v = Basis.build_from_euler(Quat(1, 2, 3, 4))
        assert isinstance(v, Basis)

    @pytest.mark.parametrize(
        "args", [(), (Quat(), Quat()), (Vector3(), Vector3()), (1,), (None,)]
    )
    def test_bad_build_from_euler(self, args):
        with pytest.raises(TypeError):
            Basis.build_from_euler(*args)

    @classmethod
    def test_build_from_axis_and_angle(axis, phi):
        v = Basis.build_from_euler(Vector3(1, 2, 3), 0.5)
        assert isinstance(v, Vector3)

    @pytest.mark.parametrize(
        "args",
        [(), (Vector3(), 0.5, Vector3()), (Vector3()), (0.5, Vector3()), (1,), (None,)],
    )
    def test_bad_build_from_axis_and_angle(self, args):
        with pytest.raises(TypeError):
            Basis.build_from_axis_and_angle(*args)

    @pytest.mark.parametrize(
        "args",
        [
            ["determinant", float, ()],
            ["get_euler", Vector3, ()],
            ["get_orthogonal_index", int, ()],
            ["get_scale", Vector3, ()],
            ["inverse", Basis, ()],
            ["orthonormalized", Basis, ()],
            ["rotated", Basis, (Vector3(), 0.5)],
            ["scaled", Basis, (Vector3(),)],
            ["tdotx", float, (Vector3(),)],
            ["tdoty", float, (Vector3(),)],
            ["tdotz", float, (Vector3(),)],
            ["transposed", Basis, ()],
            ["xform", Vector3, (Vector3(),)],
            ["xform_inv", Vector3, (Vector3(),)],
        ],
        ids=lambda x: x[0],
    )
    def test_methods(self, args):
        v = Basis()
        # Don't test methods' validity but bindings one
        field, ret_type, params = args
        assert hasattr(v, field)
        method = getattr(v, field)
        assert callable(method)
        ret = method(*params)
        assert isinstance(ret, ret_type)

    @pytest.mark.parametrize(
        "args", [("x", Vector3), ("y", Vector3), ("z", Vector3)], ids=lambda x: x[0]
    )
    def test_properties(self, args):
        v = Basis()
        field, ret_type = args
        assert hasattr(v, field)
        field_val = getattr(v, field)
        assert isinstance(field_val, ret_type)
        val = Vector3(1, 2, 3)
        setattr(v, field, val)
        field_val = getattr(v, field)
        assert field_val == val

    @pytest.mark.parametrize(
        "args",
        [
            ("x", "Not a Vector3"),
            ("y", "Not a Vector3"),
            ("z", "Not a Vector3"),
            ("x", 1),
            ("y", 2),
            ("z", 3),
        ],
        ids=lambda x: x[0],
    )
    def test_bad_properties(self, args):
        v = Basis()
        field, bad_value = args
        with pytest.raises(TypeError):
            setattr(v, field, bad_value)

    @pytest.mark.parametrize(
        "args", [("AXIS_X", int), ("AXIS_Y", int), ("AXIS_Z", int)], ids=lambda x: x[0]
    )
    def test_contants(self, args):
        v = Basis()
        field, ret_type = args
        assert hasattr(v, field)
        field_val = getattr(v, field)
        assert isinstance(field_val, ret_type)