class TestCircle: def setup(self): self.X = Circle("orange", 4) self.Y = Circle("green", 8) def testgetRadius(self): assert self.X.getRadius() == 4 assert self.Y.getRadius() == 8 def testsetRadius(self): self.X.setRadius(50) assert self.X.radius == 50 self.Y.setRadius(100) assert self.Y.radius == 100 def testcomputeself(self): assert self.X.computeArea() == (3.14159 * (4**2)) assert self.Y.computeArea() == (3.14159 * (8**2)) def testcomputerPerimeter(self): assert self.X.computePerimeter() == (3.14159 * 4 * 2) assert self.Y.computePerimeter() == (3.14159 * 8 * 2) def testgetShapeProperties(self): assert self.X.getShapeProperties( ) == f"Shape: CIRCLE, color: {self.X.color}, Radius: {self.X.radius}," '\n' f"Area: {self.X.computeArea()}, Perimeter: {self.X.computePerimeter()}" assert self.Y.getShapeProperties( ) == f"Shape: CIRCLE, color: {self.Y.color}, Radius: {self.Y.radius}," '\n' f"Area: {self.Y.computeArea()}, Perimeter: {self.Y.computePerimeter()}" def testsetColor(self): self.X.setColor("blue") assert self.X.color == "blue" def testgetColor(self): assert self.X.getColor() == "orange"
class TestCircle: def setup(self): self.A = Circle("red", 3) self.B = Circle("blue", 5) def testgetRadius(self): assert self.A.getRadius() == 3 assert self.B.getRadius() == 5 def testsetRadius(self): self.A.setRadius(1000) assert self.A.radius == 1000 self.B.setRadius(100) assert self.B.radius == 100 def testcomputeself(self): assert self.A.computeArea() == (3.14159 * (3**2)) assert self.B.computeArea() == (3.14159 * (5**2)) def testcomputePerimeter(self): assert self.A.computePerimeter() == (3.14159 * 3 * 2) assert self.B.computePerimeter() == (3.14159 * 5 * 2) def testgetShapeProperties(self): assert self.A.getShapeProperties() == f"Shape: CIRCLE, Color: {self.A.color}, Radius: {self.A.radius}, " \ f"Area: {self.A.computeArea()}, Perimeter: {self.A.computePerimeter()}" assert self.B.getShapeProperties() == f"Shape: CIRCLE, Color: {self.B.color}, Radius: {self.B.radius}, " \ f"Area: {self.B.computeArea()}, Perimeter: {self.B.computePerimeter()}" def testsetColor(self): self.A.setColor("magenta") assert self.A.color == "magenta" def testgetColor(self): assert self.A.getColor() == "red"
from Circle import Circle from Rectangle import Rectangle from Triangle import Triangle print("Enter the shape\n 1.Circle\n 2.Rectangle\n 3.Triangle") n = int(input("")) if n == 1: rad = float(input("Enter the radius:\n")) cir = Circle(rad, area=0) cir.computeArea() elif n == 2: print("Enter the length and bradth:") len = float(input("")) bre = float(input("")) rec = Rectangle(len, bre, area=0) rec.computeArea() elif n == 3: print("Enter the base and height:") base = float(input("")) height = float(input("")) tri = Triangle(base, height, area=0) tri.computeArea() else: print("Invalid choice ")