diff --git a/checks/classes/classes10.py b/checks/classes/classes10.py index 5be2042..0019b45 100644 --- a/checks/classes/classes10.py +++ b/checks/classes/classes10.py @@ -1,5 +1,12 @@ +# checks/classes/classes10.py assert Circle.pi == 3.14159, "pi should be a class attribute on Circle" -assert abs(c1.area() - 3.14159) < 1e-6, f"area of circle r=1 should be ~3.14159, got {c1.area()}" -assert abs(c2.area() - 3.14159 * 25) < 1e-4 -assert c1.pi is c2.pi, "pi should be the same class-level object for all instances" +assert ( + abs(c1.area() - 3.14159) < 1e-6 +), f"area of circle r=1 should be ~3.14159, got {c1.area()}" +assert ( + abs(c2.area() - 3.14159 * 25) < 1e-4 +), "area of circle r=5 should be ~78.54 (pi * radius ** 2)" +assert ( + c1.pi is c2.pi +), "pi should be the same class-level object for all instances" print("classes10 ✓") diff --git a/checks/classes/classes11.py b/checks/classes/classes11.py index 84d414c..302820d 100644 --- a/checks/classes/classes11.py +++ b/checks/classes/classes11.py @@ -1,5 +1,12 @@ -assert isinstance(t, Temperature), "from_string should return a Temperature instance" +# checks/classes/classes11.py +assert isinstance( + t, Temperature +), "from_string should return a Temperature instance" assert t.degrees == 36.6, f"expected 36.6, got {t.degrees}" -assert boiling.degrees == 100.0 -assert isinstance(Temperature.from_string("0C"), Temperature) +assert boiling.degrees == 100.0, ( + f"from_string('100C') should give degrees 100.0, " f"got {boiling.degrees}" +) +assert isinstance( + Temperature.from_string("0C"), Temperature +), "from_string('0C') should return a Temperature instance" print("classes11 ✓") diff --git a/checks/classes/classes12.py b/checks/classes/classes12.py index a7312c1..5990d16 100644 --- a/checks/classes/classes12.py +++ b/checks/classes/classes12.py @@ -1,16 +1,30 @@ -assert account.owner == "Alice", f"owner should be 'Alice', got {account.owner!r}" -assert account.balance == 120, f"balance should be 120 after deposit 50 and withdraw 30, got {account.balance}" -assert str(account) == "BankAccount(Alice, balance=120)", f"got {str(account)!r}" +# checks/classes/classes12.py +assert ( + account.owner == "Alice" +), f"owner should be 'Alice', got {account.owner!r}" +assert account.balance == 120, ( + "balance should be 120 after deposit 50 and withdraw 30, " + f"got {account.balance}" +) +assert ( + str(account) == "BankAccount(Alice, balance=120)" +), f"got {str(account)!r}" fresh = BankAccount("Bob", 50) fresh.deposit(25) -assert fresh.balance == 75 +assert fresh.balance == 75, ( + f"balance should be 75 after opening with 50 and depositing 25, " + f"got {fresh.balance}" +) import sys + try: fresh.withdraw(1000) assert False, "should have raised ValueError" except ValueError as e: - assert "insufficient" in str(e).lower(), f"ValueError message should mention 'insufficient', got {e!r}" + assert ( + "insufficient" in str(e).lower() + ), f"ValueError message should mention 'insufficient', got {e!r}" print("classes12 ✓") diff --git a/checks/classes/classes7.py b/checks/classes/classes7.py index c269eff..58268cb 100644 --- a/checks/classes/classes7.py +++ b/checks/classes/classes7.py @@ -1,3 +1,7 @@ +# checks/classes/classes7.py assert g.greet() == "Hello, Alice!", f"got {g.greet()!r}" -assert Greeter("Bob").greet() == "Hello, Bob!" +assert Greeter("Bob").greet() == "Hello, Bob!", ( + "Greeter('Bob').greet() should return 'Hello, Bob!'; " + "build it from self.get_name()" +) print("classes7 ✓") diff --git a/checks/classes/classes8.py b/checks/classes/classes8.py index cbac6c4..5be739c 100644 --- a/checks/classes/classes8.py +++ b/checks/classes/classes8.py @@ -1,3 +1,6 @@ +# checks/classes/classes8.py assert str(book) == "Book: 1984 by Orwell", f"got {str(book)!r}" -assert str(Book("Dune", "Herbert")) == "Book: Dune by Herbert" +assert ( + str(Book("Dune", "Herbert")) == "Book: Dune by Herbert" +), "str(Book('Dune', 'Herbert')) should be 'Book: Dune by Herbert'" print("classes8 ✓") diff --git a/checks/classes/classes9.py b/checks/classes/classes9.py index 63dca06..fb0fdde 100644 --- a/checks/classes/classes9.py +++ b/checks/classes/classes9.py @@ -1,4 +1,11 @@ +# checks/classes/classes9.py assert repr(c) == "Color(r=255, g=128, b=0)", f"got {repr(c)!r}" -assert str(c) == "rgb(255, 128, 0)" -assert repr(Color(0, 0, 0)) == "Color(r=0, g=0, b=0)" +assert str(c) == "rgb(255, 128, 0)", ( + "str(c) should stay 'rgb(255, 128, 0)'; add __repr__ without " + "changing __str__" +) +assert repr(Color(0, 0, 0)) == "Color(r=0, g=0, b=0)", ( + "repr(Color(0, 0, 0)) should be 'Color(r=0, g=0, b=0)'; " + "use the instance values" +) print("classes9 ✓")