def test_step_8_optional(self): c1 = Circle(2) c2 = Circle(4) c1 += c2 c2 *= 2 self.assertEqual(c1, Circle(6)) self.assertEqual(c2, Circle(8))
def test_s8(): c1 = Circle(2) c2 = Circle(4) assert c1 < c2 assert c2 > c1 c3 = Circle(2) assert c1 == c3
def test_from_diameter(self): c = Circle.from_diameter(8) self.assertEqual(c.diameter, 8) self.assertEqual(c.radius, 4) self.assertEqual(Circle(1.0), Circle.from_diameter()) with self.assertRaises(ValueError): Circle.from_diameter(-100)
def test_sub(): c1 = Circle(2) c2 = Circle(4) with pytest.raises(AttributeError): a = c1 - c2 b = c2 - c1 assert b == Circle(2)
def test_s4(): c = Circle(2) assert c.area == 12.566370614359172 try: c.area = 40 except AttributeError: pass
def test_two_circle_add(self): c = Circle(2) d = Circle(4) self.assertEqual(6, (c + d).radius) self.assertEqual(12, (c + d).diameter) with self.assertRaises(TypeError): d = c + 'Square'
def test_sorting(my_circle): blah = [Circle(1), Circle(6), Circle(2), Circle(19), Circle(7)] assert sorted(blah) == [ Circle(1), Circle(2), Circle(6), Circle(7), Circle(19) ]
def test_div_circles(self): a = Circle(10) self.assertEqual(Circle(5), a / 2) with self.assertRaises(ZeroDivisionError): print(a / 0) with self.assertRaises(ValueError): print(a / -2)
def test_floor_div_circles(self): a = Circle(9) self.assertEqual(Circle(4), a // 2) with self.assertRaises(ZeroDivisionError): print(a // 0) with self.assertRaises(ValueError): print(a // -2)
def test_set_diameter(self): c = Circle(4) c.diameter = 2 self.assertEqual(c.diameter, 2) self.assertEqual(c.radius, 1) with self.assertRaises(ValueError): c.diameter = -100
def test_iadd(): c1 = Circle(2) c2 = Circle(4) c3 = Circle(6) c1 += c2 assert c1.radius == 6 assert repr(c1) == repr(c3)
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_multiply_100(self): c1 = Circle(5) c2 = Circle.from_diameter(6) c3 = c1 * c2 self.assertIsInstance(c3, Circle) self.assertEqual(c3.radius, 15) self.assertEqual(c3.diameter, 30) self.assertLess(abs(c3.area - 706.858), 0.1)
def main(): print( "Variable {:>23}".format( "Value")) c1 = Circle() print( "area c5 {:.>24.2f}".format( c1.get_area())) c25 = Circle( 25) print( "area c25 {:.>23.2f}".format( c25.get_area()))
def test_augment_multiply(): my_circle_1 = Circle(4) my_circle_1 *= 2 assert my_circle_1.radius == 8.0 my_circle_2 = Circle(2) my_circle_3 = Circle(3) my_circle_2 *= my_circle_3 assert my_circle_2.radius == 6.0
def test_augment_subtract(): my_circle_1 = Circle(4) my_circle_1 -= 2 assert my_circle_1.radius == 2.0 my_circle_2 = Circle(3) my_circle_3 = Circle(2) my_circle_2 -= my_circle_3 assert my_circle_2.radius == 1.0
def test_augment_add(): my_circle_1 = Circle(4) my_circle_1 += 2 assert my_circle_1.radius == 6.0 my_circle_2 = Circle(2) my_circle_3 = Circle(3) my_circle_2 += my_circle_3 assert my_circle_2.radius == 5.0
def test_comparisons(): c1 = Circle(2) c2 = Circle(4) c3 = Circle(4) assert (c1 > c2) is False assert (c1 < c2) is True assert (c1 == c2) is False assert (c2 == c3) is True
def test_diameter_change_diameter(): c = Circle(10) assert c.radius == 10 assert c.diameter == 20 c.diameter = 4 assert c.radius == 2 assert c.diameter == 4
def test_add_100(self): c1 = Circle(4) c2 = Circle.from_diameter(10) c3 = c1 + c2 self.assertIsInstance(c3, Circle) self.assertEqual(c3.radius, 9) self.assertEqual(c3.diameter, 18) self.assertLess(abs(c3.area - 254.469), 0.1)
def test_isub(): c1 = Circle(2) c2 = Circle(4) c3 = Circle(6) with pytest.raises(AttributeError): c1 -= c2 c3 -= c2 assert c3 == Circle(2)
def test_circle_init(self): c = Circle() self.assertEqual(c.radius, 1) c = Circle(4) self.assertEqual(c.radius, 4) with self.assertRaises(TypeError): c = Circle(-100) self.assertEqual(Circle(4), c)
def test_set_circle_diameter(): """ Test the diameter can be set and it updates the radius """ circle = Circle(2) assert circle.radius == 2 assert circle.diameter == 2 * 2 circle.diameter = 5 assert circle.diameter == 5 assert circle.diameter == circle.radius * 2
def test_comps_102(self): c1 = Circle(9) c2 = Circle(8) self.assertFalse(c1 < c2) self.assertFalse(c1 <= c2) self.assertFalse(c1 == c2) self.assertTrue(c1 > c2) self.assertTrue(c1 >= c2) self.assertTrue(c1 != c2)
def test_mult(): c2 = Circle(4) c3 = c2 * 3 c4 = 3 * c2 assert c3 == Circle(12) assert c4 == Circle(12) assert repr(c2 * 3) == "'Circle(12)'" assert repr(3 * c2) == "'Circle(12)'" assert repr(c2 * 3) == repr(3 * c2)
def test_divide(): c2 = Circle(6) c3 = c2 / 3 c4 = Circle(2) c5 = Circle(1) print(type(c3)) assert c3 == c4 assert c5 == (6 / c2) assert repr(c2 / 3) == "'Circle(2)'" assert repr(6 / c2) == "'Circle(1)'"
def __init__(self): self.run = True self.circlelist = [] self.bg_color = (255, 255, 255) self.hover_color = (66, 167, 245) self.circle_color = (23, 230, 216) self.bg = pygame.image.load("background.jpg") self.tooclose = False self.math = Math() self.points = 0 self.points_label = Label("Points: " + str(self.points), 25, (0, 0, 0), (255, 255, 255), width * 0.9, 25) self.game_title_label = Label("Quick Maths", 40, (0, 0, 0), (255, 255, 255), width / 2, 150) self.choose_mode_label = Label("Choose Mode", 40, (0, 0, 0), (255, 255, 255), width / 2, 150) self.add_label = Label("Addition", 25, (0, 0, 0), (255, 255, 255), width / 5, 550) self.subtract_label = Label("Subtraction", 25, (0, 0, 0), (255, 255, 255), 2 * (width / 5), 550) self.multiply_label = Label("Multiplication", 25, (0, 0, 0), (255, 255, 255), 3 * (width / 5), 550) self.divide_label = Label("Division", 25, (0, 0, 0), (255, 255, 255), 4 * (width / 5), 550) self.end_label = Label( "You ended up with " + str(self.points) + " points.", 35, (0, 0, 0), (255, 255, 255), width / 2, 150) self.play_again_label = Label("Play Again", 25, (0, 0, 0), (255, 255, 255), width / 2, 650) self.choose_diff_label = Label("Choose Level", 32, (0, 0, 0), (255, 255, 255), width / 2, 500) self.diff_1_label = Label("1", 30, (0, 0, 0), (255, 255, 255), width * 0.35, 600) self.diff_2_label = Label("2", 30, (0, 0, 0), (255, 255, 255), width * 0.45, 600) self.diff_3_label = Label("3", 30, (0, 0, 0), (255, 255, 255), width * 0.55, 600) self.diff_4_label = Label("4", 30, (0, 0, 0), (255, 255, 255), width * 0.65, 600) self.stage = "start" for i in range(5): self.circlelist.append(Circle(width, height)) self.allcircles = Circle(width, height) self.allcircles.changepos(self.circlelist) self.allcircles.tp() self.answerLabels = [] self.mousenotpressed = True self.circlemove = False self.circlesteps = 0 self.new_question = False self.wrongsound = pygame.mixer.Sound("wrong.wav") self.rightsound = pygame.mixer.Sound("correct.wav")
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_augmented_assignment(self): a = Circle(4) b = Circle(2) a += b self.assertEqual(Circle(6), a) a *= 2 self.assertEqual(Circle(12), a) a /= 2 self.assertEqual(Circle(6), a)
def test_sort(): c0 = Circle(0) c1 = Circle(1) c2 = Circle(2) c3 = Circle(3) circles = [c2, c3, c1, c0] assert circles[0] == c2 circles.sort() print(circles) assert circles[0] == c0 assert circles[3] == c3
def test_compare(): c1 = Circle(2) c2 = Circle(4) w = c1 < c2 assert w == True x = c1 > c2 assert x == False y = c1 == c2 assert y == False c3 = c2 z = c3 == c2 assert z == True
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
def test_diameter2(): c = Circle(4) c.radius = 2 assert c.diameter == 4
def test_set_diameter(): c = Circle(4) c.diameter = 2 assert c.diameter == 2 assert c.radius == 1