Changeset 1064 for library/tests/mat_checks.h
- Timestamp:
- 06/09/10 14:00:40 (16 years ago)
- Files:
-
- 1 modified
-
library/tests/mat_checks.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
library/tests/mat_checks.h
r727 r1064 32 32 const itpp::vec &actual, double tolerance, 33 33 TestDetails const &details ) { 34 if ( !AreClose ( expected, actual, tolerance ) ) {35 MemoryOutStream stream;36 stream << "Expected " << expected << " +/- " << tolerance << " but was " << actual;34 if ( !AreClose ( expected, actual, tolerance ) ) { 35 MemoryOutStream stream; 36 stream << "Expected " << expected << " +/- " << tolerance << " but was " << actual; 37 37 38 results.OnTestFailure ( details, stream.GetText() );39 }38 results.OnTestFailure ( details, stream.GetText() ); 39 } 40 40 } 41 41 … … 43 43 const itpp::mat &actual, double tolerance, 44 44 TestDetails const &details ) { 45 if ( !AreClose ( expected, actual, tolerance ) ) {46 MemoryOutStream stream;47 stream << "Expected " << expected << " +/- " << tolerance << " but was " << actual;45 if ( !AreClose ( expected, actual, tolerance ) ) { 46 MemoryOutStream stream; 47 stream << "Expected " << expected << " +/- " << tolerance << " but was " << actual; 48 48 49 results.OnTestFailure ( details, stream.GetText() );50 }49 results.OnTestFailure ( details, stream.GetText() ); 50 } 51 51 } 52 52 … … 56 56 tests (currently 2). */ 57 57 inline itpp::vec make_close_tolerance ( const itpp::vec & variance, int nsamples ) { 58 // simplify overloading for Visual Studio59 return 3 * ( sqrt ( variance ) / sqrt ( static_cast<double> ( nsamples ) ) );58 // simplify overloading for Visual Studio 59 return 3 * ( sqrt ( variance ) / sqrt ( static_cast<double> ( nsamples ) ) ); 60 60 } 61 61 … … 64 64 class CurrentContext { 65 65 public: 66 // how many times to repeat a failing test before reporting67 // failure68 static const int max_trial_count = 3;66 // how many times to repeat a failing test before reporting 67 // failure 68 static const int max_trial_count = 3; 69 69 70 70 private: 71 static const char *config_name;72 static int index;71 static const char *config_name; 72 static int index; 73 73 74 74 public: 75 // the pointer must stay valid for the lifetime of the object76 CurrentContext ( const char *name, int idx );77 ~CurrentContext();75 // the pointer must stay valid for the lifetime of the object 76 CurrentContext ( const char *name, int idx ); 77 ~CurrentContext(); 78 78 79 /* Should be called only in blocks having an instance of80 CurrentContext. The argument, when not default, should be81 __LINE__ (and it is included in the returned string).82 */83 static std::string format_context ( int ln = -1 );79 /* Should be called only in blocks having an instance of 80 CurrentContext. The argument, when not default, should be 81 __LINE__ (and it is included in the returned string). 82 */ 83 static std::string format_context ( int ln = -1 ); 84 84 85 template<typename Expected, typename Actual>86 static void CheckEqualEx ( UnitTest::TestResults& results,87 Expected const& expected,88 Actual const& actual,89 UnitTest::TestDetails const& details ) {90 if ( ! ( expected == actual ) ) {91 UnitTest::MemoryOutStream stream;92 stream << format_context() << "expected " << expected << " but was " << actual;85 template<typename Expected, typename Actual> 86 static void CheckEqualEx ( UnitTest::TestResults& results, 87 Expected const& expected, 88 Actual const& actual, 89 UnitTest::TestDetails const& details ) { 90 if ( ! ( expected == actual ) ) { 91 UnitTest::MemoryOutStream stream; 92 stream << format_context() << "expected " << expected << " but was " << actual; 93 93 94 results.OnTestFailure ( details, stream.GetText() );95 }96 }94 results.OnTestFailure ( details, stream.GetText() ); 95 } 96 } 97 97 98 template<typename Expected, typename Actual, typename Tolerance>99 static void CheckCloseEx ( UnitTest::TestResults& results,100 Expected const& expected,101 Actual const& actual,102 Tolerance const& tolerance,103 UnitTest::TestDetails const& details ) {104 if ( !UnitTest::AreClose ( expected, actual, tolerance ) ) {105 UnitTest::MemoryOutStream stream;106 stream << format_context() << "expected " << expected << " +/- " << tolerance << " but was " << actual;98 template<typename Expected, typename Actual, typename Tolerance> 99 static void CheckCloseEx ( UnitTest::TestResults& results, 100 Expected const& expected, 101 Actual const& actual, 102 Tolerance const& tolerance, 103 UnitTest::TestDetails const& details ) { 104 if ( !UnitTest::AreClose ( expected, actual, tolerance ) ) { 105 UnitTest::MemoryOutStream stream; 106 stream << format_context() << "expected " << expected << " +/- " << tolerance << " but was " << actual; 107 107 108 results.OnTestFailure ( details, stream.GetText() );109 }110 }108 results.OnTestFailure ( details, stream.GetText() ); 109 } 110 } 111 111 }; 112 112
