Say we want to create a function to calculate the hypotenuse of a right-angled triangle based on the size of the other two sides.
First thing in TDD is to write a test:
if sides are 3 and 4, it should return 5
Run the test. FAIL! But why?
🔴 test failed: you haven't even written the function yet 🤦♂️
Next step: write just the necessary code to pass the test:
return 5
Test again...
🟢 test passed 🎉
Wait, what?! 😱 This is a terrible implementation! The result is hardcoded! What would happen if I give another set of inputs?
"Well, then, write another test," says TDD.