def test_compare(): """This will test comparision of circles""" circle1 = Cir(12) circle2 = Cir(20) circle3 = Cir(20) assert circle1 > circle2 assert circle1 < circle2 assert circle1 != circle2 assert circle3 == circle2 # extra assert circle1 <= circle2 assert circle2 >= circle3 assert circle2 <= circle3
def test_diameter_update(): """This will test after the circles radius has been initial created to see if modifying the diameter will then update the radius correctly""" circle = Cir(12) circle.dia = 20 assert circle.rad == 10 assert circle.dia == 20
def test_circle_area(): """This will test the area of a circle (pi x r2) and tests to make sure the user can't create circle directly with area""" circle = Cir(12) assert circle.area == 452.3893421169302 try: circle.area = 12 # property area can't be set first except AttributeError: pass else: assert False
def test_multiply(): """This will test that a circle can be multiplied""" circle2 = Cir(12) assert circle2 * 3, Cir(36) # left operand "__mul__" assert 3 * circle2, Cir(36) # right operand "__rmul__"
def test_add(): """This will test that two circles radii will add together""" circle1 = Cir(12) circle2 = Cir(12) assert circle1 + circle2, Cir(24)
def test_repr(): """This will test that the representation of this object will print correctly""" circle = Cir(12) assert repr(circle) == "Circle(12)"
def test_str(): """This will test that the string will print correctly""" circle = Cir(12) assert str( circle) == "Circle with the radius: 12 and area: 452.3893421169302."
def test_circle_init(): """This will test the circles radius and diameter(x2) on __init__ create""" circle = Cir(12) assert circle.rad == 12 assert circle.dia == 24
def test_sort(): """This will test the sorting of circles""" all_circles = [ Cir(6), Cir(7), Cir(8), Cir(4), Cir(0), Cir(2), Cir(3), Cir(5), Cir(9), Cir(1) ] all_circles.sort() assert all_circles == [ Cir(0), Cir(1), Cir(2), Cir(3), Cir(4), Cir(5), Cir(6), Cir(7), Cir(8), Cir(9) ]