gctl/lib/utility/assess.h

101 lines
4.0 KiB
C
Raw Permalink Normal View History

2024-09-10 15:45:07 +08:00
/********************************************************
*
*
*
*
*
*
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. You can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#ifndef _GCTL_ASSESS_H
#define _GCTL_ASSESS_H
#include "iostream"
#include "string"
#include "cmath"
#include "ctime"
#include "chrono"
/* Basic assess. If fails, returns msg. If passes, returns 0 */
#define GCTL_Assess(test, msg) \
do { if (!(test)) return msg; return "NULL";} while (0)
/* Assess if val equals expect within a certain precision prec */
#define GCTL_AssessAlmostEqual(val, expect, prec, msg) \
do { if(!(val <= expect + prec && val >= expect - prec)) return msg; return "NULL";} while (0)
/* Assess if val equals expect within a certain precision precision given in % */
#define GCTL_AssessAlmostEqualRel(val, expect, prec, msg) \
do { if(fabs(val - expect) > 0.01*prec*fabs(expect)) return msg; return "NULL";} while (0)
namespace gctl
{
/**
* @brief
*
*
* run_test()summary()
*/
class assess
{
public:
/**
* @brief
*/
assess();
/**
* @brief
*/
virtual ~assess();
/**
* @brief
*/
void clear();
/**
* @brief
*
* NULL,
*
* @return
*/
typedef std::string (*test_func_ptr)(void);
/**
* @brief
*
* @param[in] f_ptr
* @param[in] verbose
*
* @return 01
*/
int run_test(test_func_ptr f_ptr, std::string verbose);
/**
* @brief
*
* @return
*/
bool summary();
protected:
int tests_run, tests_passed, tests_failed;
std::chrono::system_clock::time_point start_t;
};
}
#endif // _GCTL_ASSESS_H