def test_p3_sub():
    point = P3(1, 2, 3)

    assert P3(0, 1, 2) == point - V3(1, 1, 1)
    assert V3(0, 0, 0) == point - point

    with pytest.raises(TypeError):
        point - 1
def test_p3_add():
    point = P3(1, 2, 3)

    assert P3(2, 3, 4) == point + V3(1, 1, 1)
    assert P3(2, 3, 4) == V3(1, 1, 1) + point

    with pytest.raises(TypeError):
        point + point
def test_plane_contains():
    plane = Plane(1, 1, 1, 0)

    assert plane.contains(P3(0, 0, 0))

    assert plane.contains(P3(-1, 1, 0))
    assert plane.contains(P3(-1, 0, 1))

    with pytest.raises(TypeError):
        plane.contains(V3(0, 0, 0))
def test_p3_approx():
    point = P3(1, 2, 3)

    assert point.approx(P3(1, 2, 3))
    assert point.approx(P3(0.99999999, 1.99999999, 2.99999999))

    assert not point.approx(P3(0.999, 1.999, 2.999))

    with pytest.raises(TypeError):
        point.approx(V3(1, 2, 3))
def test_p3_create():
    point = P3(1, 2, 3)
    assert 1 == point.x
    assert 2 == point.y
    assert 3 == point.z

    assert V3(1, 2, 3) == point.vector()
def test_v3_create():
    vector = V3(1, 2, 3)

    assert 1 == vector.x
    assert 2 == vector.y
    assert 3 == vector.z

    assert V3(1, 2, 3) == vector

    assert P3(1, 2, 3) != vector

    for a, b in zip(vector, [1, 2, 3]):
        assert a == b
def test_v3_dot():
    assert 10 == V3(1, 2, 3).dot(V3(3, 2, 1))
    assert 10 == V3(3, 2, 1).dot(V3(1, 2, 3))

    with pytest.raises(TypeError):
        V3(1, 2, 3).dot(P3(3, 2, 1))
def test_plane_create():
    plane = Plane.PointNormal(P3(0, 0, 0), V3(1, 1, 1))

    assert Plane(1, 1, 1, 0) == plane
    assert None != plane
def test_p3_ordering():

    assert P3(0, 1, 1) < P3(1, 1, 1)
    assert P3(0, 1, 1) < P3(1, 0, 0)
    assert P3(0, 1, 1) < P3(1, -1, -1)

    assert P3(1, 0, 0) < P3(1, 1, 1)
    assert P3(1, 1, 0) < P3(1, 1, 1)

    with pytest.raises(TypeError):
        P3(0, 1, 2) < V3(1, 2, 3)