Changeset 465

Show
Ignore:
Timestamp:
08/03/09 08:09:16 (15 years ago)
Author:
vbarta
Message:

computing mean tolerance from variance

Location:
library/tests
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • library/tests/epdf_harness.cpp

    r462 r465  
    8888        vec emu = smp * ones(n) / n; 
    8989        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 
    9194        CHECK_CLOSE_EX(R, er, tolerance); 
    9295    } 
  • library/tests/mat_checks.cpp

    r456 r465  
    1212    for (int i = 0; i < expected.length(); ++i) { 
    1313        if (!AreClose(expected(i), actual(i), tolerance)) { 
     14            return false; 
     15        } 
     16    } 
     17 
     18    return true; 
     19} 
     20 
     21bool 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))) { 
    1430            return false; 
    1531        } 
  • library/tests/mat_checks.h

    r456 r465  
    2222bool AreClose(const itpp::vec &expected, const itpp::vec &actual, 
    2323              double tolerance); 
     24 
     25bool AreClose(const itpp::vec &expected, const itpp::vec &actual, 
     26              const itpp::vec &tolerance); 
    2427 
    2528bool AreClose(const itpp::mat &expected, const itpp::mat &actual, 
     
    5053} 
    5154 
    52 /*! CHECK_CLOSE_EX macro should be used only in blocks having an 
    53   instance of this class (which sets the globals for error 
    54   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). */ 
    5558class CurrentContext 
    5659{ 
     
    6467    ~CurrentContext(); 
    6568 
    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> 
    6783    static void CheckCloseEx(UnitTest::TestResults& results, 
    6884                             Expected const& expected, 
     
    7995}; 
    8096 
     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 
    81110#define CHECK_CLOSE_EX(expected, actual, tolerance) \ 
    82111    do \ 
     
    87116        catch (...) { \ 
    88117            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 ")"); \ 
    90119        } \ 
    91120    } while (0)