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_compare_sphere():
    """This will test comparision of spheres"""
    sphere1 = Sphere(12)
    sphere2 = Sphere(20)
    sphere3 = Sphere(20)
    assert sphere1 > sphere2
    assert sphere1 < sphere2
    assert sphere1 != sphere2
    assert sphere3 == sphere2
    # extra
    assert sphere1 <= sphere2
    assert sphere2 >= sphere3
    assert sphere2 <= sphere3
Exemple #3
0
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
Exemple #4
0
def test_multiply_sphere():
    """This will test that a sphere can be multiplied"""
    sphere2 = Sphere(12)
    assert sphere2 * 3, Sphere(36)  # left operand "__mul__"
    assert 3 * sphere2, Sphere(36)  # right operand "__rmul__"
def test_repr():
    my_sphere = Sphere(4)
    assert repr(my_sphere) == "Sphere(4)"
def test_area_sphere():
    c = Sphere(4)
    print(c.area)
    assert round(c.area, 2) == 201.06
def test_sphere_str():
    my_sphere = Sphere(4)
    assert str(my_sphere) == "Sphere with radius: 4.000000"
def test_sphere_surface_area():
    my_sphere = Sphere(4)
    assert my_sphere.area == 4 * math.pi * 4**2
def test_repr_sphere():
    c = Sphere(4)
    assert repr(c) == "'Sphere(4)'"
    d = eval(repr(c))
    print(d)
    assert d == "Sphere(4)"
Exemple #10
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_str_sphere():
    s = Sphere(10)
    assert str(s) == "Sphere with radius: 10"
Exemple #12
0
def test_get_sphere_area():
    """ Test getting the area """
    sphere = Sphere(6)
    assert sphere.area == 4 * math.pi * 6**2
Exemple #13
0
def test_get_sphere_volume():
    """ Test getting the area """
    sphere = Sphere(6)
    assert sphere.volume == (4 / 30) * math.pi * 6**3
Exemple #14
0
def test_sphere_repr():
    """ Verify the output from repr is the expected value """
    sphere = Sphere(2)
    assert repr(sphere) == "Sphere(2)"
Exemple #15
0
def test_sphere_str():
    """ Verify the string printed is correct """
    sphere = Sphere(8)
    assert str(sphere) == "Sphere with radius: 8"
Exemple #16
0
def test_sphere_init():
    """ Test that a sphere can be initialized """
    sphere = Sphere(2)
    assert sphere.radius == 2
    assert sphere.diameter == 2 * 2
Exemple #17
0
def test_sort_sphere():
    """This will test the sorting of spheres"""
    all_sphere = [
        Sphere(6),
        Sphere(7),
        Sphere(8),
        Sphere(4),
        Sphere(0),
        Sphere(2),
        Sphere(3),
        Sphere(5),
        Sphere(9),
        Sphere(1)
    ]
    all_sphere.sort()
    assert all_sphere == [
        Sphere(0),
        Sphere(1),
        Sphere(2),
        Sphere(3),
        Sphere(4),
        Sphere(5),
        Sphere(6),
        Sphere(7),
        Sphere(8),
        Sphere(9)
    ]
def test_volume():
    s = Sphere(2)

    assert s.volume == 4 / 3 * pi * 2**3
def test_new_sphere():
    Sphere(4)
def test_alt_constructor_sphere():
    s = Sphere.from_diameter(10)

    assert s.diameter == 10
    assert s.radius == 5
def test_repr_sphere():
    s = Sphere(5)

    assert repr(s) == "Sphere(5)"
def test_sphere_volume():
    my_sphere = Sphere(4)
    assert my_sphere.volume == (4.0 / 3.0) * math.pi * 4**3
def test_sphere_area():
    s = Sphere(3)

    assert s.area == 4 * pi * 3**2
Exemple #24
0
def test_sphere_init():
    """This will test the create of sphere including radius, area, and volume"""
    sphere = Sphere(12)
    assert sphere.rad == 12
    assert sphere.volume == 7238.229473870882
    assert sphere.area == 1809.5573684677208
def test_str_sphere():
    c = Sphere(4)
    assert str(c) == "Sphere with radius: 4.000000"
Exemple #26
0
def test_sphere_str():
    """This will test that the string will print correctly"""
    sphere = Sphere(12)
    assert str(
        sphere
    ) == "Sphere with the radius 12, volume 7238.229473870882, and surface area 1809.5573684677208."
def test_volume():
    c = Sphere(4)
    assert round(c.volume, 2) == 268.08
Exemple #28
0
def test_sphere_repr():
    """This will test that the representation of this object will print correctly"""
    sphere = Sphere(12)
    assert repr(sphere) == "Sphere(12)"
def test_from_diameter_sphere():
    c = Sphere.from_diameter(8)
    assert c.diameter == 8
    assert c.radius == 4
Exemple #30
0
def test_add_sphere():
    """This will test that two spheres radii will add together"""
    sphere1 = Sphere(12)
    sphere2 = Sphere(12)
    assert sphere1 + sphere2, Sphere(24)