Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (3)
    As of 2014-10-22 03:50 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (112 votes), past polls