Fixed some 'double comparison' tests.

Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
Viktor Govako
2021-12-01 16:44:15 +03:00
committed by Konstantin Pastbin
parent 2529d5bf5d
commit 0c7e6300f5
3 changed files with 38 additions and 4 deletions

View File

@@ -67,7 +67,11 @@ UNIT_TEST(AlmostEqualULPs_double)
TEST(!base::AlmostEqualULPs(1.0, -1.0), ());
TEST(!base::AlmostEqualULPs(2.0, -2.0), ());
TEST(!base::AlmostEqualULPs(dmax, -dmax), ());
// That's why AlmostEqualULPs is a strange function, IMHO.
TEST(!base::AlmostEqualULPs(0.0, eps), ());
TEST(!base::AlmostEqualULPs(-eps, 0.0), ());
TEST(!base::AlmostEqualULPs(eps, 2.0*eps), ());
}
UNIT_TEST(AlmostEqualULPs_float)
@@ -91,7 +95,11 @@ UNIT_TEST(AlmostEqualULPs_float)
TEST(!base::AlmostEqualULPs(1.0f, -1.0f), ());
TEST(!base::AlmostEqualULPs(2.0f, -2.0f), ());
TEST(!base::AlmostEqualULPs(dmax, -dmax), ());
// That's why AlmostEqualULPs is a strange function, IMHO.
TEST(!base::AlmostEqualULPs(0.0f, eps), ());
TEST(!base::AlmostEqualULPs(-eps, 0.0f), ());
TEST(!base::AlmostEqualULPs(eps, 2.0f*eps), ());
}
UNIT_TEST(AlmostEqual_Smoke)

View File

@@ -1,6 +1,7 @@
#include "testing/testing.hpp"
#include "drape_frontend/path_text_handle.hpp"
#include "drape_frontend/visual_params.hpp"
#include "base/logging.hpp"
@@ -15,10 +16,12 @@ bool IsSmooth(m2::SplineEx const & spline)
}
return true;
}
}
} // namespace
UNIT_TEST(Rounding_Spline)
{
df::VisualParams::Init(1.0, 1024);
m2::SplineEx spline1;
df::AddPointAndRound(spline1, m2::PointD(0, 200));
df::AddPointAndRound(spline1, m2::PointD(0, 0));

View File

@@ -12,15 +12,38 @@ using namespace std;
using m2::Spline;
using m2::PointD;
namespace
{
double constexpr kAlmostZero = 1.0E-16;
void TestEqual(double x, double y)
{
if (fabs(x) < kAlmostZero || fabs(y) < kAlmostZero)
TEST_ALMOST_EQUAL_ABS(x, y, kAlmostZero, ());
else
TEST_ALMOST_EQUAL_ULPS(x, y, ());
}
void TestPointDDir(PointD const & dst, PointD const & src)
{
double const len1 = dst.Length();
double const len2 = src.Length();
TEST_ALMOST_EQUAL_ULPS(dst.x/len1, src.x/len2, ());
TEST_ALMOST_EQUAL_ULPS(dst.y/len1, src.y/len2, ());
if (len1 < kAlmostZero || len2 < kAlmostZero)
{
TestEqual(dst.x, src.x);
TestEqual(dst.y, src.y);
}
else
{
TestEqual(dst.x/len1, src.x/len2);
TestEqual(dst.y/len1, src.y/len2);
}
}
UNIT_TEST(SmoothedDirections)
} // namespace
UNIT_TEST(Spline_SmoothedDirections)
{
vector<PointD> path;
path.push_back(PointD(0, 0));