Created
August 10, 2024 13:06
-
-
Save Divya0319/0149b3f3b458b64ecfa922fc8a1e708d to your computer and use it in GitHub Desktop.
Revisions
-
Divya0319 created this gist
Aug 10, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ import copy from .point import Point class Rectangle: def __init__(self, *args): if len(args) == 2: # Case 1: Two Point objects if all(isinstance(arg, Point) for arg in args): self.topLeft, self.bottomRight = args else: raise ValueError("If two arguments are provided, both must be Point objects.") elif len(args) == 4: # Case 2: Four coordinates try: x1, y1, x2, y2 = args self.topLeft = Point(x1, y1) self.bottomRight = Point(x2, y2) except (TypeError, ValueError): raise ValueError("Four arguments must be integers or floats representing coordinates.") elif len(args) == 1 and isinstance(args[0], Rectangle): # Case 3: Copying from another Rectangle object original = args[0] self.topLeft = copy.deepcopy(original.topLeft) self.bottomRight = copy.deepcopy(original.bottomRight) else: raise ValueError("Invalid arguments. Provide either two Point objects, four coordinates, or a single Rectangle object.") # Error starts from here Traceback (most recent call last): File "/config/workspace/tests/testRectangle.py", line 21, in test_constructor_with_points self.assertIsNot(rectangle.topLeft, topLeft) AssertionError: unexpectedly identical: <config.point.Point object at 0x7f9903030580>