コード例 #1
0
def test_sphere_init():
    s1 = Sphere(6)
    assert type(s1) is Sphere
    assert s1.radius == 6
    assert s1.diameter == 6 * 2
    s2 = Sphere.from_diameter(3)
    assert type(s2) is Sphere
コード例 #2
0
 def test_ing_sphere_add(self):
     i = 0
     while i < 10:
         i = random.randint(0,50)
         j = random.randint(51,100)
         self.assertEqual(Sphere(i) + Sphere(j), Sphere(i+j))
         i += 1
コード例 #3
0
 def test_ing_sphere_imul(self):
     i = 0
     while i < 10:
         i = random.randint(0,50)
         j = random.randint(51,100)
         c1 = Sphere(i)
         c1*=j
         self.assertEqual(eval(repr(c1)), Sphere(i*j))
         i+=1
コード例 #4
0
 def test_ing_sphere_iadd(self):
     i = 0
     while i < 10:
         i = random.randint(0,50)
         j = random.randint(51,100)
         c1 = Sphere(i)
         c2 = Sphere(j)
         c1+=c2
         self.assertEqual(eval(repr(c1)), Sphere(i+j))
         i += 1
コード例 #5
0
 def test_ing_sphere_volume(self):
     self.assertEqual(Sphere(5).volume, 4/3*pi*Sphere(5).radius**3)
コード例 #6
0
 def test_ing_sphere_classmethod(self):
         i = random.randint(0,50)
         j = random.randint(51,100)
         c1 = Sphere.from_diameter(i)
         self.assertEqual(eval(repr(c1)), Sphere(i/2))
コード例 #7
0
def test_sphere_repr():
    """ Tests that __repr__ is working """
    s = Sphere(4)
    sphere1 = repr(s)
    assert sphere1 == 'Sphere(4)'
コード例 #8
0
 def test_ing_sphere_repr(self):
     i = random.randint(0,50)
     self.assertEqual(repr(Sphere(i)), 'Sphere({})'.format(i))
コード例 #9
0
def test_from_volume():
    s1 = Sphere.from_volume((4 / 3) * pi * 3**3)
    assert type(s1) is Sphere
    assert s1.radius == 3
コード例 #10
0
def test_sphere_surface_area():
    s = Sphere(8)
    assert s.area == 4 * pi * 8**2
コード例 #11
0
def test_sphere_volume():
    s = Sphere(2)
    assert s.volume == (4 / 3) * pi * 2**3
コード例 #12
0
def test_sphere_volume(): 
    """ Tests that the volume of the sphere is calculated correctly """ 
    sphere1 = Sphere(10) 
    assert sphere1.volume == (4/3) * math.pi * 10 ** 3
コード例 #13
0
def test_sphere_area(): 
    """ Tests that the area of the sphere is calculated correctly """ 
    sphere1 = Sphere(10) 
    assert sphere1.area == 4 * math.pi * 10 ** 2
コード例 #14
0
 def test_ing_sphere_area(self):
     self.assertEqual(Sphere(5).area, 4*pi*Sphere(5).radius**2)
コード例 #15
0
 def test_ing_sphere_lt(self):
     i = random.randint(0,10)       
     j = random.randint(0,10)
     self.assertEqual(Sphere(i).radius < Sphere(j).radius, Sphere(i) < Sphere(j))
コード例 #16
0
 def test_ing_sphere_area(self):
     error = AttributeError("can't set attribute")
     try:
         Sphere(5).area = 10
     except AttributeError as result:
         self.assertEqual(str(result), str(error))
コード例 #17
0
 def test_ing_sphere_gt(self):
     i = random.randint(0,50)       
     j = random.randint(51,100)
     self.assertEqual(Sphere(i).radius > Sphere(j).radius, Sphere(i) > Sphere(j))
コード例 #18
0
 def test_ing_sphere_str(self):
     i = random.randint(0,50)
     self.assertEqual(str(Sphere(i)), "Sphere with radius = {}, diameter = {} , area = {}".format(str(Sphere(i).radius), str(Sphere(i).diameter), str(Sphere(i).area)))
コード例 #19
0
 def test_ing_sphere_eq(self):
     i = random.randint(0,3)       
     j = random.randint(0,3)
     self.assertEqual(Sphere(i).radius == Sphere(j).radius, Sphere(i) == Sphere(j))
コード例 #20
0
 def test_ing_sphere_mul(self):
     i = random.randint(0,50)
     j = random.randint(51,100)
     self.assertEqual(Sphere(i)*j, Sphere(Sphere(i).radius*j))  
コード例 #21
0
def test_sphere_str(): 
    """ Tests that __str__ is working """
    s = Sphere(4)
    sphere1 = str(s)
    assert sphere1 == "Sphere with radius: 4.00"