Commit c5fde039 authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Fuzzy compare test

parent e1cafb65
#include "radixcore/fuzzy.hh"
#include <algorithm>
#include <cmath>
namespace radix
{
bool fuzzy_compare(double p1, double p2)
......
#ifndef RADIX_RADIXCORE_FUZZY_HH_
#define RADIX_RADIXCORE_FUZZY_HH_
#include <algorithm>
#include <cmath>
#include "radixcore/visibility.hh"
namespace radix
{
/**
* @brief fuzzy_compare Compares two doubles. The smaller the number the
* tighter the tolerance.
* @param p1 double
* @param p2 double
* @return true p1 == p2, false otherwise
*/
RADIX_PUBLIC bool fuzzy_compare(double p1, double p2);
/**
* @brief fuzzy_compare Compares two floats. The smaller the number the tighter
* the tolerance.
* @param p1 double
* @param p2 double
* @return true p1 == p2, false otherwise
*/
RADIX_PUBLIC bool fuzzy_compare(float p1, float p2);
} // namespace radix
......
......@@ -3,6 +3,7 @@ INCLUDE(GoogleTest)
ADD_GOOGLE_TEST(tstJson.cc NP 1)
ADD_GOOGLE_TEST(tstRange.cc NP 1)
ADD_GOOGLE_TEST(tstBug.cc NP 1)
ADD_GOOGLE_TEST(tstFuzzy.cc NP 1)
ADD_GOOGLE_TEST(tstCommandLine.cc NP 1)
ADD_GOOGLE_TEST(tstString.cc NP 1)
ADD_GOOGLE_TEST(tstSystem.cc NP 1)
......
#include "gtest/gtest.h"
#include "radixcore/fuzzy.hh"
using namespace radix;
TEST(RadixCore, FuzzyCompare)
{
EXPECT_TRUE(fuzzy_compare(1.0, 1.0));
EXPECT_TRUE(fuzzy_compare(1.0f, 1.0f));
EXPECT_FALSE(fuzzy_compare(1., 2.));
EXPECT_FALSE(fuzzy_compare(1.f, 2.f));
EXPECT_TRUE(fuzzy_compare(-1.0, -1.0));
EXPECT_TRUE(fuzzy_compare(-1.0f, -1.0f));
EXPECT_FALSE(fuzzy_compare(-1., -2.));
EXPECT_FALSE(fuzzy_compare(-1.f, -2.f));
EXPECT_TRUE(fuzzy_compare(0.0000000000000001, 0.0000000000000001));
EXPECT_FALSE(fuzzy_compare(0.0000000000000001, 0.0000000000000002));
EXPECT_TRUE(fuzzy_compare(10.00000000001, 10.000000000002));
EXPECT_TRUE(fuzzy_compare(-0.0000000000000001, -0.0000000000000001));
EXPECT_FALSE(fuzzy_compare(-0.0000000000000001, -0.0000000000000002));
EXPECT_TRUE(fuzzy_compare(-10.00000000001, -10.000000000002));
EXPECT_TRUE(fuzzy_compare(0.0000000000000001f, 0.0000000000000001f));
EXPECT_FALSE(fuzzy_compare(0.0000000000000001f, 0.0000000000000002f));
EXPECT_TRUE(fuzzy_compare(10.00000000001f, 10.000000000002f));
EXPECT_TRUE(fuzzy_compare(-0.0000000000000001f, -0.0000000000000001f));
EXPECT_FALSE(fuzzy_compare(-0.0000000000000001f, -0.0000000000000002f));
EXPECT_TRUE(fuzzy_compare(-10.00000000001f, -10.000000000002f));
}
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 to comment