def test__sphere_equal__given_two_not_equal_spheres__return_false(): assert (Sphere(center=Point( (1, 2, 3)), radius=5) == Sphere(center=Point( (1, 2, 3)), radius=6)) is False assert (Sphere(center=Point( (1, 2, 3)), radius=5) == Sphere(center=Point( (3, 5, 6)), radius=5)) is False
def test__intersect_ray_with_sphere__two_point_intersection(): R = Ray(Point((0, 0, 2)), Vector( (1, 0, 0))) #ray passing through the sphere S = Sphere(Point((0, 0, 0)), 3) val = np.sqrt(5) assert (_intersect_ray_with_sphere(R, S) == (Point( (val, 0, 2)), Point((-val, 0, 2)))) is True
def test_intersect_ray_with_sphere_false(): r1 = Ray((0, 0, 0), (1, 1, 1)) s1 = Sphere((10, 10, 10), 5) d, intercepts = intersect(r1, s1) intercepts_analytical = [Point([5.0, 0.0, 0.0]), Point([-5.0, 0.0, 0.0])] d_analytical = 2 assert ((intercepts == intercepts_analytical) and (d_analytical == d)) is False
def test__intersect__ray_not_intersect_with_sphere__return_true(): r1 = Ray((100, 100, 100), (200, 200, 100)) s1 = Sphere((0, 0, 0), 5) d, intersections = intersect(r1, s1) calculated_intersections = [0] d_analytical = 0 assert ((intersections == calculated_intersections) and (d_analytical == d)) is True
def test__intersect_ray_with_sphere_return_true_1(): sph = Sphere((0, 0, 0), 2) ray = Ray((2, 0, 0), (2, 1, 0)) temp = _intersect_ray_with_sphere(ray, sph) val = 2 if np.array_equal(temp, [[2, 0, 0]]) is True: val = 1 assert (val == 1) is True
def test__intersect_ray_with_sphere_return_false_1(): sph = Sphere((0, 0, 0), 1) ray = Ray((5, 0, 0), (0, 5, 0)) val = 2 temp = _intersect_ray_with_sphere(ray, sph) if temp == 0: val = 0 assert (val == 2) is False
def test_intersect_no_intersect_ray_with_sphere_true(): r1 = Ray((100, 100, 100), (200, 200, 100)) s1 = Sphere((0, 0, 0), 5) d, intercepts = intersect(r1, s1) intercepts_analytical = [0] d_analytical = 0 assert ((intercepts == intercepts_analytical) and (d_analytical == d)) is True
def test__intersect_ray_with_sphere_return_true(): sph = Sphere((0, 0, 0), 1) ray = Ray((-1, 0, 0), (0, 0, 0)) temp = _intersect_ray_with_sphere(ray, sph) val = 1 print(temp) if np.array_equal(temp, [[1.0, 0.0, 0.0], [-1.0, 0.0, 0.0]]): val = 2 assert (val == 2) is True
def test__intersect_ray_with_sphere_return_false(): sph = Sphere((0, 0, 0), 1) ray = Ray((1, 0, 0), (1, 1, 0)) val = 2 temp = _intersect_ray_with_sphere(ray, sph) print(temp) if np.array_equal(temp, [[1.0, 0.0, 0.0]]) is True: val = 1 assert (val == 2) is False
def test__intersect__ray_with_sphere__return_false(): r1 = Ray((0, 0, 0), (1, 1, 1)) s1 = Sphere((10, 10, 10), 3) d, intersections = intersect(r1, s1) calculated_intersections = [ Point([3.0, 0.0, 0.0]), Point([-3.0, 0.0, 0.0]) ] d_analytical = 2 assert ((intersections == calculated_intersections) and (d_analytical == d)) is False
def test_sphere_equality_given_two_equal_centre_radius_return_true(): assert (Sphere((0, 0, 0), 2) == Sphere((0, 0, 0), 2)) is True
def test__sphere__given_two_equal_spheres__return_true(): s1 = Sphere((1, 2, 3), 4) s2 = Sphere((1, 2, 3), 4) assert (s1 == s2) is True
def test__sphere_equal__given_two_not_equal_sphere_radius__return_false(): assert (Sphere((0, 0, 0), 2) == Sphere((0, 0, 0), 4)) is False
def test_intersection__sphere_center_elsewhere__given_ray_that_intersects_at_no_points__return_true( ): assert (intersection(Ray((-2, 1.5, 0), (1, 0, 0)), Sphere((1, 1, 1), 1.0)) == None)
def test_intersection__sphere_center_elsewhere__given_tangent_ray__return_true( ): assert (intersection(Ray((-3, 1, 0), (1, 0, 0)), Sphere( (1, 1, 1), 1.0)) == Point([1, 1, 0]))
def test_intersection__sphere_center_at_origin__given_ray_that_intersects_at_two_points__return_true( ): assert array_equal( intersection(Ray((-2, 0, 0), (1, 0, 0)), Sphere((0, 0, 0), 1.0)), [Point([-1, 0, 0]), Point([1, 0, 0])]) is True
def test_sphere_equal__given_two_unequal_spheres__return_false(): assert (Sphere((0, 0, 0), 3) == Sphere((0, 0, 0), 5)) is False
def test_sphere_equal__given_two_equal_spheres__return_true(): assert (Sphere((0, 0, 0), 3) == Sphere((0, 0, 0), 3)) is True
def test__sphere_equal__given_two_not_equal_sphere_center__return_false(): assert (Sphere((0, 0, 0), 5) == Ray((1, 1, 1), 5)) is False
def test_sphere_equality_given_two_different_centre_radius_return_false(): assert (Sphere((0, 0, 1), 4) == Sphere((5, 0, 0), 2)) is False
def test_intersection__sphere_center_at_origin__given_tangent_ray__return_true( ): assert (intersection(Ray((-3, 1, 0), (1, 0, 0)), Sphere( (0, 0, 0), 1.0)) == Point([0, 1, 0]))
def test_ray_equal__given_two_equal_rays__return_true(): assert (Sphere((0, 0, 0), (1, 1, 1)) == Sphere((0, 0, 0), (1, 1, 1))) is True
def test_intersection__sphere_center_at_origin__given_ray_that_originates_inside_sphere__return_true( ): assert (intersection(Ray((-0.5, 0, 0), (1, 0, 0)), Sphere( (0, 0, 0), 1.0)) == Point([1, 0, 0]))
def test_ray_equal__given_two_unequal_rays__return_false(): assert (Sphere((0, 0, 0), (2, 1, 1)) == Sphere((0, 0, 0), (1, 1, 1))) is False
def test_intersection__sphere_center_elsewhere__given_ray_that_intersects_at_two_points__return_true( ): assert array_equal( intersection(Ray((-2, 1, 1), (1, 0, 0)), Sphere((1, 1, 1), 1.0)), [Point([0, 1, 1]), Point([2, 1, 1])]) is True
def test_sphere_eq_different_center_point_and_different_radius__return_False(): Sphere1 = Sphere([1, 1, 1], 5) Sphere4 = Sphere([2, 2, 2], 7) assert (Sphere1 == Sphere4) is False
def test_intersection__sphere_center_elsewhere__given_ray_that_originates_inside_sphere__return_true( ): assert (intersection(Ray((1, 1, 1), (0, 0, 1)), Sphere( (1, 1, 1), 1.0)) == Point([1, 1, 2]))
def test__sphere__given_two_not_equal_spheres__return_false(): s1 = Sphere((1, 2, 3), 4) s2 = Sphere((0, 0, 0), 6) assert (s1 == s2) is False
def test_sphere_eq_same_center_point_and_same_radius__return_True(): Sphere1 = Sphere([1, 1, 1], 5) Sphere2 = Sphere([1, 1, 1], 5) assert (Sphere1 == Sphere2) is True
def test__sphere_equal__given_two_equal_spheres__return_true(): assert (Sphere((1, 2, 3), 5) == Sphere((1, 2, 3), 5)) is True