Example #1
0
def test_property_normal():
    v = Plane(1, 2, 3, 4)
    assert hasattr(v, "normal")
    field_val = v.normal
    assert isinstance(field_val, Vector3)
    for val in (Vector3(), Vector3(0.1, -0.1, 2)):
        v.normal = val
        field_val = v.normal
        assert field_val == val
    for bad in ("dummy", None, b"b"):
        with pytest.raises(TypeError):
            v.normal = bad
Example #2
0
def test_property_d():
    v = Plane(1, 2, 3, 4)
    assert hasattr(v, "d")
    field_val = v.d
    assert isinstance(field_val, (float, int))
    for val in (0.5, -1, 2):
        v.d = val
        field_val = v.d
        assert field_val == val
    for bad in ("dummy", None, b"b"):
        with pytest.raises(TypeError):
            v.d = bad
Example #3
0
def test_repr():
    v = Plane(1, 2, 3, 4)
    assert repr(v) == "<Plane(1, 2, 3, 4)>"
Example #4
0
def test_bad_init_from_vectors(bad_v1, bad_v2, bad_v3):
    with pytest.raises(TypeError):
        Plane.from_vectors(bad_v1, bad_v2, bad_v3)
Example #5
0
def test_init():
    v = Plane(1, 2, 3, 4)
    assert type(v) == Plane
    assert v.normal == Vector3(1, 2, 3)
    assert v.d == 4
Example #6
0
def test_init_from_vectors():
    v = Plane.from_vectors(Vector3(), Vector3(), Vector3())
    assert v.normal == Vector3()
    assert v.d == 0
Example #7
0
def test_bad_init_from_normal(bad_normal, bad_d):
    with pytest.raises(TypeError):
        Plane.from_normal(bad_normal, bad_d)
Example #8
0
def test_init_from_normal(expected_normal, expected_d):
    v = Plane.from_normal(expected_normal, expected_d)
    assert v.normal == expected_normal, msg_tmpl % (v.normal, expected_normal)
    assert v.d == expected_d, msg_tmpl % (v.d, expected_d)
Example #9
0
def test_bad_init(args):
    with pytest.raises(TypeError):
        Plane(*args)
Example #10
0
def test_not_equal(bad):
    arr = Plane(1, 2, 3, 4)
    assert not arr == bad  # Force use of __eq__
    assert arr != bad  # Force use of __ne__
Example #11
0
def test_equal():
    arr = Plane(1, 2, 3, 4)
    same = Plane(1, 2, 3, 4)
    assert arr == same  # Force use of __eq__
    assert not arr != same  # Force use of __ne__
Example #12
0
def test_methods_call_with_none(field, params):
    v = Plane(1, 2, 3, 4)
    method = getattr(v, field)
    with pytest.raises(TypeError):
        method(*params)
Example #13
0
    # Don't test methods' validity but bindings one
    assert hasattr(v, field)
    method = getattr(v, field)
    assert callable(method)
    ret = method(*params)
    assert type(ret) == ret_type


@pytest.mark.parametrize(
    "field,params",
    [
        ["is_point_over", (None, )],
        ["distance_to", (None, )],
        ["has_point", (None, 0.5)],
        ["project", (None, )],
        ["intersect_3", (None, Plane(1, 1, 1, 1))],
        ["intersect_3", (Plane(1, 1, 1, 1), None)],
        ["intersects_ray", (None, Vector3())],
        ["intersects_ray", (Vector3(), None)],
        ["intersects_segment", (None, Vector3())],
        ["intersects_segment", (Vector3(), None)],
    ],
    ids=lambda x: x[0],
)
def test_methods_call_with_none(field, params):
    v = Plane(1, 2, 3, 4)
    method = getattr(v, field)
    with pytest.raises(TypeError):
        method(*params)