Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: Test::LectroTest and pseudo random distributions

by xdg (Monsignor)
on Aug 04, 2005 at 19:20 UTC ( [id://480995]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Test::LectroTest and pseudo random distributions
in thread When test-driven development just won't do

I hadn't seen the tutorial, but the presentation had the same angular differences example. I see the point, but don't find it compelling because of the contrived nature of the manual testing. E.g. the "bad" manual example only uses positive numbers, and never bothers to test the obvious edge case:

return abs($a - $b) % 180

This edge case is either side of the modulo 180, and a quick examination of the code (without even testing) shows that it's impossible to ever have an angular difference of 180 degrees. Even ignoring the code for a moment, the real edge cases that thoughtful manual testing should have checked are the edges of acceptable output -- zero angular difference and 180 degrees of angular difference.

At a certain point in the tutorial, the author refines the problem as so:

If you think about it, our recipe above is actually a specification of a general property that our implementation must hold to: "For all angles a and for all angles diff in the range -180 to 180, we assert that angdiff($a, $a + $diff) must equal abs($diff)."

Testing differences of -180, -1, 0, 1, and 180 is sufficient -- the random testing in between doesn't add additional information. (And this principle extends to the later example of differences greater than 180 or even 360 degrees.) My point is that if you understand the problem space well enough and specify the expectation well enough, ordinary tests are easily sufficient. So you can use Test::LectroTest, or just this:

for ( -180, -1, 0, 1, 180 ) { is( angdiff(0, $_), abs $_, "angdiff (0,$_)" ); }

Let me be fair -- I think Test::LectroTest could be a very useful tool for exploring a poorly understood problem space by generating lots of test cases for examination, but I wouldn't use it as a first-line-of-defense testing tool.

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Replies are listed 'Best First'.
Re^4: Test::LectroTest and pseudo random distributions
by Anonymous Monk on Aug 04, 2005 at 20:22 UTC
    My point is that if you understand the problem space well enough and specify the expectation well enough, ordinary tests are easily sufficient.
    If you understand the problem well enough, you might as well try and mathematically prove that your program conforms to the specification, and dispense with the tests all together.

      Unless you program in a language (or with a technique) that can verify the correctness of your program, you will have trouble when someone modifies the code.

      Easy to say, but hard to do. I have a friend who did his Ph.D. dissertation on mathematically-provable program compilation and it's a very complicated problem. (Which, I guess, puts me in the pragmatic "systems" camp instead of the purist "theory" camp for comp sci.)

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://480995]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-04-19 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found