def test_step_9(self): s1 = Sphere(4) s2 = Sphere(5) s3 = Sphere.from_diameter(8) self.assertEqual(s1.radius, 4) self.assertEqual(s1.diameter, 8) self.assertEqual(s3.diameter, 8) self.assertEqual(s3.radius, 4) self.assertEqual(s1.area, 201.06192982974676) self.assertEqual(s1.volume, 268.082573106329) self.assertEqual(str(s1), "Sphere with radius: 4") self.assertEqual(repr(s1), "Sphere(4)") self.assertEqual(s1 + s2, Sphere(9)) self.assertEqual(s2 * 3, Sphere(15)) self.assertEqual(3 * s2, Sphere(15)) self.assertEqual(s1 > s2, False) self.assertEqual(s1 < s2, True) self.assertEqual(s1 == s2, False) self.assertEqual(s1 != s2, True) spheres = [Sphere(3), Sphere(0), Sphere(2), Sphere(1)] spheres.sort() expected = [Sphere(0), Sphere(1), Sphere(2), Sphere(3)] self.assertEqual(spheres, expected) s1 += s2 s2 *= 2 self.assertEqual(s1, Sphere(9)) self.assertEqual(s2, Circle(10))
def test_creation_sphere_diameter(): """ Test a Sphere can be created using the diameter property """ sphere = Sphere.from_diameter(6) assert str(sphere) == "Sphere with radius: 3.0" assert sphere.radius == 3 assert sphere.diameter == 6 assert sphere.volume == (4 / 30) * math.pi * 3**3 assert sphere.area == 4 * math.pi * 3**2
def test_sphere(): s1 = Sphere(15) assert str(s1) == "Sphere with radius: 15.000000" assert repr(s1) == "Sphere(15)" assert isclose(s1.volume, 943, rel_tol=.01) assert isclose(s1.area, 2827.43, rel_tol=.01) s1.volume = 7 assert isclose(s1.volume, 7, rel_tol=.01) assert isclose(s1.radius, 1.29, rel_tol=.01) s2 = Sphere.from_diameter(18) assert s2.radius == 9
def test_from_diameter_sphere(): c = Sphere.from_diameter(8) assert c.diameter == 8 assert c.radius == 4
def test_alt_constructor_sphere(): s = Sphere.from_diameter(10) assert s.diameter == 10 assert s.radius == 5
def test_sphere_from_diameter_type(): s = Sphere.from_diameter(10) s.radius == 5 assert isinstance(s, Sphere)