[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master e08be34 12/23: Improve a unit test
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master e08be34 12/23: Improve a unit test |
Date: |
Tue, 27 Jul 2021 21:59:52 -0400 (EDT) |
branch: master
commit e08be34eab3c62bbcd8d56eb4f09802f55eb2b4d
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Improve a unit test
---
zero_test.cpp | 47 ++++++++++++++++++++++++++++-------------------
1 file changed, 28 insertions(+), 19 deletions(-)
diff --git a/zero_test.cpp b/zero_test.cpp
index fd6b326..be3dbd9 100644
--- a/zero_test.cpp
+++ b/zero_test.cpp
@@ -213,7 +213,15 @@ void test_a_decimal_function
/// Test with all biases, asserting obvious invariants.
template<typename F>
-void test_bias(double bound0, double bound1, int dec, F f, double exact_root)
+void test_bias
+ (double bound0
+ ,double bound1
+ ,int dec
+ ,F f
+ ,double exact_root
+ ,int line
+ ,char const* file = __FILE__
+ )
{
double maximum_error = max_err(exact_root, 0.5 * std::pow(10.0, -dec));
@@ -221,15 +229,16 @@ void test_bias(double bound0, double bound1, int dec, F
f, double exact_root)
root_type rl = decimal_root(f, bound0, bound1, bias_lower, dec);
root_type rh = decimal_root(f, bound0, bound1, bias_higher, dec);
- LMI_TEST(root_is_valid == rn.validity);
- LMI_TEST(root_is_valid == rl.validity);
- LMI_TEST(root_is_valid == rh.validity);
+ INVOKE_LMI_TEST_RELATION(root_is_valid,==,rn.validity,file,line);
+ INVOKE_LMI_TEST_RELATION(root_is_valid,==,rl.validity,file,line);
+ INVOKE_LMI_TEST_RELATION(root_is_valid,==,rh.validity,file,line);
- LMI_TEST(rl.root <= rn.root && rn.root <= rh.root);
+ INVOKE_LMI_TEST_RELATION(rl.root,<=,rn.root,file,line);
+ INVOKE_LMI_TEST_RELATION(rn.root,<=,rh.root,file,line);
- LMI_TEST(std::fabs(rh.root - rl.root) <= maximum_error);
- LMI_TEST(std::fabs(rl.root - exact_root) <= maximum_error);
- LMI_TEST(std::fabs(rh.root - exact_root) <= maximum_error);
+ INVOKE_LMI_TEST_RELATION(std::fabs(rh.root -
rl.root),<=,maximum_error,file,line);
+ INVOKE_LMI_TEST_RELATION(std::fabs(rl.root -
exact_root),<=,maximum_error,file,line);
+ INVOKE_LMI_TEST_RELATION(std::fabs(rh.root -
exact_root),<=,maximum_error,file,line);
}
double e_function(double z)
@@ -673,19 +682,19 @@ void test_biases()
// Rounding to -100 decimals makes the maximum error 1e+100,
// which probably isn't useful in practice.
- test_bias(0.0, 4.0e100, -100, e, std::exp(1.0));
- test_bias(0.0, 4.0 , 0, e, std::exp(1.0));
- test_bias(0.5, 5.0 , 1, e, std::exp(1.0));
- test_bias(0.5, 5.0 , 2, e, std::exp(1.0));
- test_bias(0.5, 5.0 , 3, e, std::exp(1.0));
- test_bias(0.5, 5.0 , 4, e, std::exp(1.0));
- test_bias(0.5, 5.0 , 5, e, std::exp(1.0));
- test_bias(0.5, 5.0 , 6, e, std::exp(1.0));
- test_bias(0.5, 5.0 , 7, e, std::exp(1.0));
- test_bias(0.5, 5.0 , 8, e, std::exp(1.0));
+ test_bias(0.0, 4.0e100, -100, e, std::exp(1.0), __LINE__);
+ test_bias(0.0, 4.0 , 0, e, std::exp(1.0), __LINE__);
+ test_bias(0.5, 5.0 , 1, e, std::exp(1.0), __LINE__);
+ test_bias(0.5, 5.0 , 2, e, std::exp(1.0), __LINE__);
+ test_bias(0.5, 5.0 , 3, e, std::exp(1.0), __LINE__);
+ test_bias(0.5, 5.0 , 4, e, std::exp(1.0), __LINE__);
+ test_bias(0.5, 5.0 , 5, e, std::exp(1.0), __LINE__);
+ test_bias(0.5, 5.0 , 6, e, std::exp(1.0), __LINE__);
+ test_bias(0.5, 5.0 , 7, e, std::exp(1.0), __LINE__);
+ test_bias(0.5, 5.0 , 8, e, std::exp(1.0), __LINE__);
// Rounding to 100 decimals shouldn't round at all; the
// effective maximum error is 6ϵ × e = 3.62148e-15 .
- test_bias(0.0, 4.0 , 100, e, std::exp(1.0));
+ test_bias(0.0, 4.0 , 100, e, std::exp(1.0), __LINE__);
}
/// Test the worked-out example given here:
- [lmi-commits] [lmi] master 4b26bf8 01/23: Add a parenthetical comment to a unit test, (continued)
- [lmi-commits] [lmi] master 4b26bf8 01/23: Add a parenthetical comment to a unit test, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 86ae65d 18/23: Revert "Demonstration, for immediate reversion", Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master e59df26 14/23: Refactor, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 8f2f355 19/23: Augment unit tests; record some observations, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master a259cb6 05/23: Calculate maximum possible number of iterations, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master d0a65c2 04/23: Demonstrate that Brent's δ can be almost arbitrarily small, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 548f9ab 06/23: Document known shortcomings of a unit-testing helper, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 19a4a3a 03/23: For now at least, trace solves in regression test, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 04c58eb 09/23: Count iterations and evaluations separately, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master bbf2517 10/23: Use signum() where a signum function is wanted, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master e08be34 12/23: Improve a unit test,
Greg Chicares <=
- [lmi-commits] [lmi] master 02dde17 13/23: Avoid catastrophic cancellation, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master d2dcbf8 15/23: Reduce complexity, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master e93ca8f 17/23: Demonstration, for immediate reversion, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 4500338 22/23: Simplify, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 2ad4944 20/23: Record some more observations--no files changed, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 028b454 23/23: Find any root with only 64 function evaluations, Greg Chicares, 2021/07/27