Exemple #1
0
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
Exemple #2
0
def test_set_sphere_volume():
    """ Verify the area can not be set """
    sphere = Sphere(3)
    with pytest.raises(AttributeError):
        sphere.volume = 4
def test_sphere_volume():
    s = Sphere(4)
    assert s.volume() == 268.082573106329