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
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
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
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
def test_ing_sphere_volume(self): self.assertEqual(Sphere(5).volume, 4/3*pi*Sphere(5).radius**3)
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))
def test_sphere_repr(): """ Tests that __repr__ is working """ s = Sphere(4) sphere1 = repr(s) assert sphere1 == 'Sphere(4)'
def test_ing_sphere_repr(self): i = random.randint(0,50) self.assertEqual(repr(Sphere(i)), 'Sphere({})'.format(i))
def test_from_volume(): s1 = Sphere.from_volume((4 / 3) * pi * 3**3) assert type(s1) is Sphere assert s1.radius == 3
def test_sphere_surface_area(): s = Sphere(8) assert s.area == 4 * pi * 8**2
def test_sphere_volume(): s = Sphere(2) assert s.volume == (4 / 3) * pi * 2**3
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
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
def test_ing_sphere_area(self): self.assertEqual(Sphere(5).area, 4*pi*Sphere(5).radius**2)
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))
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))
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))
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)))
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))
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))
def test_sphere_str(): """ Tests that __str__ is working """ s = Sphere(4) sphere1 = str(s) assert sphere1 == "Sphere with radius: 4.00"