def test_less_than(self): for i in range(100): c1 = Circle(i) c2 = Circle(i + 1) self.assertTrue(c1 < c2) self.assertFalse(c2 < c1) self.assertFalse(c1 < c1)
def test_ing_add(self): i = 0 while i < 10: i = random.randint(0,50) j = random.randint(51,100) self.assertEqual(Circle(i) + Circle(j), Circle(i+j)) i += 1
def test_multiplication(self): """"Tests multiplication""" c1 = Circle(2) c2 = Circle(4) c3 = Circle(8) c4 = c1 * c2 self.assertEqual(c3, c4)
def main(): circle1 = Circle() print("The area of th circle of radius", circle1.radius, "is", circle1.getArea()) circle2 = Circle(25) print("The area of th circle of radius", circle2.radius, "is", circle2.getArea())
def test_addition(self): """Tests addition.""" c1 = Circle(2) c2 = Circle(4) c3 = Circle(6) c4 = c1 + c2 self.assertEqual(c3, c4)
def Rs_SVG(self, tell=False): fixed = Circle() fixed.r = self.RR fixed.N = 100 fixed.__Calc__() #svg=fixed.Rs.Mesh_SVG_Draw_Curve('black') rolling = Circle() rolling.r = self.r rolling.c = Vector([self.RR + self.r, 0]) rolling.N = 100 rolling.__Calc__() #svg=svg+rolling.Rs.Mesh_SVG_Draw_Curve('black') self.Rs.Mesh_SVG( self.Curve_SVG_Name("d0R", ""), self.Curve_Component_Get("R", "Color", "Ana"), tell, self.Show_Points, self.Show_Point_Size, self.Curve_Component_Get("R", "Color", "Ana"), True, #text self.Curve_Coordinate_System_Get(), [], [], self.Symmetries, fixed.Rs.Mesh_SVG_Draw_Curve('black', [], [], 2) #thickness #+ #rolling.Rs.Mesh_SVG_Draw_Curve('black',[],[],2) )
def test_equal(self): for i in range(100): c1 = Circle(i) c2 = Circle(i) c3 = Circle(i + 1) self.assertEqual(c1, c2) self.assertNotEqual(c1, c3)
def test_reflected(): c1 = Circle(3) c1 = c1 * 3 assert c1.radius == 3 * 3 c2 = Circle(4) c2 = 4 * c2 assert c2.radius == 4 * 4
def __init__(self): self.canvas = Canvas(self) self.p1 = Circle(pos=[0, 0.8, 0], radius=0.2, color=[1, 0, 0]) self.p2 = Circle(pos=[0, -0.8, 0], radius=0.2, color=[0, 0, 1]) self.ball = Circle(pos=[0, 0, 0], radius=0.1, color=[0, 1, 1]) # self.canvas = canvas self.movePuck = False self.deg = 0
def test_comparisons(self): c1 = Circle(2) c2 = Circle(3) c3 = Circle(2) self.assertEqual((c1>c2),False) self.assertEqual((c1<c2), True) self.assertEqual((c1==c2), False) self.assertEqual((c1==c3), True)
def test_addition(self): for i in range(100): # Addition c1 = Circle(i) c2 = Circle(i * 2) self.assertEqual(c2, c1 + c1) c1 += c1 self.assertEqual(c2, c1)
def test_ing_imul(self): i = 0 while i < 10: i = random.randint(0,50) j = random.randint(51,100) c1 = Circle(i) c1*=j self.assertEqual(eval(repr(c1)), Circle(i*j)) i+=1
def test_comp(self): c1 = Circle(2) c2 = Circle(4) c3 = Circle(4) self.assertFalse(c1 > c2) self.assertTrue(c1 < c2) self.assertFalse(c1 == c2) self.assertTrue(c2 == c3)
def test_subtract(): c1 = Circle(10) c2 = Circle(8) c3 = c1 - c2 assert c3.radius == 2 c1 -= 4 assert c1.radius == 6 with pytest.raises(ValueError): 6 - c2
def test_add(): """ Testing that adding two Circle classes together yields a Circle class with sums of their radius """ c1 = Circle(2) c2 = Circle(4) print(c1 + c2) assert(c1+c2) == 6
def test_multiply(self): for i in range(100): # Addition c1 = Circle(i) c2 = Circle(i * 2) self.assertEqual(c2, c1 * 2) self.assertEqual(c2, 2 * c1) c1 *= 2 self.assertEqual(c2, c1)
def test_ing_iadd(self): i = 0 while i < 10: i = random.randint(0,50) j = random.randint(51,100) c1 = Circle(i) c2 = Circle(j) c1+=c2 self.assertEqual(eval(repr(c1)), Circle(i+j)) i += 1
def test_step_7(self): c1 = Circle(2) c2 = Circle(4) c3 = Circle(4) self.assertEqual(c1 + c2, 6) self.assertEqual(c2 * 3, 12) self.assertEqual(c1 > c2, False) self.assertEqual(c1 < c2, True) self.assertEqual(c1 == c2, False) self.assertEqual(c2 == c3, True)
def test_sorting(self): c1 = Circle(1) c2 = Circle(2) c3 = Circle(3) c4 = Circle(4) c5 = Circle(5) presorted = [c1,c2,c3,c4,c5] unsorted = [c3,c5,c1,c2,c4] unsorted.sort(reverse=False) self.assertEqual(presorted, unsorted)
def main(): circle1 = Circle() # 반지름 1인 원을 생성한다. print("반지름이", circle1.radius, "인 원의 넓이는 ", circle1.getArea(), "입니다.") circle2 = Circle(25) # 반지름 25인 원을 생성한다. print("반지름이", circle2.radius, "인 원의 넓이는 ", circle2.getArea(), "입니다.") circle3 = Circle(125) # 반지름 125인 원을 생성한다. print("반지름이", circle3.radius, "인 원의 넓이는 ", circle3.getArea(), "입니다.") circle2.radius = 100 # 반지름을 100으로 다시 설정 print("반지름이", circle2.radius, "인 원의 넓이는 ", circle2.getArea(), "입니다.")
def main(): circle = Circle() redCircle = RedShapeDecorator(Circle()) redRectangle = RedShapeDecorator(Rectangle()) print("Circle with normal border") circle.draw() print("Circle of red border") redCircle.draw() print("Rectangle of red border") redRectangle.draw()
def test_comparisons(): c1 = Circle(5) c2 = Circle(10) c3 = Circle(5) a1 = c1 > c2 assert a1 is False a2 = c1 < c2 assert a2 is True a3 = c1 == c3 assert a3 is True a4 = c1 <= c3 assert a4 is True a5 = c1 >= c3 assert a5 is True
def drawDoubleRosette( Center=Point(), r=1, start_angle=0, nb_points_resolution=10000, dpi=300): plot_opt = PlotOptions(nb_points_resolution, dpi, r) circL = [ Circle(plot_opt, x, r) for x in generate_equidistant_points_on_circle( 12, Center, r, start_angle) ] circL.append(Circle(plot_opt, Center, r)) fig, a1 = plt.subplots(1) a1.set_aspect(1) drawCircles(circL, a1) plt.show()
def main(): #创建一个半径为1的圆 circle1 = Circle() #初始化的self的圆半径就是1 print("The area of the circle of radius:", circle1.radius, "is", circle1.getArea()) circle2 = Circle(25) print("The area of the circle of radius:", circle2.radius, "is", circle2.getArea()) circle2.radius = 100 print("The area of the circle of radius:", circle2.radius, "is", circle2.getArea())
def main(): c1 = Circle() print("Radius: ", c1.radius, "Circle1 Area:", c1.getArea()) c2 = Circle(25) print("Radius: ", c2.radius, "Circle2 Area:", c1.getArea()) c3 = Circle(125) print("Radius: ", c3.radius, "Circle3 Area:", c1.getArea()) c2.radius = 100 print("Radius: ", c2.radius, "Circle2 Area:", c2.getArea()) c1.setRadius(50) print("Radius: ", c1.radius, "Circle1 Area:", c1.getArea())
def main(): # Create a circle with radius 1 circle1 = Circle() print("the area of the circle of radius", circle1.radius, "is", circle1.getArea()) circle2 = Circle(25) print("the area of the circle of radius", circle2.radius, "is", circle2.getArea()) circle3 = Circle(125) print("the area of the circle of radius", circle3.radius, "is", circle3.getArea()) # modify circle radius circle2.radius = 100 print("the area of circle of radius", circle2.radius, "is", circle2.getArea())
def generate_circle_random_pos(): colors = [RED, GREEN, BLUE, CYAN, MAGENTA, AZURE, OLIVE, GOLDEN] x = randint(CIRCLE_RADIUS, WINDOW_WIDTH - CIRCLE_RADIUS) y = randint(CIRCLE_RADIUS, WINDOW_HEIGHT - CIRCLE_RADIUS) return Circle(x, y, CIRCLE_RADIUS, colors[randint(0, len(colors) - 1)], 0, 0, randint(0, 5))
def findType(self, position, radius, typeR): correctServices = [] minRadius = radius nearest = 0 position.mercator() region = Circle(position, radius) regionRect = Rectangle(Point(position.x - radius, position.y + radius), Point(position.x + radius, position.y - radius)) if radius < 250: servicesInRect = self._find(self.root, regionRect) for service in servicesInRect: distance = region.isInside(service) if service.type == typeR and distance < radius: correctServices.append(service) if distance < minRadius: nearest = service minRadius = distance else: for r in range(250, radius, 250): servicesInRect = self._find(self.root, regionRect) for service in servicesInRect: distance = region.isInside(service) if service.type == typeR and distance < r: correctServices.append(service) if distance < minRadius: nearest = service minRadius = distance if len(correctServices) > 0: break return nearest, minRadius
def test_FitSmallestCircleCustomImpl(self): generator = Random2DPointsSetGenerator(nPointsMin=25, nPointsMax=60, xmin=-15, xmax=15, ymin=-15, ymax=15, stub=False) for testIter in range(MaxTestIter): randomPoints = generator.Generate() radius, center = FitCircleTo2DPoints(randomPoints, useExternalImpl=False) circle = Circle(radius, center) radiusExt, centerExt = FitCircleTo2DPoints(randomPoints, useExternalImpl=True) #all random points must be inside the circle or on its perimeter for point in randomPoints: self.assertTrue(circle.ContainsPoint(point)) #radius from custom impl. is often slightly larger than one from external impl., #but sometimes, they are nearly identical if not radiusExt <= radius: print("\nFor a random set of " + str(len(randomPoints)) + " points :") print("radius, center from external impl. " + str(round(radiusExt, 4)) + ", " + str(centerExt)) print("radius, center from custom impl. " + str(round(radius, 4)) + ", " + str(center)) self.assertTrue(radiusExt < radius + Point2D.COMPARISONTOLERANCE)
def test_FitSmallestCircleExternalImpl(self): generator = Random2DPointsSetGenerator(nPointsMin=25, nPointsMax=60, xmin=-15, xmax=15, ymin=-15, ymax=15, stub=False) euclideanDist = lambda p1, p2: pow( pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2), 0.5) for testIter in range(MaxTestIter): randomPoints = generator.Generate() radius, center = FitCircleTo2DPoints(randomPoints, useExternalImpl=True) circle = Circle(radius, center) nRandomPointsOnPerimeter = 0 #all random points must be inside the circle or on its perimeter for point in randomPoints: self.assertTrue(circle.ContainsPoint(point)) if abs(euclideanDist(point, center) - radius) <= Point2D.COMPARISONTOLERANCE: nRandomPointsOnPerimeter += 1 #at least 2 points must be on the perimeter of the circle self.assertTrue(nRandomPointsOnPerimeter >= 2)