Commit a032d0e2c0adffdcaaf5d3ab3eae7100888af118
1 parent
33eec0f7
Add test_value method in GTestSuite class.
Showing
4 changed files
with
56 additions
and
3 deletions
include/GTestSuite.hpp
| @@ -72,10 +72,15 @@ class GTestSuite{ | @@ -72,10 +72,15 @@ class GTestSuite{ | ||
| 72 | void test_assert(bool result, | 72 | void test_assert(bool result, |
| 73 | const std::string& name, | 73 | const std::string& name, |
| 74 | const std::string& message=""); | 74 | const std::string& message=""); |
| 75 | + void test_value(double value, | ||
| 76 | + double value_expected, | ||
| 77 | + double eps = 0, | ||
| 78 | + const std::string& name="", | ||
| 79 | + const std::string& message=""); | ||
| 75 | void test_try(const std::string& name); | 80 | void test_try(const std::string& name); |
| 76 | void test_try_success(); | 81 | void test_try_success(); |
| 77 | void test_try_failure(const std::string& message="", | 82 | void test_try_failure(const std::string& message="", |
| 78 | - const std::string& type=""); | 83 | + const std::string& type=""); |
| 79 | void test_try_failure(const std::exception& e); | 84 | void test_try_failure(const std::exception& e); |
| 80 | GException::test_failure& exception_failure(const std::string& message); | 85 | GException::test_failure& exception_failure(const std::string& message); |
| 81 | GException::test_error& exception_error(const std::string& message); | 86 | GException::test_error& exception_error(const std::string& message); |
pyext/GTestSuite.i
| @@ -56,6 +56,11 @@ class GTestSuite{ | @@ -56,6 +56,11 @@ class GTestSuite{ | ||
| 56 | void test_assert(bool result, | 56 | void test_assert(bool result, |
| 57 | const std::string& name, | 57 | const std::string& name, |
| 58 | const std::string& message=""); | 58 | const std::string& message=""); |
| 59 | + void test_value( double value, | ||
| 60 | + double value_expected, | ||
| 61 | + double eps = 0, | ||
| 62 | + const std::string& name="", | ||
| 63 | + const std::string& message=""); | ||
| 59 | void test_try(const std::string& name); | 64 | void test_try(const std::string& name); |
| 60 | void test_try_success(); | 65 | void test_try_success(); |
| 61 | void test_try_failure(const std::string& message="", | 66 | void test_try_failure(const std::string& message="", |
src/test/GTestSuite.cpp
| @@ -30,6 +30,7 @@ | @@ -30,6 +30,7 @@ | ||
| 30 | #include <config.h> | 30 | #include <config.h> |
| 31 | #endif | 31 | #endif |
| 32 | #include "GTestSuite.hpp" | 32 | #include "GTestSuite.hpp" |
| 33 | +#include "GTools.hpp" | ||
| 33 | #include "GLog.hpp" | 34 | #include "GLog.hpp" |
| 34 | 35 | ||
| 35 | /* __ Method name definitions ____________________________________________ */ | 36 | /* __ Method name definitions ____________________________________________ */ |
| @@ -306,10 +307,52 @@ void GTestSuite::test_assert(bool assert, const std::string& name,const std::str | @@ -306,10 +307,52 @@ void GTestSuite::test_assert(bool assert, const std::string& name,const std::str | ||
| 306 | 307 | ||
| 307 | // Return | 308 | // Return |
| 308 | return; | 309 | return; |
| 309 | - | 310 | + |
| 310 | } | 311 | } |
| 311 | 312 | ||
| 312 | /***********************************************************************//** | 313 | /***********************************************************************//** |
| 314 | + * @brief Test a value | ||
| 315 | + * @param[in] value Value to test | ||
| 316 | + * @param[in] value_expected Value expected | ||
| 317 | + * @param[in] eps Precision of the test (default 0) | ||
| 318 | + * @param[in] name Test case name. (defaults to "") | ||
| 319 | + * @param[in] message Test case message. (defaults to "") | ||
| 320 | + * Test if the value is between [ value_excepted-eps, value_excepted+eps ] | ||
| 321 | + ***************************************************************************/ | ||
| 322 | +void GTestSuite::test_value(double value, double value_expected, double eps, const std::string& name, const std::string& message){ | ||
| 323 | + | ||
| 324 | + std::string formated_name; | ||
| 325 | + if(name!=""){ | ||
| 326 | + formated_name = format_name(name); | ||
| 327 | + } | ||
| 328 | + else{ | ||
| 329 | + formated_name = format_name("Test "+str(value)+" is between ["+str(value_expected-eps)+","+str(value_expected+eps)+"]"); | ||
| 330 | + } | ||
| 331 | + // Create a test case of failure type | ||
| 332 | + GTestCase* testcase = new GTestCase(GTestCase::FAIL_TEST,formated_name); | ||
| 333 | + | ||
| 334 | + // If value is not between [ value_excepted-eps, value_excepted+eps ] | ||
| 335 | + if(value > value_expected + eps || value < value_expected - eps) | ||
| 336 | + { | ||
| 337 | + // test case is not ok | ||
| 338 | + testcase->m_passed=false; | ||
| 339 | + | ||
| 340 | + //increment number of failures | ||
| 341 | + m_failures++; | ||
| 342 | + } | ||
| 343 | + //Set message | ||
| 344 | + testcase->message(message); | ||
| 345 | + | ||
| 346 | + // Show the result ( ".","F" or, "E") | ||
| 347 | + m_log<<testcase->print_result(); | ||
| 348 | + | ||
| 349 | + // Add the test in the container | ||
| 350 | + m_tests.push_back(testcase); | ||
| 351 | + | ||
| 352 | + // Return | ||
| 353 | + return; | ||
| 354 | +} | ||
| 355 | +/***********************************************************************//** | ||
| 313 | * @brief Test an try block | 356 | * @brief Test an try block |
| 314 | * @param[in] name Test case name. (defaults to "") | 357 | * @param[in] name Test case name. (defaults to "") |
| 315 | * @see test_try_sucess() | 358 | * @see test_try_sucess() |
test/test_GObservations.cpp
| @@ -139,7 +139,7 @@ GModelPar& TestGObservation::test_observations_optimizer(int mode) | @@ -139,7 +139,7 @@ GModelPar& TestGObservation::test_observations_optimizer(int mode) | ||
| 139 | test_assert(opt.status()==0,"Check if converged","Optimizer did not convered"); | 139 | test_assert(opt.status()==0,"Check if converged","Optimizer did not convered"); |
| 140 | 140 | ||
| 141 | //check if value is correct | 141 | //check if value is correct |
| 142 | - test_assert(fabs(result.value()-RATE) < result.error()*3,"check if value is correct","Value is not precise enough."); | 142 | + test_value(result.value(),RATE,result.error()*3); |
| 143 | 143 | ||
| 144 | return (((obs.models())[0])[0]); | 144 | return (((obs.models())[0])[0]); |
| 145 | } | 145 | } |