summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/catch/projects/SelfTest/ApproxTests.cpp
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2017-02-05 15:45:26 +0100
committer Miodrag Milanovic <mmicko@gmail.com>2017-02-05 15:46:07 +0100
commit02c97cd0f7c4d630f1a90f9f2626746e47a28c09 (patch)
tree2b48d051a55f2b65525824546cd9fcf9e05907cf /3rdparty/catch/projects/SelfTest/ApproxTests.cpp
parentd20b4ba6864b45d0c068d98d43e63c8bc5014a3b (diff)
Updated Catch to latest (nw)
Diffstat (limited to '3rdparty/catch/projects/SelfTest/ApproxTests.cpp')
-rw-r--r--3rdparty/catch/projects/SelfTest/ApproxTests.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/3rdparty/catch/projects/SelfTest/ApproxTests.cpp b/3rdparty/catch/projects/SelfTest/ApproxTests.cpp
index 53656596c0a..6b7cf44a394 100644
--- a/3rdparty/catch/projects/SelfTest/ApproxTests.cpp
+++ b/3rdparty/catch/projects/SelfTest/ApproxTests.cpp
@@ -42,6 +42,36 @@ TEST_CASE
///////////////////////////////////////////////////////////////////////////////
TEST_CASE
(
+ "Less-than inequalities with different epsilons",
+ "[Approx]"
+)
+{
+ double d = 1.23;
+
+ REQUIRE( d <= Approx( 1.24 ) );
+ REQUIRE( d <= Approx( 1.23 ) );
+ REQUIRE_FALSE( d <= Approx( 1.22 ) );
+ REQUIRE( d <= Approx( 1.22 ).epsilon(0.1) );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+TEST_CASE
+(
+ "Greater-than inequalities with different epsilons",
+ "[Approx]"
+)
+{
+ double d = 1.23;
+
+ REQUIRE( d >= Approx( 1.22 ) );
+ REQUIRE( d >= Approx( 1.23 ) );
+ REQUIRE_FALSE( d >= Approx( 1.24 ) );
+ REQUIRE( d >= Approx( 1.24 ).epsilon(0.1) );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+TEST_CASE
+(
"Approximate comparisons with floats",
"[Approx]"
)
@@ -110,3 +140,48 @@ TEST_CASE( "Approximate PI", "[Approx][PI]" )
REQUIRE( divide( 22, 7 ) == Approx( 3.141 ).epsilon( 0.001 ) );
REQUIRE( divide( 22, 7 ) != Approx( 3.141 ).epsilon( 0.0001 ) );
}
+
+////////////////////////////////////////////////////////////////////////////////
+
+#if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS)
+class StrongDoubleTypedef
+{
+ double d_ = 0.0;
+
+ public:
+ explicit StrongDoubleTypedef(double d) : d_(d) {}
+ explicit operator double() const { return d_; }
+};
+
+inline std::ostream& operator<<( std::ostream& os, StrongDoubleTypedef td ) {
+ return os << "StrongDoubleTypedef(" << static_cast<double>(td) << ")";
+}
+
+TEST_CASE
+(
+ "Comparison with explicitly convertible types",
+ "[Approx]"
+)
+{
+ StrongDoubleTypedef td(10.0);
+
+ REQUIRE(td == Approx(10.0));
+ REQUIRE(Approx(10.0) == td);
+
+ REQUIRE(td != Approx(11.0));
+ REQUIRE(Approx(11.0) != td);
+
+ REQUIRE(td <= Approx(10.0));
+ REQUIRE(td <= Approx(11.0));
+ REQUIRE(Approx(10.0) <= td);
+ REQUIRE(Approx(9.0) <= td);
+
+ REQUIRE(td >= Approx(9.0));
+ REQUIRE(td >= Approx(10.0));
+ REQUIRE(Approx(10.0) >= td);
+ REQUIRE(Approx(11.0) >= td);
+
+}
+#endif
+
+////////////////////////////////////////////////////////////////////////////////