
Boss
Boss: Rescue the Legacy Library

Boss Fight!
Every passing test breaks a shield.
Deep in the Guild archive sits an ancient lending system. Nobody dares touch it, because it has no tests. Members keep complaining:
- "I donated 2 more copies of the Star Atlas, but the count went down to 2!"
- "The last copy was lent out, then someone borrowed it again, and the stock became −1!"
- "Asking what a brand-new member has on loan crashes my report,
it says
Noneinstead of an empty list."
A wise apprentice doesn't just poke at legacy code. First, write tests that expose each bug (red). Then fix the code (green). Those tests stay behind as regression tests, so the bugs can never sneak back unnoticed.
Assignment
- Fix
Libraryso that:add(title, copies)adds to any copies already there;lendraisesValueErrorwhen no copies are left (stock never goes negative);on_loan(member)returns[]for members with no loans.
- Give
TestLibraryat least 3 test methods. They must all pass on your fixed code, and they must fail if the oldaddbug or the oldlendbug ever came back. - Keep
give_backworking. It already does!
- Fix
Libraryso that:add(title, copies)adds to any copies already there;lendraisesValueErrorwhen no copies are left (stock never goes negative);on_loan(member)returns[]for members with no loans.
- Give
TestLibraryat least 3 test methods. They must all pass on your fixed code, and they must fail if the oldaddbug or the oldlendbug ever came back. - Keep
give_backworking. It already does!
main.py Python sleeping
Press Run to try your code, then Check to test it.