Timeline for Writing the minimum code to pass a unit test - without cheating!
Current License: CC BY-SA 2.5
12 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 25, 2010 at 16:45 | comment | added | user1249 | @SnOrfus, or just silently overflow. This would, however, be a very good test case for numerically sensitive implementations. | |
| Nov 25, 2010 at 16:37 | comment | added | Steven Evers | @Robert Harvey: Not all inputs. factorial(long.MaxValue) would throw. | |
| Nov 25, 2010 at 16:36 | comment | added | Steven Evers | @Thorbjørn Ravn Andersen: Agreed, I rescind my comment about the implied contract. | |
| Nov 25, 2010 at 16:32 | comment | added | user1249 | @Robert, yes, and the test suite is the runnable version of the spec. | |
| Nov 25, 2010 at 16:31 | comment | added | user1249 | @SnOrfus, the place for "implied contracts" to be is in the test cases. If you contract is for factorials, you TEST if known factorials are and if known non-factorials aren't. Plenty of them. Doesn't take long to convert the list of the ten first factorials to a for-loop testing every number up to the tenth factorial. | |
| Nov 25, 2010 at 16:29 | comment | added | Robert Harvey | Actually, the specification should say that it satisfies all inputs, not just F(6). | |
| Nov 25, 2010 at 16:21 | comment | added | Steven Evers | +1: This is the general idea from my knowledge as well, but something needs to be said about fulfilling the implied contract (ie. the method name factorial). If you only ever spec (ie test) f(6) = 120 then you only ever need to 'return 120'. Once you start adding tests to ensure that f(x) == x*x-1...*x-x-1 : upperBound >= x >= 0 then you will arrive at a function that satisfies the factorial equation. | |
| Nov 25, 2010 at 16:17 | comment | added | CaffGeek | @Thorbjørn Ravn Andersen, exactly, the most important part of Red-Green-Refactor, is the refactoring. | |
| Nov 25, 2010 at 16:11 | history | edited | user1249 | CC BY-SA 2.5 |
added 1 characters in body
|
| Nov 25, 2010 at 16:09 | comment | added | user1249 | @Robert, at SOME point adding a new case will not result in the simplest possible code anymore, at which point you write a new implementation. As you have the tests in place already, you know exactly when your new implementation does the same as the old one. | |
| Nov 25, 2010 at 16:04 | comment | added | Robert Harvey | Seriously? By this logic, you will have to rewrite the code every time someone comes up with a new input. | |
| Nov 25, 2010 at 16:01 | history | answered | user1249 | CC BY-SA 2.5 |