root/library/tests/mat_checks.cpp @ 1064

Revision 1064, 1.8 kB (checked in by mido, 14 years ago)

astyle applied all over the library

  • Property svn:eol-style set to native
RevLine 
[426]1#include "mat_checks.h"
[481]2#include <sstream>
[426]3
[477]4namespace UnitTest {
[426]5
[477]6bool AreClose ( const itpp::vec &expected, const itpp::vec &actual,
7                double tolerance ) {
[1064]8    if ( expected.length() != actual.length() ) {
9        return false;
10    }
[428]11
[1064]12    for ( int i = 0; i < expected.length(); ++i ) {
13        if ( !AreClose ( expected ( i ), actual ( i ), tolerance ) ) {
14            return false;
15        }
16    }
[428]17
[1064]18    return true;
[428]19}
20
[477]21bool AreClose ( const itpp::vec &expected, const itpp::vec &actual,
22                const itpp::vec &tolerance ) {
[1064]23    if ( ( expected.length() != actual.length() ) ||
24            ( actual.length() != tolerance.length() ) ) {
25        return false;
26    }
[465]27
[1064]28    for ( int i = 0; i < expected.length(); ++i ) {
29        if ( !AreClose ( expected ( i ), actual ( i ), tolerance ( i ) ) ) {
30            return false;
31        }
32    }
[465]33
[1064]34    return true;
[465]35}
36
[477]37bool AreClose ( const itpp::mat &expected, const itpp::mat &actual, double tolerance ) {
[1064]38    if ( ( expected.rows() != actual.rows() ) ||
39            ( expected.cols() != actual.cols() ) ) {
40        return false;
41    }
[426]42
[1064]43    for ( int i = 0; i < expected.rows(); ++i ) {
44        for ( int j = 0; j < expected.cols(); ++j ) {
45            if ( !AreClose ( expected ( i, j ), actual ( i, j ), tolerance ) ) {
46                return false;
47            }
48        }
49    }
[477]50
[1064]51    return true;
[426]52}
53
54}
[456]55
56const char *CurrentContext::config_name = "???";
57
58int CurrentContext::index = -1;
59
[477]60CurrentContext::CurrentContext ( const char *name, int idx ) {
[1064]61    config_name = name;
62    index = idx;
[456]63}
64
[477]65CurrentContext::~CurrentContext() {
[1064]66    config_name = "???";
67    index = -1;
[456]68}
[481]69
[722]70std::string CurrentContext::format_context ( int ln ) {
[1064]71    std::stringstream ss;
72    ss << "error at " << config_name << '[' << index << ']';
[481]73
[1064]74    if ( ln >= 0 ) {
75        ss << ", harness line " << ln;
76    }
[481]77
[1064]78    ss << ": ";
79    return ss.str();
[481]80}
Note: See TracBrowser for help on using the browser.