def testValidConstruction(self): p1 = Point(0, 0) p2 = Point(2, 0) p3 = Point(0, 2) p4 = Point(3, 0) p5 = Point(0, 3) c1 = Circle(p1, p2, p3, p4, p5) self.assertEqual(p1, c1.center) self.assertEqual(p2, c1.focus1) self.assertEqual(p3, c1.focus2) self.assertEqual(p4, c1.edge1) self.assertEqual(p5, c1.edge2) c2 = Circle(1, 1, 4, 4, -2, 4, 6, 6, -4, 6) self.assertEqual(1, c2.center.x) self.assertEqual(1, c2.center.y) self.assertEqual(4, c2.focus1.x) self.assertEqual(4, c2.focus1.y) self.assertEqual(-2, c2.focus2.x) self.assertEqual(4, c2.focus2.y) self.assertEqual(6, c2.edge1.x) self.assertEqual(6, c2.edge1.y) self.assertEqual(-4, c2.edge2.x) self.assertEqual(6, c2.edge2.y)
def testComputeRadius(self): p1 = Point(0, 0) p2 = Point(1, 0) p3 = Point(0, 1) p4 = Point(2, 0) p5 = Point(0, 2) c1 = Circle(p1, p2, p3, p4, p5) self.assertAlmostEqual(2, c1.computeRadius(), places=3) c2 = Circle(1, 1, 4, 4, -2, 4, 6, 6, -4, 6) self.assertAlmostEqual(7.071, c2.computeRadius(), places=3)
def test_circle(): """ Defines tests on some specific circle objects. """ radius5 = Circle(5) radius8 = Circle(8) # Test areas, perimeters, and diameters assert radius5.area() == 78.54 assert radius8.area() == 201.06 assert radius5.perimeter() == 31.42 assert radius8.perimeter() == 50.27 assert radius5.diameter() == 10 assert radius8.diameter() == 16
def create_shape(type): if type == "Circle": return Circle() if type == "Square": return Square() else: raise TypeError("Shape {} is not known!".format(type))
def testValidateCircle(self): c1 = Circle(0, 0, 2, 0, 0, 2, 3, 0, 0, 3) Validator.validateCircle(c1, "Circle unexpectedly invalid") self.assertRaises( ShapeException, Validator.validateCircle, "(0, 0, 2, 0, 0, 2, 3, 0, 0, 3)", "String \'(0, 0, 2, 0, 0, 2, 3, 0, 0, 3)\' is not a valid circle") self.assertRaises(ShapeException, Validator.validateCircle, Point(1, 1), "Point is not a valid circle")
def get_circles(filename): """ Read in from the YAML file supplied and create a list of circles based on the input data. """ try: handle = open(filename, "r") data = yaml.safe_load(handle) except yaml.YAMLError as error: print(error) finally: handle.close() # Use a list comprehension to create a new Circle # object for each radius integer found in the circle_list. circle_objects = [Circle(radius) for radius in data["circle_list"]] # Return the list of Circle objects return circle_objects
def test_error_if_not_figure(item): circle_1 = Circle(1) with pytest.raises(Exception): circle_1.add_area(item)
from shapes.ellipse import Ellipse from shapes.circle import Circle from shapes.rectangle import Rectangle from shapes.square import Square from shape_list.shape_list import ShapeList from color.color import Color shape_list = ShapeList() try: shape_list.append(1) except TypeError: print('Only shape append support') shape_list.append(Circle(5, Color.BLUE)) shape_list.append(Rectangle(2, 3, Color.RED)) shape_list.append(Square(5, Color.BLUE)) shape_list.append(Ellipse(2, 3, Color.GREEN)) print(shape_list) print(shape_list.sorted_shapes_areas(Color.BLUE)) print(Ellipse(4, 5, Color.BLUE).__hash__()) print(Ellipse(4, 5, Color.RED).__hash__()) print(Ellipse(5, 4, Color.BLUE).__hash__()) a = Circle(4, Color.BLUE) d = Circle(4, Color.BLUE) b = Circle(4, Color.RED) c = Ellipse(4, 5, Color.BLUE) print(a == c) #False print(a == b) #False print(a == d) #True
def test_circle_is_instance_figure(): assert isinstance(Circle(1), BaseShape)
def test_name_circle(): circle_1 = Circle(1) assert circle_1.get_name() == "Circle"
def test_name(self): circle = Circle(1) assert circle.name == 'Окружность_2'
def test_add_square(self): circle = Circle(5) assert self.circle.add_square(circle) == pi * (121 + 25)
def setup_class(self): self.circle = Circle(11)
def test_circles_equals_area_after_add_area(): circle_1 = Circle(1) circle_2 = Circle(2) assert circle_1.add_area(circle_2) == circle_2.add_area(circle_1)
def setUp(self): """ Create a few test objects. """ self.radius5 = Circle(5) self.radius8 = Circle(8)
def run_command(self, input_list): """ Checks the arguments of the input list are within the command list and run the associated command.\n Parameters: (1) user input parameters """ # Create clear console function clear_console = lambda: os.system('cls') # Create command list command_list = [ "rectangle", "square", "circle", "add", "shift", "move", "scale", "menu", "display", "exit" ] # Create parameters list parameters = list(input_list) parameters.pop(0) # remove first element parameters = [int(i) for i in parameters] # Check if command is in command list if input_list[0] not in command_list: print( "First argument is invalid, check correct spelling provided!") # Create Rectangle elif input_list[0] == "rectangle" and len(input_list) == 5: # Set Rectangle object, store shape and return output r = Rectangle(parameters[0], parameters[1], parameters[2], parameters[3]) self._shapes[self._idx] = r r.display_stats() # Update shape index self._idx += 1 print() print("Input the command 'menu' for the list of commands.") # Create Square elif input_list[0] == "square" and len(input_list) == 4: # Set Square object, store shape and return output s = Square(parameters[0], parameters[1], parameters[2]) self._shapes[self._idx] = s s.display_stats() # Update shape index self._idx += 1 print() print("Input the command 'menu' for the list of commands.") # Create Circle elif input_list[0] == "circle" and len(input_list) == 4: # Set Circle object, store shape and return output c = Circle(parameters[0], parameters[1], parameters[2]) self._shapes[self._idx] = c c.display_stats() # Update shape index self._idx += 1 print() print("Input the command 'menu' for the list of commands.") # Move or scale a shape elif (input_list[0] == "move" or input_list[0] == "scale") and len(input_list) == 4: # Check shape parameter is correct if parameters[0] not in self._shapes: print("Shape doesn't exist! Try a different index.") else: print("---------------------------------") print(f"Shape Number: {parameters[0]} updated") print("---------------------------------") # Move the selected shape if input_list[0] == "move": self._shapes[parameters[0]].move(parameters[1], parameters[2]) # Scale the selected shape elif input_list[0] == "scale": self._shapes[parameters[0]].scale(parameters[1], parameters[2]) # Display shape statistics self._shapes[parameters[0]].display_stats() print() print("Input the command 'menu' for the list of commands.") # Display add menu elif input_list[0] == "add": clear_console() self.add_menu() # Display shift menu or shapes elif input_list[0] == "shift" or input_list[0] == "display": # Check shape size if len(self._shapes) == 0: print("No shapes have been created! Create a shape first.") else: clear_console() # Show shift menu if input_list[0] == "shift": self.shift_menu() # Display shape list for key, shape in self._shapes.items(): print("------------------------------") print(f"Shape Number: {key}") print("------------------------------") shape.display_stats() print() # Show additional print if input_list[0] == "display": print("Input the command 'menu' for the list of commands.") # Display menu elif input_list[0] == "menu": clear_console() self.main_menu() # Exit the program elif input_list[0] == "exit": self.exit_program() # Check arguments length else: print( f"Incorrect argument length. Length provided: {len(input_list)}" ) # Create extra space print()
def test_circle_angles_equals_zero(): circle_1 = Circle(10) assert circle_1.get_angles() == 0