def test_sphere_set_diameter(): """ Tests the setter method for the Sphere class property diameter. """ s1 = Sphere(3) s2 = Sphere(10) s1.diameter = 6 assert s1.diameter == 6 assert s1.radius == 3 assert s2.radius == 10 assert s2.diameter == 20 s2.diameter = 3 assert s2.diameter == 3 assert s2.radius == 1.5
def test_setter(): c = Circle(4) c.diameter = 2 assert c.diameter == 2 assert c.radius == 1 s = Sphere(4) s.diameter = 2 assert s.diameter == 2 assert s.radius == 1
def test_diameter(): s = Sphere(4) assert s.diameter == 8 s.diameter = 4 assert s.radius == 2
circles.sort(key=Circle.sort_key, reverse=True) assert circles[0] == c10 assert circles[-1] == c1 # Test reflection assert c6 * 20 == 20 * c6 # Test augmentation assert c11 == Circle(150) assert c12 == Circle(150) c11 += c12 assert c11 == Circle(300) c11 *= c12 assert c11 == Circle(45000) # Test Sphere subclass additional derived attributes s1 = Sphere(10) assert int(s1.volume) == 4188 assert int(s1.area) == 1256 # override Circle area property # Test alternate constructor s2 = Sphere.from_diameter(20) assert s2.radius == 10 # Test str and repr reflect Sphere subclass s1.diameter = 100 s2.diameter = 200 assert s1.__str__() == "Sphere(50.0)" assert s2.__repr__() == "Sphere(100.0)"
assert c2 == Circle(8) s1 = Sphere(2) s2 = Sphere(4) s3 = Sphere(4) assert s1 < s2 assert s2 == s3 assert s2 != s1 assert s1 * 3 == 3 * s1 s1 *= 20 assert s1 == 40 s2 += s3 assert s2 == Sphere(8) ######## # Step 9 ######## def test_volume(): s = Sphere(4) assert round(s.volume, 5) == 268.08257 s = Sphere(4) s.diameter = 2 assert s.diameter == 2 assert s.radius == 1
def test_sphere_diameter_change(): c = Sphere(5) assert c.diameter == 10 c.diameter = 50 assert c.diameter == 50 assert c.radius == 25
def test_sphere_diameter_change(): c = Sphere(10) c.diameter = 10 assert c.radius == 5