Verifying and extending a design 00:00:00 Make a prediction You will turn an invariant into a short test trace that checks both the returned result and the state left behind. Lee is refused a seat Ana already holds. If the test checks only that Lee got an error, could the implementation still be wrong? Yes. The refusal might accidentally erase Ana's existing hold. Assert that the failure result is correct and then read the seat back to prove Ana still owns it. 00:00:31 Lee, Noor and the bridge A model bridge looks solid until the train crosses its middle span. Drive the train to one mark at a time and watch where the deck bends. Then try the same weight from the other side. The moving train is a sequence of calls; a bending pillar identifies the step where an invariant first stops holding. Retest both directions after the fix. A passing final screenshot would not locate that first bad step. Verification in a design round means that you show that the code does what was agreed. You pick concrete inputs, walk through the code line by line, and write down the state after each call. Then you name the tests that would keep it right. Most bugs in a round are small: a limit on the wrong side, a change before a check, a second call by the same person. You see them in the first trace, or the interviewer sees them first. 00:01:23 Make a double booking visible Write the invariant before the implementation: a seat has at most one active owner at a given time. Book seat seven for Ana. The system returns a confirmation and the seat maps to Ana. Try the identical seat for Lee before Ana releases it. The second call must fail and the seat must still belong to Ana. Checking both catches failures that report the right error but corrupt the state. List the results, not just the call count. Ana claims seat seven. Bo tries the same seat. Inspect both booking records and the availability count; if Bo got an error but the seat count also fell, an assertion on the error alone would miss a real defect. 00:02:09 Test the end of a booking Use a clock you control for an expiring hold. Start at noon and advance to one instant before expiry, then exactly to expiry. Specify whether equality is expired and test both sides. A real sleep makes this boundary slower and less reliable. Freeze time at one second before the deadline, then move the clock to the exact deadline. A rule saying valid strictly before expiry yields two different answers. With the opposite equality convention the second test changes. A clock seam makes this boundary repeatable without sleeping. A test that never checks unchanged state can overlook a failed operation that destroyed somebody else's data. Use a fake clock when expiry matters, and a controlled interleaving when simultaneous calls matter. Real waiting obscures precisely the boundary you need to test. SQLite. Its testing page describes four independently developed test harnesses, 100% branch coverage in an as-deployed configuration, and tests with simulated lack of memory and I/O errors. Git fsck. A command that verifies the connectivity and validity of the objects in the database: an invariant check that ships with the product. 00:03:29 Try an interview follow-up How would you verify two threads renting the last bike? First on paper: list the steps of both, and look for an order in which both pass the check. Then make check and change one step with a lock. A stress test adds trust, and cannot prove it. A pickup service can cancel a reservation or hand it to a customer. Show a happy pickup first. Now interleave cancellation between checking the status and handing over the item. Write a test in which exactly one transition wins. This clarifies both the state boundary and the observable outcome for the losing caller. 00:04:09 What to take with you Trace three things: one usual case, one refusal, and one boundary. Write the state after each call, and compare it with the invariants. Name tests as sentences about behaviour. Hand in the clock and other outside things, so that tests need no waiting and no network.