Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In my (limited) experience the first option is quite a bit safer. In a test-case you only test predefined input and compare the outcome, this works well as long as every possible edge-case has been checked. The first option just checks every input and thus tests the 'live' values, it filters out bugs real quickly, however it comes with a performance penalty.</p> <p>In <a href="http://rads.stackoverflow.com/amzn/click/0735619670" rel="nofollow noreferrer">Code Complete</a> Steve McConnell learns us the first method can be used successfully to filter out bugs in a <strong>debug</strong> build. In release build you can filter-out all assertions (for instance with a compiler flag) to get the extra performance.</p> <p>In my opinion the best way is to use both methods:</p> <p>Method 1 to catch illegal values</p> <pre><code>int doWonderfulThings(const int* fantasticData) { ASSERT(fantasticData); ASSERTNOTEQUAL(0, fantasticData) return WOW_VALUE / fantasticData; } </code></pre> <p>and method 2 to test edge-cases of an algorithm.</p> <pre><code>int doMoreWonderfulThings(const int fantasticNumber) { int count = 100; for(int i = 0; i &lt; fantasticNumber; ++i) { count += 10 * fantasticNumber; } return count; } TEST(TDD_Enjoy) { // Test lower edge ASSERT_EQ(0, doMoreWonderfulThings(-1)); ASSERT_EQ(0, doMoreWonderfulThings(0)); ASSERT_EQ(110, doMoreWonderfulThings(1)); //Test some random values ASSERT_EQ(350, doMoreWonderfulThings(5)); ASSERT_EQ(2350, doMoreWonderfulThings(15)); ASSERT_EQ(225100, doMoreWonderfulThings(150)); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload