def test_v3_add(): xyz = V3(1, 2, 3) * si.meters assert make(V3(2, 4, 6), si.meters).approx(xyz + xyz) with pytest.raises(TypeError): xyz + V3(1, 2, 3)
def test_v3_sub(): xyz = V3(1, 2, 3) * si.meters assert make(V3(0, 0, 0), si.meters).approx(xyz - xyz) with pytest.raises(TypeError): xyz - V3(1, 2, 3)
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_v3_mul(): xyz = V3(1, 2, 3) * si.meters assert make(V3(2, 4, 6), si.meters).approx(xyz * 2) assert make(V3(2, 4, 6), si.meters).approx(2 * xyz) with pytest.raises(TypeError): xyz * xyz
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_angle(): x = V3(1, 0, 0) * si.meters y = V3(0, 1, 0) * si.millimeters assert pytest.approx(eta) == x.angle(y).get_as(si.radians) z = V3(0, 0, 1) * si.meters assert pytest.approx(eta) == x.angle(z).get_as(si.radians)
def test_v3_div(): xyz = V3(2, 4, 6) * si.meters assert make(V3(1, 2, 3), si.meters).approx(xyz / 2) with pytest.raises(TypeError): 2 / xyz with pytest.raises(TypeError): xyz / None
def test_create(): xyz = make(V3(1, 2, 3), si.meters) assert V3(1, 2, 3) * si.meters == xyz assert V3(1, 2, 3) == xyz.get_as(si.meters) assert V3(1000, 2000, 3000) == xyz.get_as(si.millimeters) assert V2(1, 2) * si.meters == xyz.xy() assert V2(2, 3) * si.meters == xyz.yz() assert V2(1, 3) * si.meters == xyz.xz()
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_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_div(): assert V3(1.5, 2.5, 3.5) == V3(3, 5, 7) / 2 with pytest.raises(TypeError): V3(3, 5, 7) / V3(1, 1, 1) assert V3(1, 2, 3) == V3(3, 5, 7) // 2 with pytest.raises(TypeError): V3(3, 5, 7) // V3(1, 1, 1)
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_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_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)
def test_v3_neg(): assert V3(-1, -2, -3) == -V3(1, 2, 3)
def test_cmp(): xyz = V3(1, 2, 3) * si.meters assert not V3(1, 2, 3) == xyz assert not None == xyz
def test_v3_sub(): assert V3(0, 0, 0) == V3(3, 2, 1) - V3(3, 2, 1) with pytest.raises(TypeError): V3(1, 2, 3) - 5
def test_v3_add(): assert V3(2, 3, 4) == V3(1, 2, 3) + V3(1, 1, 1) with pytest.raises(TypeError): V3(1, 2, 3) + 5
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_v3_magnitude(): vector = V3(2, 2, 2) assert 12**0.5 == vector.magnitude() assert 12**0.5 == abs(vector)
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_plane_normal(): plane = Plane(1, 1, 1, 1) assert V3(1, 1, 1).unit() == plane.normal()
def test_v3_cross(): x = V3(1, 0, 0) * si.meters y = V3(0, 1, 0) * si.meters assert make(V3(0, 0, 1), si.meters**2).approx(x.cross(y)) assert make(V3(0, 0, -1), si.meters**2).approx(y.cross(x))
def test_v3_manhattan_distance(): xyz = V3(1, 2, 3) * si.meters assert 6 * si.meters == xyz.manhattan_distance()
def test_v3_magnitude(): xyz = V3(1, 1, 1) * si.meters assert pytest.approx(3**0.5) == xyz.magnitude().get_as(si.meters)
def test_v3_unit(): xyz = V3(1, 2, 3) * si.meters assert pytest.approx(1) == xyz.unit().magnitude().quantity