Commit e2c3eb0a by Szeberényi Imre

almostEQ fix

parent c7dedca7
......@@ -2,14 +2,15 @@
#define GTEST_LITE_H
/**
* \file gtest_lite.h (v3/2019)
* \file gtest_lite.h (v4/2022)
*
* Google gtest keretrendszerhez hasonló rendszer.
* Sz.I. 2015., 2016., 2017. (_Has_X)
* Sz.I. 2018 (template), ENDM, ENDMsg, nullptr_t
* Sz.I. 2019 singleton
* Sz.I. 2021 ASSERT.., STRCASE...
* Sz.I. 2021 EXPEXT_REGEXP, CREATE_Has_fn_, cmp w. NULL
* Sz.I. 2021 EXPEXT_REGEXP, CREATE_Has_fn_, cmp w. NULL, EXPECT_ param fix
* V.B., Sz.I. 2022 almostEQ fix
*
* A tesztelés legalapvetőbb funkcióit támogató függvények és makrók.
* Nem szálbiztos megvalósítás.
......@@ -339,8 +340,8 @@ public:
static Test& test = Test::getTest();
/// általános sablon a várt értékhez.
template <typename T>
std::ostream& EXPECT_(T exp, T act, bool (*pred)(T, T), const char *file, int line,
template <typename T1, typename T2>
std::ostream& EXPECT_(T1 exp, T2 act, bool (*pred)(T1, T1), const char *file, int line,
const char *expr, const char *lhs = "elvart", const char *rhs = "aktual") {
return test.expect(pred(exp, act), file, line, expr)
<< "** " << lhs << ": " << std::boolalpha << exp
......@@ -348,8 +349,8 @@ std::ostream& EXPECT_(T exp, T act, bool (*pred)(T, T), const char *file, int li
}
/// pointerre specializált sablon a várt értékhez.
template <typename T>
std::ostream& EXPECT_(T* exp, T* act, bool (*pred)(T*, T*), const char *file, int line,
template <typename T1, typename T2>
std::ostream& EXPECT_(T1* exp, T2* act, bool (*pred)(T1*, T1*), const char *file, int line,
const char *expr, const char *lhs = "elvart", const char *rhs = "aktual") {
return test.expect(pred(exp, act), file, line, expr)
<< "** " << lhs << ": " << (void*) exp
......@@ -463,16 +464,16 @@ template <typename T>
bool almostEQ(T a, T b) {
// eps: ha a relatív, vagy abszolút hiba ettől kisebb, akkor elfogadjuk
T eps = 10 * std::numeric_limits<T>::epsilon(); // 10-szer a legkisebb érték
if (a == b) return true;
if (fabs(a - b) < eps)
T diff = fabs(a - b);
if (diff < eps)
return true;
double aa = fabs(a);
double ba = fabs(b);
T aa = fabs(a);
T ba = fabs(b);
if (aa < ba) {
aa = ba;
ba = fabs(a);
}
return (aa - ba) < aa * eps;
return diff < aa * eps;
}
/// Segédsablon ostream átirányításához
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment