Changeset 465
- Timestamp:
- 08/03/09 08:09:16 (16 years ago)
- Location:
- library/tests
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
library/tests/epdf_harness.cpp
r462 r465 88 88 vec emu = smp * ones(n) / n; 89 89 mat er = (smp * smp.T()) / n - outer_product(emu, emu); 90 CHECK_CLOSE_EX(mean, emu, tolerance); 90 91 vec delta = sqrt(variance) / sqrt(nsamples); 92 CHECK_CLOSE_EX(mean, emu, delta); 93 91 94 CHECK_CLOSE_EX(R, er, tolerance); 92 95 } -
library/tests/mat_checks.cpp
r456 r465 12 12 for (int i = 0; i < expected.length(); ++i) { 13 13 if (!AreClose(expected(i), actual(i), tolerance)) { 14 return false; 15 } 16 } 17 18 return true; 19 } 20 21 bool AreClose(const itpp::vec &expected, const itpp::vec &actual, 22 const itpp::vec &tolerance) { 23 if ((expected.length() != actual.length()) || 24 (actual.length() != tolerance.length())) { 25 return false; 26 } 27 28 for (int i = 0; i < expected.length(); ++i) { 29 if (!AreClose(expected(i), actual(i), tolerance(i))) { 14 30 return false; 15 31 } -
library/tests/mat_checks.h
r456 r465 22 22 bool AreClose(const itpp::vec &expected, const itpp::vec &actual, 23 23 double tolerance); 24 25 bool AreClose(const itpp::vec &expected, const itpp::vec &actual, 26 const itpp::vec &tolerance); 24 27 25 28 bool AreClose(const itpp::mat &expected, const itpp::mat &actual, … … 50 53 } 51 54 52 /*! CHECK_ CLOSE_EX macro should be used only in blocks having an53 instance of this class (which sets the globals for error54 reporting). */55 /*! CHECK_EQUAL_EX and CHECK_CLOSE_EX macros should be used only in 56 blocks having an instance of this class (which sets the globals for 57 error reporting). */ 55 58 class CurrentContext 56 59 { … … 64 67 ~CurrentContext(); 65 68 66 template< typename Expected, typename Actual, typename Tolerance > 69 template<typename Expected, typename Actual> 70 static void CheckEqualEx(UnitTest::TestResults& results, 71 Expected const& expected, 72 Actual const& actual, 73 UnitTest::TestDetails const& details) { 74 if (!(expected == actual)) { 75 UnitTest::MemoryOutStream stream; 76 stream << "error at " << config_name << '[' << index << "]: expected " << expected << " but was " << actual; 77 78 results.OnTestFailure(details, stream.GetText()); 79 } 80 } 81 82 template<typename Expected, typename Actual, typename Tolerance> 67 83 static void CheckCloseEx(UnitTest::TestResults& results, 68 84 Expected const& expected, … … 79 95 }; 80 96 97 #define CHECK_EQUAL_EX(expected, actual) \ 98 do \ 99 { \ 100 try { \ 101 CurrentContext::CheckEqualEx(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), 0, false)); \ 102 } \ 103 catch (...) { \ 104 UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ 105 "Unhandled exception in CHECK_EQUAL_EX(" #expected ", " #actual ")"); \ 106 } \ 107 } while (0) 108 109 81 110 #define CHECK_CLOSE_EX(expected, actual, tolerance) \ 82 111 do \ … … 87 116 catch (...) { \ 88 117 UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \ 89 "Unhandled exception in CHECK_CLOSE (" #expected ", " #actual ")"); \118 "Unhandled exception in CHECK_CLOSE_EX(" #expected ", " #actual ")"); \ 90 119 } \ 91 120 } while (0)