[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));
- [lmi-commits] [lmi] master updated (f0526be -> 86661b6), Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 7bd1245 01/22: Add a unit test: root of another unfriendly function, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master c01b9b0 02/22: Improve concinnity, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 012967c 08/22: Diagnose any attempt to find a root in a zero-measure interval, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 83eb025 05/22: Rename a local variable, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master ec0a308 06/22: Refactor, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 99aebcc 07/22: Treat decimal_root return value more flexibly, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 5c31ab3 09/22: Fix latent unit-test errors,
Greg Chicares <=
- [lmi-commits] [lmi] master 2391573 11/22: Rename a variable, for terseness, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master b14e318 18/22: Adjust tolerance for a particular unit-test function, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 1c448d8 20/22: Augment decimal_root()'s return type, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 53c3513 21/22: Reorder unit tests, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 5cf534c 04/22: Constify, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 3865416 10/22: Rearrange certain unit tests, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 1f8316c 16/22: Test actual return value, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 3d4adb3 17/22: Clarify, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 200e756 03/22: Clarify documentation, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 1b0ed06 12/22: Change argument order, Greg Chicares, 2021/06/06