Re: TDD for numerical algorithms
Jim Murphy <[email protected]> Mon, 24 May 2010 23:47:43 -0400
| Newsgroups | gmane.comp.programming.refactoring |
|---|---|
| Message-ID | <6992068AB16E460883BC712F138B0AB9@LAPTOP01> |
----- Original Message ----- From: Adam Sroka To: [email protected] Sent: Monday, May 24, 2010 10:24 PM Subject: Re: [refactoring] TDD for numerical algorithms On Mon, May 24, 2010 at 6:35 PM, Richard <[email protected]> wrote: > > How would you use TDD to implement the Mersenne twister random number > generator? <http://en.wikipedia.org/wiki/Mersenne_Twister> > > In particular, I'm curious as to what kind of test cases you would write. > It's the wrong question. TDD is an evolutionary process. Like all evolutionary processes it is impossible to reverse engineer it for any non-trivial problem. That is to say: there is no good answer to the question "What set of tests do I need to write to arrive at the given solution?" That said, there are certainly any number of sets of tests for which Mersenne Twister is a potential solution. There may even be some set of tests for which it is the simplest possible solution. And, any given set of tests that could be solved by this algorithm could also be used to test drive a solution that may or may not be as effective and may or may not trivially resemble the given solution. I disagree with this answer. If a customer comes to you and wants a Mersenne Twister coded in, say, C++, you can't very well give him/her something else as a "potential solution". You could discuss the requirement for the particular algorithm with the customer, and offer possibly simpler, cheaper alternatives. But if the customer says "I want X", you either build X or you find alternate employment. To respond to the original question, when a specific algorithm is involved I believe you need to provide additional means to query the state of the process, and then test that the desired state has been reached after each step of the algorithm. On the other hand, if all that is required is an equivalent algorithm, you would need to determine what "equivalent" means and test for that. As an aside, this question reminds me of an old Dilbert cartoon: http://web.archive.org/web/20011027002011/http://dilbert.com/comics/dilbert/archive/images/dilbert2001182781025.gif [Non-text portions of this message have been removed] ------------------------------------ Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/refactoring/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/refactoring/join (Yahoo! ID required) <*> To change settings via email: [email protected] [email protected] <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/