Saturday, 15 March 2014

unit testing - Boundary value analysis in C++ with CppUnit -



unit testing - Boundary value analysis in C++ with CppUnit -

i'm trying implement boundary tests in cppunit. want check limit value boundaries around limit.

for upper boundary wanted add together smallest inkrement possible. double increment can accessed

numeric_limits<double>::epsilon()

however, if add together epsilon limit not-a-number (nan) result:

class="lang-c prettyprint-override">#include <stdio.h> #include <iostream> #include <limits> #include <math.h> using namespace std; const double warning_limit = 8000.0; int main(void) { double warninglowerlimit = warning_limit - numeric_limits<double>::epsilon(); if(warninglowerlimit < warning_limit ) { cout << "lower" << endl; } else if (warninglowerlimit > warning_limit) { cout << "upper" << endl; } else if ( fabs(warninglowerlimit) < 0.001) { cout << "same" << endl; } else { cout << "nan" << endl; // <-- result } }

can please explain me, why result not lower limit?

best regards

else if ( fabs(warninglowerlimit) < 0.001) { cout << "same" << endl; }

that should be

fabs(warninglowerlimit - warning_limit)

there. without checking difference, cout << "nan" if warninglowerlimit == warning_limit example.

unit-testing limit cppunit boundary epsilon

No comments:

Post a Comment