def test_s4(): c = Circle(2) assert c.area == 12.566370614359172 try: c.area = 40 except AttributeError: pass
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 fitness(chrome): val = decode(chrome) # interpret the circle xyrad = val.split() circ = Circle(int(xyrad[0]),int(xyrad[1]), int(xyrad[2])) # Evaluate this circle against all the circles in the initial_list # Also do a bounds check for drawing the circle on the screen for item in initial_list: if circ.intersects(item) == True: return if circ.containsCircle(item) == True: return if circ.x + circ.radius > canvas_width or circ.x - circ.radius < 0: return if circ.y + circ.radius > canvas_height or circ.y - circ.radius < 0: return chrome.fitness = circ.area() if chrome.fitness >= sol.fitness: sol.fitness = chrome.fitness sol.name = chrome.name
""" Program for user to create a rectangle shape """ from rectangle import Rectangle rectangle = Rectangle( 0, 0, 3, 2 ) # four parameters are passed to __init__ constructor to create an instance of shape rectangle.move(5, 15) # move method is inherited from base class print(rectangle) print(rectangle.area()) from circle_class import Circle circle = Circle(3, 6, 1) print(circle) print(circle.area())
def test_get_area(self): c = Circle(2) self.assertAlmostEqual(c.area, 12.5663706, places=7) with self.assertRaises(AttributeError): c.area = 13
def test_area2(): c = Circle(2) with pytest.raises(AttributeError): c.area = 42
def test_set_area(): c = Circle(7) with pytest.raises(AttributeError): c.area = 10
def test_area_101(self): c = Circle(12) with self.assertRaises(AttributeError): c.area = 58
def test_area(): c = Circle(2) assert c.area == 12.566370614359172 with pytest.raises(AttributeError): c.area = 12
def test_set_circle_area(): """ Verify the area can not be set """ circle = Circle(3) with pytest.raises(AttributeError): circle.area = 4
def test_set_no_area(): my_circle = Circle(3) with pytest.raises(AttributeError): my_circle.area = 20
def test_area_set(): with pytest.raises(AttributeError): c = Circle(4) c.area = 4
def test_change_values_area(): c = Circle(13) c.area = 6 assert isclose(c.radius, 1.38, rel_tol=.01) assert isclose(c.diameter, c.radius * 2, rel_tol=.01)
def test_set_area(): c = Circle(2) assert isclose(c.area, (pi * 2**2), rel_tol=.01) c.area = 500 assert isclose(c.area, 500, rel_tol=.01)