Validate and communicateLesson 55 of 76 · 7 min
Test a small case you can solve
Verify model arithmetic with boundary cases and independent references.
Verification asks whether the implementation follows the stated model. A small exact case is often more revealing than a large plausible-looking simulation. Choose inputs that force zero, certain or easily calculated outcomes.
For a stocking-loss function, demand equal to stock should create neither shortage nor waste. Zero demand should leave all stock unused. Demand above stock should incur shortage cost only for the missing units. These cases test signs, boundaries and units without relying on random variation.
Keep reference calculations independent of the implementation being checked. Copying the same expression into an expected-answer cell can preserve the same bug. Once the deterministic rule passes, test its use across random inputs and retain every failed case while investigating.
- No demand, stock 5
- Exact match
- Demand 8, stock 5
Can a plausible simulated mean conceal a sign error in a per-trial loss?
Write a prediction (optional)
Seeded teaching simulation
Select Run Python below with the code unchanged.
A saved draft is open. To run the published example, open Tools and select Restore example. Recover draft brings your code back.
Execution error
Technical error details
Your result
Published example output
This result comes from the original Python. Your runs appear above. Build environment ↗
demand, stock, actual, expected: 0 5 10.0 10 demand, stock, actual, expected: 5 5 0.0 0 demand, stock, actual, expected: 8 5 30.0 30 All exact boundary cases passed.
Read the first result
The assertions check specific model properties. They do not establish that the penalty values describe real consequences.
Try an edit
Calculate the penalty by hand for demand 2 and stock 0, and for demand 5.25 and stock 5. Append (2, 0, 20), (5.25, 5, 2.5) to the cases list. Select Run Python again. Read the new demand, stock, actual, expected rows. Does each actual value match your hand calculation? What would an integer conversion do to the 2.5 result?
Scope. A finite set of tests can miss untested cases and cannot establish empirical validity.
Try a fresh case
What does a passing implementation test establish?
Need a hint?
Hint 1
Separate the code rule from the real-world mechanism.
Hint 2
Name exactly what the test compares.