Introduction
Writing software can be tricky because bugs often appear after coding. Test-driven development helps prevent bugs by making sure code works correctly from the start.
Imagine building a puzzle where you first decide where a piece should go before placing it. You check if it fits perfectly before moving on to the next piece, fixing any mistakes immediately.
┌───────────────┐
│ Write a Test │
└──────┬────────┘
│ Fails
↓
┌───────────────┐
│ Write Code to │
│ Pass Test │
└──────┬────────┘
│ Passes
↓
┌───────────────┐
│ Refactor Code │
└──────┬────────┘
│
↓
┌───────────────┐
│ Repeat Cycle │
└───────────────┘def add(a: int, b: int) -> int: return a + b def test_add(): assert add(2, 3) == 5 assert add(-1, 1) == 0 if __name__ == '__main__': test_add() print('All tests passed!')