Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
radix
Commits
c5fde039
Commit
c5fde039
authored
Aug 18, 2021
by
LEFEBVREJP email
Browse files
Fuzzy compare test
parent
e1cafb65
Changes
4
Hide whitespace changes
Inline
Side-by-side
radixcore/fuzzy.cc
View file @
c5fde039
#include
"radixcore/fuzzy.hh"
#include
<algorithm>
#include
<cmath>
namespace
radix
{
bool
fuzzy_compare
(
double
p1
,
double
p2
)
...
...
radixcore/fuzzy.hh
View file @
c5fde039
#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
...
...
radixcore/tests/CMakeLists.txt
View file @
c5fde039
...
...
@@ -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
)
...
...
radixcore/tests/tstFuzzy.cc
0 → 100644
View file @
c5fde039
#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.0
f
,
1.0
f
));
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.0
f
,
-
1.0
f
));
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.0000000000000001
f
,
0.0000000000000001
f
));
EXPECT_FALSE
(
fuzzy_compare
(
0.0000000000000001
f
,
0.0000000000000002
f
));
EXPECT_TRUE
(
fuzzy_compare
(
10.00000000001
f
,
10.000000000002
f
));
EXPECT_TRUE
(
fuzzy_compare
(
-
0.0000000000000001
f
,
-
0.0000000000000001
f
));
EXPECT_FALSE
(
fuzzy_compare
(
-
0.0000000000000001
f
,
-
0.0000000000000002
f
));
EXPECT_TRUE
(
fuzzy_compare
(
-
10.00000000001
f
,
-
10.000000000002
f
));
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment