> First, technically returning 9 for a test of add(4,5) is correct. Your tests define what the function does, not the name.
You are technically correct that testing "add(4,5) == 9" is valid. However, everyone already knows that an "add(a,b)" function which always returns 9 is broken.
> So when you add the add(10,2) test case, the really pedantic way of doing it would be to handle the extra case with an if-check
Saying an if-check is the correct way to refactor does a disservice to TDD practitioners everywhere.
Implementing a trivial add function via TDD is just bad. It would have been far better to choose something slightly more complicated such as sorting or fizzbuzz.
You are technically correct that testing "add(4,5) == 9" is valid. However, everyone already knows that an "add(a,b)" function which always returns 9 is broken.
> So when you add the add(10,2) test case, the really pedantic way of doing it would be to handle the extra case with an if-check
Saying an if-check is the correct way to refactor does a disservice to TDD practitioners everywhere.
Implementing a trivial add function via TDD is just bad. It would have been far better to choose something slightly more complicated such as sorting or fizzbuzz.