File: 0010-Use-BOOST_CHECK_CLOSE-for-floating-point-comparisons.patch

package info (click to toggle)
opm-common 2024.10%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 98,420 kB
  • sloc: cpp: 263,013; python: 3,155; sh: 198; xml: 174; pascal: 136; makefile: 12
file content (40 lines) | stat: -rw-r--r-- 1,914 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
From: Markus Blatt <markus@dr-blatt.de>
Date: Tue, 25 May 2021 11:42:50 +0200
Subject: Use BOOST_CHECK_CLOSE for floating point comparisons.

BOOST_CHECK_EQUAL will only reliably work if the computations on the
left and right hand side were made in the exact same order, which is
often not the case.
---
 tests/parser/ScheduleTests.cpp       | 4 ++--
 tests/test_nonuniformtablelinear.cpp | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests/parser/ScheduleTests.cpp b/tests/parser/ScheduleTests.cpp
index 8558aaa..32fb107 100644
--- a/tests/parser/ScheduleTests.cpp
+++ b/tests/parser/ScheduleTests.cpp
@@ -1447,8 +1447,8 @@ WELTARG
     BOOST_CHECK_EQUAL( wpp_2.WaterRate.get<std::string>(), "WUWRAT" );
     const auto prod_controls = wpp_2.controls(st, 0);
 
-    BOOST_CHECK_EQUAL(prod_controls.oil_rate, 10 * siFactorL);
-    BOOST_CHECK_EQUAL(prod_controls.water_rate, 20 * siFactorL);
+    BOOST_CHECK_CLOSE(prod_controls.oil_rate, 10 * siFactorL, 1e-13);
+    BOOST_CHECK_CLOSE(prod_controls.water_rate, 20 * siFactorL, 1e-13);
 
     BOOST_CHECK (wpp_2.hasProductionControl( Opm::Well::ProducerCMode::ORAT) );
     BOOST_CHECK (wpp_2.hasProductionControl( Opm::Well::ProducerCMode::WRAT) );
diff --git a/tests/test_nonuniformtablelinear.cpp b/tests/test_nonuniformtablelinear.cpp
index 5c44c6c..1d5ac64 100644
--- a/tests/test_nonuniformtablelinear.cpp
+++ b/tests/test_nonuniformtablelinear.cpp
@@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(table_operations)
     BOOST_CHECK_EQUAL(t1.domain().first, new_domain.first);
     BOOST_CHECK_EQUAL(t1.domain().second, new_domain.second);
     for (int i = 0; i < numvals; ++i) {
-        BOOST_CHECK_EQUAL(t1((xv[i] + 1.0)*20.0 - 100.0), yv[i]);
+        BOOST_CHECK_CLOSE(t1((xv[i] + 1.0)*20.0 - 100.0), yv[i], 1e-13);
     }
     BOOST_CHECK_CLOSE(t1(0.0), 3.0, 1e-13);
     BOOST_CHECK(std::fabs(t1.derivative(0.0)  + 1.0/20.0) < 1e-11);