///------------------------------------------------------------------------------------------------- /// /// \file utils.hpp /// \brief Some constants and functions for google tests /// \author Thibaut Monseigne (Inria). /// \version 0.1. /// \date 26/10/2018. /// \copyright GNU Affero General Public License v3.0. /// ///------------------------------------------------------------------------------------------------- #pragma once #include "openvibe/CIdentifier.hpp" #include "openvibe/CTime.hpp" #include #include #include const std::string SEP = "\n====================\n"; //--------------------------------------------------------------------------------------------------- /// Check if double are almost equals. /// The first number. /// The second number. /// The tolerance. /// true if almmost equals, false otherwise. inline bool AlmostEqual(const double a, const double b, const double epsilon = OV_EPSILON) { return std::fabs(a - b) < std::fabs(epsilon); } //***************************************************************** //********** Error Message Standardization for googltest ********** //***************************************************************** //--------------------------------------------------------------------------------------------------- /// Error message for numeric value. /// The name of the test. /// The reference value. /// The calculate value. /// Error message. /// Generic numeric type parameter. template ::value, T>::type> std::string ErrorMsg(const std::string& name, const T ref, const T calc) { std::stringstream ss; ss << SEP << name << " : Reference : " << ref << ", \tCompute : " << calc << SEP; return ss.str(); } //--------------------------------------------------------------------------------------------------- /// Error message for string value. /// inline std::string ErrorMsg(const std::string& name, const std::string& ref, const std::string& calc) { std::stringstream ss; ss << SEP << name << " : Reference : " << ref << ", \tCompute : " << calc << SEP; return ss.str(); } //--------------------------------------------------------------------------------------------------- /// Error message for CTime value. /// inline std::string ErrorMsg(const std::string& name, const OpenViBE::CTime& ref, const OpenViBE::CTime& calc) { std::stringstream ss; ss << SEP << name << " : Reference : " << ref.str(true, true) << ", \tCompute : " << calc.str(true, true) << SEP; return ss.str(); } //--------------------------------------------------------------------------------------------------- /// Error message for CIdentifier value. /// inline std::string ErrorMsg(const std::string& name, const OpenViBE::CIdentifier& ref, const OpenViBE::CIdentifier& calc) { std::stringstream ss; ss << SEP << name << " : Reference : " << ref << ", \tCompute : " << calc << SEP; return ss.str(); } //--------------------------------------------------------------------------------------------------- /// Error message for CIdentifier value. /// inline std::string ErrorMsg(const std::string& name, const OpenViBE::CMatrix& ref, const OpenViBE::CMatrix& calc) { std::stringstream ss; ss << SEP << name << " : " << std::endl << "********** Reference **********\n" << ref << std::endl << "********** Compute **********\n" << calc << SEP; return ss.str(); }