Re: TDD for numerical algorithms

Adam Sroka <[email protected]> Mon, 24 May 2010 19:24:58 -0700
Newsgroups gmane.comp.programming.refactoring
Message-ID <[email protected]>
On Mon, May 24, 2010 at 6:35 PM, Richard <[email protected]> wrote:
>
>
>
> OK, I know this isn't strictly refactoring and more of a TDD question,
> but I don't know of a forum specifically for TDD.
>

There is a testdrivendevelopment yahoo group similar to this one. In
fact, it has more members and is historically higher traffic than this
one (both have been pretty quiet lately, though.)

> 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.

Make sense?

What is potentially a more interesting question is: if I test drove
towards a problem for which I knew Mersenne Twister was a possible
solution could I then refactor my solution to resemble a known
implementation of that algorithm? In my experience it is usually
possible to do that, but you have to know the solution pretty well to
get there.

What I can guarantee is that if you follow the process of TDD
diligently you will arrive at a simple, possibly naive, solution to
the problem that was posed. Often the advantages of having a naively
simple, thoroughly tested solution that solves the business problem
for all known inputs outweigh the advantages of having a
mathematically elegant one.


------------------------------------

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/