Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re^3: Test::LectroTest and pseudo random distributions by xdg
in thread When test-driven development just won't do by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-29 00:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found