def test_sphere_from_diameter(): """ Verifies the radius and diameter gets set as expected when initializing a Sphere object using the class method from the diameter. """ s1 = Sphere.from_diameter(100) s2 = Sphere.from_diameter(30) assert s1.diameter == 100 assert s1.radius == 50 assert s2.diameter == 30 assert s2.radius == 15
def test_sphere_change_radius(): s = Sphere.from_diameter(8) assert s.radius == 4 s.radius = 3 assert s.diameter == 6
def test_sphere_diameter(): s = Sphere.from_diameter(8) # note that the classmethod got properly inherited assert type(s) == Sphere print(s.volume()) assert s.volume() == 268.082573106329
def test_from_diameter(): c = Circle.from_diameter(8) assert c.radius == 4 assert c.diameter == 8 s = Sphere.from_diameter(8) assert s.radius == 4 assert s.diameter == 8
def test_sphere_set_diameter(): ''' Test 24: Testing set diameter fuctionality. ''' #pylint: disable=E1120, C0103 s = Sphere.from_diameter(8) assert s.area == 4 * pi * 4**2 assert s.volume == 4 / 3 * pi * 4**3
def test_sphere(): """ Verifies the radius gets set as expected when initializing a Sphere object. """ s1 = Sphere(3) s2 = Sphere(4) s3 = Sphere.from_diameter(12) assert s1.radius == 3 assert s2.radius == 4 assert s3.radius == 6
def test_sphere_diameter(): """ Verifies the diameter gets set as expected when initializing a Sphere object. """ s1 = Sphere(3) s2 = Sphere(4) s3 = Sphere.from_diameter(12) assert s1.diameter == 6 assert s2.diameter == 8 assert s3.diameter == 12
def test_sphere_from_diameter_type(): s = Sphere.from_diameter(10) s.radius == 5 # is this an instance of a Sphere? assert isinstance(s, Sphere) # it is also a Circle because it's a subclass of Circle # with subclassing, it is *both* a Circle and a Sphere # (and an object) assert isinstance(s, Circle) assert isinstance(s, object) # checks if it is exactly this type assert type(s) is Sphere # but not exactly a Circle assert not type(s) is Circle
def test_sphere_mul(): """ Verifies multiplying a Sphere object by a scalar will result in the product of the scalar and the radius. """ s1 = Sphere(10) s2 = Sphere.from_diameter(8) # Verify that the representation of the Sphere objects is equal to # the scalar times the radius assert repr(s1 * 2) == "Sphere(20)" assert repr(3 * s2) == "Sphere(12)" # tests rmul assert s1 * 3 == 3 * s1 assert s2 * 4 == 4 * s2
def test_sphere(): """ tests sphere area and volume to a relative tolerance to one one-hundredth. tests ability to change sphere volume and calculate correct resulting volume and radius. :return: None """ 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_sphere_add(): """ Verifies the addition of two Spheres will equal the sum of their radiuses. """ s1 = Sphere(12) s2 = Sphere(4) s3 = Sphere.from_diameter(10) s4 = s2 + s1 s5 = s1 + s2 + s3 assert repr(s3 + s2) == "Sphere(9)" assert repr(s4) == "Sphere(16)" assert repr(s5) == "Sphere(21)" assert s4.radius == 16 assert s4.area == 4 * pi * 16**2 assert s4.diameter == 32 assert s5.radius == 21 assert s5.area == 4 * pi * 21**2 assert s5.diameter == 42
def test_sphere_iadd(): """ Tests the builtin += method syntax works for circles. """ s1 = Sphere(2) s2 = Sphere(10) s3 = Sphere.from_diameter(20) s1 += s2 s2 += s3 assert s1.radius == 12 assert s2.radius == 20 s1 = Sphere(14) s1 += s3 assert s1.radius == 24 s2 += s2 assert s2.radius == 40 s4 = Sphere(4) s2 += s4 assert s2.radius == 44
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)"
def test_sphere_from_diameter(): assert Sphere.from_diameter(3).diameter == 3 assert Sphere.from_diameter(4).radius == 2
def test_sphere_from_diameter_type(): s = Sphere.from_diameter(10) s.radius == 5 assert isinstance(s, Sphere)
def test_sphere_from_diameter(): s = Sphere.from_diameter(8) assert s.radius == 4 assert s.diameter == 8
def test_sphere_init_by_diameter(): """ Verify a sphere can be initialized using a diameter """ a_sphere = Sphere.from_diameter(20) assert a_sphere.radius == 10 assert a_sphere.volume == 4188.790204786391 assert isinstance(a_sphere, Sphere)
def test_sphere_from_diameter_type(): sphere = Sphere.from_diameter(5) assert sphere.radius == 2.5 assert sphere.diameter == 5
def test_sphere_from_diameter(): s = Sphere.from_diameter(10) assert s.radius == 5 assert s.diameter == 10
def test_sphere_from_diameter(): """ Tests you can create a sphere from diameter """ sphere1 = Sphere.from_diameter(10) assert sphere1.radius == 5
def test_sphere_from_diameter(): c = Sphere.from_diameter(10) assert isinstance(c, Sphere)
def test_alternate_sphere_constructor(): s=Sphere.from_diameter(10) assert(s.radius==5)
def test_sphere_diameter(): s = Sphere.from_diameter(8) assert type(s) == Sphere print(s.volume()) assert s.volume() == 268.082573106329
def test_sphere_from_diameter(): s = Sphere.from_diameter(5) assert s.radius == 2.5 assert s.__class__ == Sphere
def test_from_diameter(): s = Sphere.from_diameter(4) assert s.radius == 2 assert s.diameter == 4 assert s.area == approx(50.26548245743669)
def test_sphere_diameter(): s = Sphere.from_diameter(8) print(s.volume()) assert False
def test_sphere_from_diameter(): sphere_obj = Sphere.from_diameter(8) assert sphere_obj.radius == 4 assert sphere_obj.area == 4 * math.pi * sphere_obj.radius**2
def test_sphere_from_diamter_type(): s = Sphere.from_diameter(10) c = C.from_diameter(10) assert isinstance(s, Sphere) assert isinstance(s, C)
def test_Sphere_clsmethod(): s = Sphere.from_diameter(8) assert s.diameter == 8 assert s.radius == 4
def test_sphere_from_diameter_type(): s = Sphere.from_diameter(10) assert 5 == s.radius