Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
radix
Commits
5bbeef85
Commit
5bbeef85
authored
Aug 18, 2021
by
LEFEBVREJP email
Browse files
Merge branch 'fuzzy_compare_test' into 'master'
Fuzzy compare test See merge request
!121
parents
e1cafb65
c5fde039
Pipeline
#159795
passed with stages
in 18 minutes and 3 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
radixcore/fuzzy.cc
View file @
5bbeef85
#include "radixcore/fuzzy.hh"
#include <algorithm>
#include <cmath>
namespace
radix
{
bool
fuzzy_compare
(
double
p1
,
double
p2
)
...
...
radixcore/fuzzy.hh
View file @
5bbeef85
#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 @
5bbeef85
...
...
@@ -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 @
5bbeef85
#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
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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