Example #1
0
def test_sphere_from_diameter():
    assert Sphere.from_diameter(3).diameter == 3
    assert Sphere.from_diameter(4).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)"
Example #3
0
def test_area_sphere():
    s = Sphere(2)
    sph = Sphere(4)

    assert s.area == 50.26548245743669
    assert sph.area == 201.06192982974676
Example #4
0
def test_from_diameter():
    assert Circle.from_diameter(3).diameter == 3
    assert Circle.from_diameter(4).radius == 2


def test_repr():
    temp_stdout = StringIO()
    with contextlib.redirect_stdout(temp_stdout):
        print(repr(circle2))
    output = temp_stdout.getvalue().strip()
    assert "Circle(3)" in output


# Sphere tests

sphere1 = Sphere(2)
sphere2 = Sphere(3)


def test_volume():
    assert sphere1.volume == 33.510321638291124


def test_area():
    assert sphere1.surface_area == 50.26548245743669


def test_radius():
    assert sphere1.radius == 2

def test_sphere_diameter():
    s = Sphere.from_diameter(8)

    assert type(s) == Sphere
    print(s.volume())
    assert s.volume() == 268.082573106329
Example #6
0
def test_str():
    my_circle = Circle(4)
    my_sphere = Sphere(4)
    assert str(my_circle) == "Circle with radius 4.000000"
    assert str(my_sphere) == "Sphere with radius 4.000000"
def test_sphere_from_diameter_type():
    s = Sphere.from_diameter(10)
    s.radius == 5
    assert isinstance(s, Sphere)
def test_sphere_str():
    s = Sphere(12)

    assert str(s) == "Sphere with radius: 12"
    assert eval(repr(s)) == s
def test_sphere_area():
    s1 = Sphere(4)

    assert s1.area == 201.06192982974676
def test_sphere():
    s = Sphere(5)

    assert s.radius == 5
    assert s.diameter == 10
Example #11
0
def test_sphere_from_diameter():
    s = Sphere.from_diameter(8)

    assert s.radius == 4
    assert s.diameter == 8
Example #12
0
def test_str_():
    s = Sphere(2)

    assert str(s) == "Sphere with a radius 2.000000"
Example #13
0
def test_rpr_():
    s = Sphere(2)

    assert repr(s) == 'Sphere(2)'
Example #14
0
def test_sphere_area():
    s = Sphere(4)

    with pytest.raises(NotImplementedError):
        s.area()
def test_volume():
    s1 = Sphere(4)

    assert s1.volume() == 268.082573106329
Example #16
0
def test_sphere_repr():
    s = Sphere(12)

    assert repr(s) == "Sphere(12)"
    assert eval(repr(s)) == s
Example #17
0
def test_sphere_sa():
    """Tests computation for volume of Sphere object."""
    s2 = Sphere(8)
    assert s2.volume == (4 / 3 * pi * 8**3)
def test_sphere_vol():
    s = Sphere(4)

    print(s.volume())
    assert s.volume() == 268.082573106329
Example #19
0
def test_sphere():
    """Tests construction of Sphere object with radius 2."""
    s2 = Sphere(2)
    assert str(s2) == 'Sphere with radius 2.000000'
Example #20
0
def test_area():
    my_circle = Circle(3)
    my_sphere = Sphere(3)
    assert my_circle.area == math.pi * 9
    assert my_sphere.area == 4 * math.pi * 9
Example #21
0
def test_sphere_sa():
    """Tests computation for surface area of Sphere object."""
    s2 = Sphere(4)
    assert s2.area == (4 * pi * 4**2)
Example #22
0
def test_repr():
    my_circle = Circle(4)
    my_sphere = Sphere(4)
    assert repr(my_circle) == "Circle(4)"
    assert repr(my_sphere) == "Sphere(4)"
Example #23
0
def test_volume_sphere():
    s = Sphere(3)

    assert s.volume == 113.09733552923254