Challenge 2: Testing a Divide-by-Zero Panic — Possible Solution ==================================================================== pub fn divide(a: f64, b: f64) -> f64 { if b == 0.0 { panic!("cannot divide by zero"); } a / b } #[cfg(test)] mod tests { use super::*; #[test] #[should_panic] fn dividing_by_zero_panics() { divide(10.0, 0.0); } } WHY THIS WORKS AS AN ANSWER ------------------------------ divide explicitly calls panic!("cannot divide by zero") when b is 0.0 — reusing Course 1 Chapter 7's panic! for a genuinely unrecoverable situation (per that chapter's own guidance: panic! for "this should never happen," which a caller passing 0.0 as a divisor to a raw divide function reasonably counts as, absent Result-based error handling). The test function itself calls divide(10.0, 0.0) with NO assertion macro at all — it doesn't need one. Because it's marked #[should_panic], this chapter's own rule applies: the test PASSES specifically because the call panics, and would FAIL if divide somehow returned normally instead (which would indicate the zero-check was broken or removed). This inverts the usual pass/fail logic on purpose — exactly the tool this chapter introduced specifically for testing that error conditions are correctly detected and rejected, rather than testing a successful, non-panicking code path.