lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 55873f1 13/13: Test an uncommon code path


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 55873f1 13/13: Test an uncommon code path
Date: Sun, 4 Jul 2021 19:04:46 -0400 (EDT)

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

    Test an uncommon code path
---
 zero_test.cpp | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/zero_test.cpp b/zero_test.cpp
index c26a16c..be1ad58 100644
--- a/zero_test.cpp
+++ b/zero_test.cpp
@@ -535,6 +535,21 @@ void test_various_functions()
     auto root_05 = 1.4142135623730951;
     test_a_decimal_function(f05, root_05, 0.0 , 2.0, 17     , __LINE__, 10);
     test_a_function        (f05, root_05, 0.0 , 2.0, 1.0e-15, __LINE__);
+
+    // Despite its apparent insipidity, this is actually a very
+    // interesting test: after the first iterate has been calculated
+    // as -0.05 by linear interpolation, the values are:
+    //   a, fa   1.9   -0.39
+    //   b, fb  -0.05  -3.9975
+    //   c, fc  -2.1    0.41
+    // so fb and fc have the same sign while |fc| < |fb|, which is
+    // an uncommon conjunction of circumstances that this unit test
+    // contrives to engender. Usually the second test is met only if
+    // the first is, too.
+    auto f06 = [](double x) {return x * x - 4.0;};
+    auto root_06 = -2.0;
+    test_a_function        (f06, root_06 , 1.9, -2.1, 1.0e-15, __LINE__);
+    test_a_function        (f06, root_06, -2.1 , 1.9, 1.0e-15, __LINE__);
 }
 
 void test_hodgepodge()



reply via email to

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