#ifndef _tst_Validatrix_h_ #define _tst_Validatrix_h_ #include #include #include #include #include #include namespace tst { namespace Validatrix { const double kDefaultTolerance = 1e-6; enum CompareType { eEqual = 0, eAbsolute = 1, eRelative = 2 }; template struct Type; template<> struct Type { static const char Code = 'i'; }; template<> struct Type { static const char Code = 'i'; }; template<> struct Type { static const char Code = 'i'; }; template<> struct Type { static const char Code = 'i'; }; template<> struct Type { static const char Code = 'u'; }; template<> struct Type { static const char Code = 'u'; }; template<> struct Type { static const char Code = 'u'; }; template<> struct Type { static const char Code = 'u'; }; template<> struct Type { static char const Code = 'd'; }; template<> struct Type { static char const Code = 'd'; }; inline char CompareCode(const CompareType c) { const char comp[] = { 'e', 'a', 'r' }; return comp[c]; } template std::string Pack(const std::size_t n, const T* const v, const CompareType c, const double tolerance = kDefaultTolerance) { if (!n) return ""; std::ostringstream os; os << Type::Code; if (n > 1) os << '[' << n << ']'; os << CompareCode(c); if (c != eEqual && tolerance != kDefaultTolerance) os << '@' << tolerance; os << ' '; for (std::size_t i = 0; i < n; ++i) os << v[i] << ' '; return os.str(); } template std::string Pack(const T& value, const CompareType c, const double tolerance = kDefaultTolerance) { return Pack(1, &value, c, tolerance); } template std::string Pack(const utl::Trace& trace, const CompareType c, const double tolerance = kDefaultTolerance) { return Pack(trace.GetSize(), &(*trace.Begin()), c, tolerance); } template std::string Pack(const std::vector& vec, const CompareType c, const double tolerance = kDefaultTolerance) { return Pack(vec.size(), &vec.front(), c, tolerance); } template std::string Pack(const utl::TimeDistribution& td, const CompareType c, const double tolerance = kDefaultTolerance) { typedef utl::TimeDistribution TD; typedef typename TD::SparseIterator TDI; std::string res; for (TDI it = td.SparseBegin(), end = td.SparseEnd(); it != end; ++it) { res.append(Pack(it->template get<0>(), eEqual)); res.append(Pack(it->template get<1>(), c, tolerance)); } return res; } template std::string BeEqual(const T& value) { return Pack(value, eEqual); } template std::string BeEqual(const std::size_t n, const T* const v) { return Pack(n, v, eEqual); } /*template std::string BeEqual(const std::size_t n, const std::vector* const v) { return Pack(n, v, eEqual); }*/ template std::string BeCloseAbs(const T& value, const double tolerance = kDefaultTolerance) { return Pack(value, eAbsolute, tolerance); } template std::string CloseAbs(const std::size_t n, const T* const v, const double tolerance = kDefaultTolerance) { return Pack(n, v, eAbsolute, tolerance); } /*template std::string BeCloseAbs(const std::size_t n, const std::vector* const v, const double tolerance = kDefaultTolerance) { return Pack(n, v, eAbsolute, tolerance); }*/ template std::string BeCloseRel(const T& value, const double tolerance = kDefaultTolerance) { return Pack(value, eRelative, tolerance); } template std::string BeCloseRel(const std::size_t n, const T* const v, const double tolerance = kDefaultTolerance) { return Pack(n, v, eRelative, tolerance); } /*template std::string BeCloseRel(const std::size_t n, const std::vector* const v, const double tolerance = kDefaultTolerance) { return Pack(n, v, eRelative, tolerance); }*/ std::string BeLabel(const std::string& tag); bool Compare(std::istream& s1, std::istream& s2, const bool failOnFirst = true); } } #endif