Boss

Boss: Rescue the Legacy Library

The boss
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 None instead 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

  1. Fix Library so that:
    • add(title, copies) adds to any copies already there;
    • lend raises ValueError when no copies are left (stock never goes negative);
    • on_loan(member) returns [] for members with no loans.
  2. Give TestLibrary at least 3 test methods. They must all pass on your fixed code, and they must fail if the old add bug or the old lend bug ever came back.
  3. Keep give_back working. It already does!