HackerTube 中文?
Thematic readings

Why do tests pass when the program is wrong?

Gary Bernhardt’s isolated tests and Andrej Karpathy’s neural network both deliver good news when the code is wrong.

A passing test is useful evidence. What specific mistake could still produce that result? These talks offer two surprisingly different answers.

When the mock shares your mistake

Imagine testing a reminder service. You tell a fake user repository which accounts have expired, then check whether the service emails them. The fake and the caller can agree perfectly even if both misunderstand the real repository. One integration check against real records tests a different promise.

if you don't stub the boundary correctly, your test will pass and your production system will be wrong.
Gary Bernhardt · Boundaries · Original captions
Replay 4:14–4:25 →

Running the real program is no guarantee either

Karpathy trains a small network and watches loss fall. But the training loop forgot to clear old gradients. On this easy problem the accumulated gradients took larger steps and appeared to work even better. Falling loss could never distinguish these implementations.

you may have lots of bugs in the code and uh your network might actually work
Andrej Karpathy · Building micrograd · Original captions
Replay 2:13:44–2:13:51 →
Try two steps: can loss fall with uncleared gradients?

Start at w = 4 and aim for zero. With loss w²/2, the gradient is w. Subtract a quarter of the gradient at each step.

Weight: 4 → 3 → 2.25
The second gradient is 3. Loss falls from 8 to about 2.53.
Weight: 4 → 3 → 1.25
The second step uses 4 + 3 = 7. Loss falls from 8 to about 0.78, even with the bug.

Give the suspected error a chance to fail

For the mock, compare its output with a real query. For gradient accumulation, hand-calculate two small updates and compare the second one. Deliberately introduce the mistake: does the new check turn red?