Ok, then, next test:
if input is 5 and 12, should return 13
Test it... 🔴 test failed! Now, time to write the minimum code to pass:
if input=3,4 then return 5
if input=4,12 then return 13
Run tests: 🟢 test passed!
Oh, c'mon!! 😠 This hurts even more!!! This code is not generic. I could be defining tests literally forever!
"True," says TDD, "enter the new phase: refactoring."
Refactoring is about cleaning the code, making it more generic, clear and maintainable. In this case, we might use some Pythagorean hints:
return square_root(a * a + b * b)
Run tests: 🟢 test passed!
Nice! This looks much better now. But wait, we have't finished yet...