lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 5c31ab3 09/22: Fix latent unit-test errors


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 5c31ab3 09/22: Fix latent unit-test errors
Date: Sun, 6 Jun 2021 21:38:00 -0400 (EDT)

branch: master
commit 5c31ab387a96d881341d0ebd4d12d800429beb8d
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Fix latent unit-test errors
    
    Delving the problem identified in commit 83dc78bf6d89d of 20210604T2059Z
    to the core reveals that tests of the form
      (observed - expected) <= tolerance
    can be made stricter by using the absolute value of the LHS, and that
    tests so straitened can be made to succeed by choosing an objective
    function that has a zero at the expected value.
---
 zero_test.cpp | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/zero_test.cpp b/zero_test.cpp
index 2ee0635..3cde119 100644
--- a/zero_test.cpp
+++ b/zero_test.cpp
@@ -26,7 +26,9 @@
 #include "materially_equal.hpp"
 #include "test_tools.hpp"
 
-#include <algorithm>
+#include <algorithm>                    // max()
+#include <cmath>                        // exp(), fabs(), log(), pow(), 
signbit()
+#include <limits>
 
 namespace
 {
@@ -52,19 +54,19 @@ void test_zero(double bound0, double bound1, int dec, F f, 
double exact_root)
                 (std::fabs(rl.first), std::fabs(rh.first)
                 )
         ;
-    LMI_TEST((rh.first - rl.first) <= tol);
+    LMI_TEST(std::fabs(rh.first - rl.first) <= tol);
 
     double toll =
             std::pow(10.0, -dec)
         +   6.0 * epsilon * std::fabs(rl.first)
         ;
-    LMI_TEST((rl.first - exact_root) <= toll);
+    LMI_TEST(std::fabs(rl.first - exact_root) <= toll);
 
     double tolh =
             std::pow(10.0, -dec)
         +   6.0 * epsilon * std::fabs(rh.first)
         ;
-    LMI_TEST((rh.first - exact_root) <= tolh);
+    LMI_TEST(std::fabs(rh.first - exact_root) <= tolh);
 }
 
 double e_function(double z)
@@ -249,9 +251,9 @@ int test_main(int, char*[])
     double d = brent_zero(-1.0, 4.0, 1.0e-20, e_19);
     LMI_TEST(std::fabs(d) <= epsilon);
 
-//  test_zero(-1.0, 4.0, -100, e_19, std::exp(1.0));
-    test_zero(-1.0, 4.0,    0, e_19, std::exp(1.0));
-    test_zero(-1.0, 4.0,  100, e_19, std::exp(1.0));
+    test_zero(-1.0e100, 4.0e100, -100, e, std::exp(1.0));
+    test_zero(-1.0    , 4.0    ,    0, e, std::exp(1.0));
+    test_zero(-1.0    , 4.0    ,  100, e, std::exp(1.0));
 
     d = brent_zero(-100.0, 100.0, 1.0e-20, eq_2_1);
     LMI_TEST(-100.0 <= d && d <= -100.0 * (1.0 - 6.0 * epsilon));



reply via email to

[Prev in Thread] Current Thread [Next in Thread]