コード例 #1
0
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
コード例 #2
0
def test_sphere_change_radius():
    s = Sphere.from_diameter(8)

    assert s.radius == 4

    s.radius = 3
    assert s.diameter == 6
コード例 #3
0
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
コード例 #4
0
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
コード例 #5
0
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
コード例 #6
0
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
コード例 #7
0
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
コード例 #9
0
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
コード例 #10
0
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
コード例 #11
0
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
コード例 #12
0
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
コード例 #13
0
    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)"
コード例 #14
0
def test_sphere_from_diameter():
    assert Sphere.from_diameter(3).diameter == 3
    assert Sphere.from_diameter(4).radius == 2
コード例 #15
0
def test_sphere_from_diameter_type():
    s = Sphere.from_diameter(10)
    s.radius == 5
    assert isinstance(s, Sphere)
コード例 #16
0
def test_sphere_from_diameter():
    s = Sphere.from_diameter(8)

    assert s.radius == 4
    assert s.diameter == 8
コード例 #17
0
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)
コード例 #18
0
def test_sphere_from_diameter_type():
    sphere = Sphere.from_diameter(5)
    assert sphere.radius == 2.5
    assert sphere.diameter == 5
コード例 #19
0
def test_sphere_from_diameter():
    s = Sphere.from_diameter(10)

    assert s.radius == 5
    assert s.diameter == 10
コード例 #20
0
def test_sphere_from_diameter():
    """ Tests you can create a sphere from diameter """
    sphere1 = Sphere.from_diameter(10)

    assert sphere1.radius == 5
コード例 #21
0
def test_sphere_from_diameter():
    c = Sphere.from_diameter(10)
    assert isinstance(c, Sphere)
コード例 #22
0
def test_alternate_sphere_constructor():
    s=Sphere.from_diameter(10)
    assert(s.radius==5)
コード例 #23
0
def test_sphere_diameter():
    s = Sphere.from_diameter(8)

    assert type(s) == Sphere
    print(s.volume())
    assert s.volume() == 268.082573106329
コード例 #24
0
ファイル: test_circle.py プロジェクト: zmeves/SP_Online_PY210
def test_sphere_from_diameter():
    s = Sphere.from_diameter(5)

    assert s.radius == 2.5

    assert s.__class__ == Sphere
コード例 #25
0
def test_from_diameter():
    s = Sphere.from_diameter(4)
    assert s.radius == 2
    assert s.diameter == 4
    assert s.area == approx(50.26548245743669)
コード例 #26
0
def test_sphere_diameter():
    s = Sphere.from_diameter(8)

    print(s.volume())

    assert False
コード例 #27
0
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
コード例 #28
0
def test_sphere_from_diamter_type():
    s = Sphere.from_diameter(10)
    c = C.from_diameter(10)
    assert isinstance(s, Sphere)
    assert isinstance(s, C)
コード例 #29
0
def test_Sphere_clsmethod():
    s = Sphere.from_diameter(8)
    assert s.diameter == 8
    assert s.radius == 4
コード例 #30
0
def test_sphere_from_diameter_type():
    s = Sphere.from_diameter(10)
    assert 5 == s.radius