def testCircleContainsCircleInstanceMethod(self): c = Circle(radius=2) a = Circle(center=[1, 0]) b = Circle(center=[3, 3], radius=3) self.assertTrue(c in c, '{!r} in {!r}'.format(c, c)) self.assertTrue(a in c, '{!r} in {!r}'.format(a, c)) self.assertFalse(b in c, '{!r} in {!r}'.format(b, c))
def testCircleSettingRadiusAttributeWithNonNumbers(self): for fail in [[], {}, ()]: c = Circle() with self.assertRaises(TypeError): c.radius = fail with self.assertRaises(ValueError): c.radius = 'fail'
def testCircleDoesIntersectLineInstanceMethod(self): c = Circle() l = Line(c.a, c.a_neg) with self.assertRaises(NotImplementedError): c.doesIntersect(l)
def testCircleDoesIntersectCircleInstanceMethod(self): c = Circle() a = Circle(center=[c.radius, 0]) b = Circle(center=[2, 2]) self.assertTrue(c.doesIntersect(c)) self.assertTrue(c.doesIntersect(a)) self.assertFalse(c.doesIntersect(b))
def testCircleSettingCenterAttribute(self): p = Point.gaussian() c = Circle() c.center = p self.assertListEqual(c.center.xyz, p.xyz) c = Circle(p) c.center = None self.assertListEqual(c.center.xyz, [0] * 3)
def testCircleContainsSegmentInstanceMethod(self): c = Circle(radius=2) s = Segment([-1, 0], [1, 0]) self.assertTrue(s in c, '{!r} in {!r}'.format(s, c)) s = Segment(c.a, c.a_neg) self.assertTrue(s in c, '{!r} in {!r}'.format(s, c))
def testCircleContainsPointInstanceMethod(self): c = Circle(radius=2) self.assertTrue(c.center in c) for v in c.vertices.values(): self.assertTrue(v in c, '{!r} in {!r}'.format(v, c)) for v in c.vertices.values(): v *= 2 self.assertFalse(v in c, '{!r} in {!r}'.format(v, c))
def _update_joystick_head_position_on_canvas(self): """ This function draws joystick with new position, on canvas. :return: None """ draw_obj_in_new_position = self.coords joystick_head_circle = Circle(self._actual_joystick_position, self._joystick_head_radius) joystick_bottom_circle = Circle(self._start_joystick_position, self._joystick_bottom_radius) draw_obj_in_new_position(self._joystick_head, joystick_head_circle.get_spanning_points()) draw_obj_in_new_position(self._joystick_bottom, joystick_bottom_circle.get_spanning_points())
def testCircleCreationWithNoArgumentsOrKeywords(self): c = Circle() self.assertIsInstance(c, Circle) self.assertListEqual(c.center.xyz, [0] * 3) self.assertEqual(c.radius, 1)
def testCircleSettingRadiusAttributeWithNumbers(self): for number in [2, 3.4, '5.6']: c = Circle() c.radius = number self.assertEqual(c.radius, float(number))
def testCircleDoesIntersectGarbageInstanceMethod(self): c = Circle() for fail in [None, [], {}, (), 'fail', 1]: with self.assertRaises(TypeError): c.doesIntersect(fail)
def testCircleCreationWithCenterAndRadiusArguments(self): p = Point.gaussian() c = Circle(p, 2) self.assertIsInstance(c, Circle) self.assertListEqual(c.center.xyz, p.xyz) self.assertEqual(c.radius, 2)
def testCircleAreaAttributeGetter(self): c = Circle() self.assertEqual(c.area, math.pi)
def testCircleCreationWithKeywordsReversed(self): p = Point.gaussian() c = Circle(radius=3, center=p) self.assertIsInstance(c, Circle) self.assertListEqual(c.center.xyz, p.xyz) self.assertEqual(c.radius, 3)
def testCircleCreationWithOnlyCenterKeyword(self): p = Point.gaussian() c = Circle(center=p) self.assertIsInstance(c, Circle) self.assertListEqual(c.center.xyz, p.xyz) self.assertEqual(c.radius, 1)
def testCircleCreationWithOnlyRadiusKeyword(self): c = Circle(radius=2) self.assertIsInstance(c, Circle) self.assertListEqual(c.center.xyz, [0] * 3) self.assertEqual(c.radius, 2)
def testCircleDiameterAttributeGetter(self): c = Circle() self.assertEqual(c.diameter, 2)
def testCircleCreationWithEmptyContainersAsCenterArgument(self): for thing in [None, [], (), {}]: c = Circle(thing) self.assertIsInstance(c, Circle) self.assertListEqual(c.center.xyz, [0] * 3) self.assertEqual(c.radius, 1)
def testCircleInscribedInTriangle(self): with self.assertRaises(NotImplementedError): Circle.inscribedInTriangle(Triangle())
def testCircleCircumfrenceAttributeGetter(self): c = Circle() self.assertEqual(c.circumfrence, math.pi * 2)
def testCircleCenterAttributeGetter(self): c = Circle() self.assertIsInstance(c.center, Point) self.assertListEqual(c.center.xyz, [0] * 3)
def testCircleCreationWithAllKeywords(self): p = Point.gaussian() c = Circle(center=p, radius=2) self.assertIsInstance(c, Circle) self.assertListEqual(c.center.xyz, p.xyz) self.assertEqual(c.radius, 2)
def testCircleRadiusAttributeGetter(self): c = Circle() self.assertIsInstance(c.radius, float) self.assertEqual(c.radius, 1)