diff options
Diffstat (limited to 'src/GeneralizedPolynomial-Uniform/test_molecule_posn.c')
-rw-r--r-- | src/GeneralizedPolynomial-Uniform/test_molecule_posn.c | 447 |
1 files changed, 227 insertions, 220 deletions
diff --git a/src/GeneralizedPolynomial-Uniform/test_molecule_posn.c b/src/GeneralizedPolynomial-Uniform/test_molecule_posn.c index bd3a1f9..4f6a5f5 100644 --- a/src/GeneralizedPolynomial-Uniform/test_molecule_posn.c +++ b/src/GeneralizedPolynomial-Uniform/test_molecule_posn.c @@ -7,11 +7,27 @@ * Usage: * test_molecule_posn # run a preset set of tests * test_molecule_posn molecule_size \ - * out_of_range_tolerance_min \ - * out_of_range_tolerance_max \ + * boundary_off_centering_tolerance_min \ + * boundary_off_centering_tolerance_max \ + * boundary_extrapolation_tolerance_min \ + * boundary_extrapolation_tolerance_max \ + * boundary_off_centering_tolerance_max \ * x # do a single test as specified */ +const char* help_msg = +"usage:\n" +"# run a preset series of tests:\n" +" test_molecule_posn\n" +"# run a single test as specified:\n" +" test_molecule_posn molecule_size \\\n" +" boundary_off_centering_tolerance_min \\\n" +" boundary_off_centering_tolerance_max \\\n" +" boundary_extrapolation_tolerance_min \\\n" +" boundary_extrapolation_tolerance_max \\\n" +" x\n" +; + #include <math.h> #include <string.h> #include <limits.h> @@ -39,8 +55,10 @@ const int grid_i_max = 105; /* x_max = 13.6 */ */ static void run_interactive_test(int molecule_size, - fp out_of_range_tolerance_min, - fp out_of_range_tolerance_max, + fp boundary_off_centering_tolerance_min, + fp boundary_off_centering_tolerance_max, + fp boundary_extrapolation_tolerance_min, + fp boundary_extrapolation_tolerance_max, fp x); static int run_batch_tests(void); @@ -56,152 +74,135 @@ struct args_results { /* args */ int molecule_size; - fp out_of_range_tolerance_min; - fp out_of_range_tolerance_max; + fp boundary_off_centering_tolerance_min; + fp boundary_off_centering_tolerance_max; + fp boundary_extrapolation_tolerance_min; + fp boundary_extrapolation_tolerance_max; fp x; /* results */ + int status; int i_center; fp x_rel; - int m_min, m_max; }; /* test data */ +#define OK 0 +#define X_LT_MIN MOLECULE_POSN_ERROR_X_LT_MIN +#define X_GT_MAX MOLECULE_POSN_ERROR_X_GT_MAX static const struct args_results test_data[] = { - /* molecule size 2 */ - { 2, 1.0, 1.0e-12, 7.19, INT_MIN, -1.1, 0,+1 }, - { 2, 1.0, 1.0e-12, 7.21, 42, -0.9, 0,+1 }, - { 2, 1.0, 1.0e-12, 7.24, 42, -0.6, 0,+1 }, - { 2, 1.0, 1.0e-12, 7.26, 42, -0.4, 0,+1 }, - { 2, 1.0, 1.0e-12, 7.29, 42, -0.1, 0,+1 }, - { 2, -1.0, 1.0e-12, 7.29, INT_MIN, -0.1, 0,+1 }, - { 2, 1.0e-12, 1.0e-12, 7.3, 42, 0.0, 0,+1 },/* grid_x_min */ - { 2, 1.0e-12, 1.0e-12, 7.31, 42, +0.1, 0,+1 }, - { 2, -1.0 , 1.0e-12, 7.31, 42, +0.1, 0,+1 }, - { 2, 1.0e-12, 1.0e-12, 7.35, 42, +0.5, 0,+1 }, - { 2, 1.0e-12, 1.0e-12, 7.39, 42, +0.9, 0,+1 }, - { 2, 1.0e-12, 1.0e-12, 7.41, 43, 0.1, 0,+1 }, - { 2, 1.0e-12, 1.0e-12, 9.81, 67, +0.1, 0,+1 }, - { 2, 1.0e-12, 1.0e-12, 9.85, 67, +0.5, 0,+1 }, - { 2, 1.0e-12, 1.0e-12, 9.89, 67, +0.9, 0,+1 }, - { 2, 1.0e-12, 1.0e-12, 13.45, 103, +0.5, 0,+1 }, - { 2, 1.0e-12, 1.0e-12, 13.51, 104, +0.1, 0,+1 }, - { 2, 1.0e-12, 1.0e-12, 13.55, 104, +0.5, 0,+1 }, - { 2, 1.0e-12, 1.0e-12, 13.59, 104, +0.9, 0,+1 }, - { 2, 1.0e-12, -1.0, 13.59, 104, +0.9, 0,+1 }, - { 2, 1.0e-12, 1.0e-12, 13.6, 104, +1.0, 0,+1 },/* grid_x_max */ - { 2, 1.0e-12, 1.0, 13.61, 104, +1.1, 0,+1 }, - { 2, 1.0e-12, -1.0, 13.61, INT_MAX, +1.1, 0,+1 }, - { 2, 1.0e-12, 1.0, 13.65, 104, +1.5, 0,+1 }, - { 2, 1.0e-12, 1.0, 13.69, 104, +1.9, 0,+1 }, - { 2, 1.0e-12, 1.0, 13.71, INT_MAX, +2.1, 0,+1 }, - - /* molecule size 3 */ - { 3, 1.0, 1.0e-12, 7.19, INT_MIN, -2.1, -1,+1 }, - { 3, 1.0, 1.0e-12, 7.21, 43, -1.9, -1,+1 }, - { 3, 1.0, 1.0e-12, 7.24, 43, -1.6, -1,+1 }, - { 3, 1.0, 1.0e-12, 7.26, 43, -1.4, -1,+1 }, - { 3, 1.0, 1.0e-12, 7.29, 43, -1.1, -1,+1 }, - { 3, -1.0, 1.0e-12, 7.29, INT_MIN, -1.1, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 7.3, 43, -1.0, -1,+1 },/* grid_x_min */ - { 3, 1.0e-12, 1.0e-12, 7.31, 43, -0.9, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 7.34, 43, -0.6, -1,+1 }, - { 3, -1.0, 1.0e-12, 7.34, INT_MIN, -0.6, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 7.36, 43, -0.4, -1,+1 }, - { 3, -1.0, 1.0e-12, 7.36, 43, -0.4, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 7.39, 43, -0.1, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 7.4, 43, 0.0, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 7.44, 43, +0.4, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 7.46, 44, -0.4, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 9.8, 67, 0.0, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 9.81, 67, +0.1, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 9.84, 67, +0.4, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 9.86, 68, -0.4, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 9.89, 68, -0.1, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 9.9, 68, 0.0, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 13.44, 103, +0.4, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 13.46, 104, -0.4, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 13.5, 104, 0.0, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 13.51, 104, +0.1, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 13.54, 104, +0.4, -1,+1 }, - { 3, 1.0e-12, -1.0, 13.54, 104, +0.4, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 13.56, 104, +0.6, -1,+1 }, - { 3, 1.0e-12, -1.0, 13.56, INT_MAX, +0.6, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 13.59, 104, +0.9, -1,+1 }, - { 3, 1.0e-12, 1.0e-12, 13.6, 104, +1.0, -1,+1 },/* grid_x_max */ - { 3, 1.0e-12, 1.0, 13.61, 104, +1.1, -1,+1 }, - { 3, 1.0e-12, 1.0, 13.65, 104, +1.5, -1,+1 }, - { 3, 1.0e-12, 1.0, 13.69, 104, +1.9, -1,+1 }, - { 3, 1.0e-12, 1.0, 13.71, INT_MAX, +2.1, -1,+1 }, - - /* molecule size 4 */ - { 4, 0.2, 1.0e-12, 7.27, INT_MIN, -1.3, -1,+2 }, - { 4, 0.2, 1.0e-12, 7.29, 43, -1.1, -1,+2 }, - { 4, 1.0e-12, 1.0e-12, 7.3, 43, -1.0, -1,+2 },/* grid_x_min */ - { 4, 1.0e-12, 1.0e-12, 7.33, 43, -0.7, -1,+2 }, - { 4, 1.0e-12, 1.0e-12, 7.39, 43, -0.1, -1,+2 }, - { 4, -1.0, 1.0e-12, 7.39, INT_MIN, -0.1, -1,+2 }, - { 4, 1.0e-12, 1.0e-12, 7.4, 43, 0.0, -1,+2 }, - { 4, -1.0, 1.0e-12, 7.41, 43, +0.1, -1,+2 }, - { 4, 1.0e-12, 1.0e-12, 7.42, 43, +0.2, -1,+2 }, - { 4, 1.0e-12, 1.0e-12, 7.48, 43, +0.8, -1,+2 }, - { 4, 1.0e-12, 1.0e-12, 7.51, 44, +0.1, -1,+2 }, - { 4, 1.0e-12, 1.0e-12, 9.81, 67, +0.1, -1,+2 }, - { 4, 1.0e-12, 1.0e-12, 9.85, 67, +0.5, -1,+2 }, - { 4, 1.0e-12, 1.0e-12, 9.89, 67, +0.9, -1,+2 }, - { 4, 1.0e-12, 1.0e-12, 13.39, 102, +0.9, -1,+2 }, - { 4, 1.0e-12, 1.0e-12, 13.41, 103, +0.1, -1,+2 }, - { 4, 1.0e-12, 1.0e-12, 13.48, 103, +0.8, -1,+2 }, - { 4, 1.0e-12, -1.0, 13.48, 103, +0.8, -1,+2 }, - { 4, 1.0e-12, 1.0e-12, 13.5, 103, +1.0, -1,+2 }, - { 4, 1.0e-12, 1.0e-12, 13.51, 103, +1.1, -1,+2 }, - { 4, 1.0e-12, -1.0, 13.51, INT_MAX, +1.1, -1,+2 }, - { 4, 1.0e-12, 1.0e-12, 13.55, 103, +1.5, -1,+2 }, - { 4, 1.0e-12, 1.0e-12, 13.59, 103, +1.9, -1,+2 }, - { 4, 1.0e-12, 1.0e-12, 13.6, 103, +2.0, -1,+2 },/* grid_x_max */ - { 4, 1.0e-12, 2.0, 13.79, 103, +3.9, -1,+2 }, - { 4, 1.0e-12, 2.0, 13.81, INT_MAX, +4.1, -1,+2 }, - - /* molecule size 5 */ - { 5, 3.0, 1.0e-12, 6.99, INT_MIN, -5.1, -2,+2 }, - { 5, 3.0, 1.0e-12, 7.01, 44, -4.9, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 7.3, 44, -2.0, -2,+2 },/* grid_x_min */ - { 5, 1.0e-12, 1.0e-12, 7.4, 44, -1.0, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 7.44, 44, -0.6, -2,+2 }, - { 5, -1.0, 1.0e-12, 7.44, INT_MIN, -0.6, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 7.46, 44, -0.4, -2,+2 }, - { 5, -1.0, 1.0e-12, 7.46, 44, -0.4, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 7.49, 44, -0.1, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 7.5, 44, 0.0, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 7.54, 44, +0.4, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 7.56, 45, -0.4, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 7.6, 45, 0.0, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 7.64, 45, +0.4, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 9.8, 67, 0.0, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 9.81, 67, +0.1, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 9.84, 67, +0.4, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 9.86, 68, -0.4, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 9.89, 68, -0.1, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 9.9, 68, 0.0, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 13.34, 102, +0.4, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 13.36, 103, -0.4, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 13.39, 103, -0.1, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 13.41, 103, +0.1, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 13.44, 103, +0.4, -2,+2 }, - { 5, 1.0e-12, -1.0, 13.44, 103, +0.4, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 13.46, 103, +0.6, -2,+2 }, - { 5, 1.0e-12, -1.0, 13.46, INT_MAX, +0.6, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 13.48, 103, +0.8, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 13.5, 103, +1.0, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 13.51, 103, +1.1, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 13.54, 103, +1.4, -2,+2 }, - { 5, 1.0e-12, -1.0, 13.54, INT_MAX, +1.4, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 13.56, 103, +1.6, -2,+2 }, - { 5, 1.0e-12, -1.0, 13.56, INT_MAX, +1.6, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 13.59, 103, +1.9, -2,+2 }, - { 5, 1.0e-12, 1.0e-12, 13.6, 103, +2.0, -2,+2 },/* grid_x_max */ - { 5, 1.0e-12, 1.5, 13.74, 103, +3.4, -2,+2 }, - { 5, 1.0e-12, 1.5, 13.76, INT_MAX, +3.6, -2,+2 }, + /*** molecule size 2 ***/ + /* status */ + /* off_centering extrapolation i_center */ + /* min max min max x x_rel */ + { 2, 999.0, 999.0, 1.0, 999.0, 7.19, X_LT_MIN, 0, 0.0 }, + { 2, 999.0, 999.0, 1.0, 999.0, 7.21, OK, 42, -0.9 }, + { 2, 999.0, 999.0, 1.0, 999.0, 7.24, OK, 42, -0.6 }, + { 2, 999.0, 999.0, 1.0, 999.0, 7.26, OK, 42, -0.4 }, + { 2, 0.0, 0.0, 1.0, 999.0, 7.26, X_LT_MIN, 0, 0.0 }, + { 2, 1.0e-6, 999.0, 0.2, 999.0, 7.29, X_LT_MIN, 0, 0.0 }, + { 2, 0.2, 999.0, 1.0e-6, 999.0, 7.29, X_LT_MIN, 0, 0.0 }, + { 2, 0.2, 999.0, 0.2, 999.0, 7.29, OK, 42, -0.1 }, + { 2, 0.0, 0.0, 1.0e-6, 999.0, 7.31, OK, 42, +0.1 }, + { 2, 0.0, 0.0, 1.0e-6, 999.0, 7.34, OK, 42, +0.4 }, + { 2, 0.0, 0.0, 1.0e-6, 999.0, 7.36, OK, 42, +0.6 }, + { 2, 0.0, 0.0, 1.0e-6, 999.0, 7.39, OK, 42, +0.9 }, + { 2, 0.0, 0.0, 1.0e-6, 999.0, 7.41, OK, 43, +0.1 }, + { 2, 0.0, 0.0, 1.0e-6, 1.0e-6, 9.81, OK, 67, +0.1 }, + { 2, 0.0, 0.0, 1.0e-6, 1.0e-6, 9.84, OK, 67, +0.4 }, + { 2, 0.0, 0.0, 1.0e-6, 1.0e-6, 9.85, OK, 67, +0.5 }, + { 2, 0.0, 0.0, 1.0e-6, 1.0e-6, 9.86, OK, 67, +0.6 }, + { 2, 0.0, 0.0, 1.0e-6, 1.0e-6, 9.89, OK, 67, +0.9 }, + { 2, 0.0, 0.0, 1.0e-6, 1.0e-6, 13.45, OK, 103, +0.5 }, + { 2, 0.0, 0.0, 1.0e-6, 1.0e-6, 13.51, OK, 104, +0.1 }, + { 2, 0.0, 0.0, 1.0e-6, 1.0e-6, 13.59, OK, 104, +0.9 }, + { 2, 0.0, 0.2, 1.0e-6, 1.0e-6, 13.61, X_GT_MAX, 0, 0.0 }, + { 2, 0.0, 1.0e-6, 1.0e-6, 1.0e-6, 13.61, X_GT_MAX, 0, 0.0 }, + { 2, 0.0, 0.2, 0.0, 0.2, 13.61, OK, 104, +1.1 }, + + /*** molecule size 3 ***/ + /* status */ + /* off_centering extrapolation i_center */ + /* min max min max x x_rel */ + { 3, 0.5, 999.0, 999.0, 999.0, 7.29, X_LT_MIN, 0, 0.0 }, + { 3, 999.0, 999.0, 0.0, 999.0, 7.29, X_LT_MIN, 0, 0.0 }, + { 3, 0.7, 999.0, 0.2, 999.0, 7.29, OK, 43, -1.1 }, + { 3, 0.3, 999.0, 0.0, 999.0, 7.31, X_LT_MIN, 0, 0.0 }, + { 3, 0.5, 999.0, 0.0, 999.0, 7.31, OK, 43, -0.9 }, + { 3, 0.0, 0.0, 0.0, 0.0, 7.36, OK, 43, -0.4 }, + { 3, 0.0, 0.0, 0.0, 0.0, 7.44, OK, 43, +0.4 }, + { 3, 0.0, 0.0, 0.0, 0.0, 7.46, OK, 44, -0.4 }, + { 3, 0.0, 0.0, 0.0, 0.0, 9.81, OK, 67, +0.1 }, + { 3, 0.0, 0.0, 0.0, 0.0, 9.84, OK, 67, +0.4 }, + { 3, 0.0, 0.0, 0.0, 0.0, 9.86, OK, 68, -0.4 }, + { 3, 0.0, 0.0, 0.0, 0.0, 9.89, OK, 68, -0.1 }, + { 3, 0.0, 0.0, 0.0, 0.0, 13.44, OK, 103, +0.4 }, + { 3, 0.0, 0.0, 0.0, 0.0, 13.46, OK, 104, -0.4 }, + { 3, 0.0, 0.0, 0.0, 0.0, 13.54, OK, 104, +0.4 }, + { 3, 0.0, 0.2, 0.0, 0.0, 13.56, OK, 104, +0.6 }, + { 3, 999.0, 0.0, 999.0, 999.0, 13.56, X_GT_MAX, 0, 0.0 }, + { 3, 0.0, 0.5, 0.0, 0.0, 13.59, OK, 104, +0.9 }, + { 3, 999.0, 0.3, 999.0, 999.0, 13.59, X_GT_MAX, 0, 0.0 }, + { 3, 999.0, 0.5, 999.0, 999.0, 13.61, X_GT_MAX, 0, 0.0 }, + { 3, 999.0, 999.0, 999.0, 0.0, 13.61, X_GT_MAX, 0, 0.0 }, + { 3, 999.0, 0.7, 999.0, 0.2, 13.61, OK, 104, +1.1 }, + { 3, 999.0, 999.0, 999.0, 0.2, 13.63, X_GT_MAX, 0, 0.0 }, + { 3, 999.0, 0.7, 999.0, 999.0, 13.63, X_GT_MAX, 0, 0.0 }, + { 3, 999.0, 0.9, 999.0, 0.4, 13.63, OK, 104, +1.3 }, + + /*** molecule size 4 ***/ + /* status */ + /* off_centering extrapolation i_center */ + /* min max min max x x_rel */ + { 4, 1.0, 999.0, 999.0, 999.0, 7.29, X_LT_MIN, 0, 0.0 }, + { 4, 999.0, 999.0, 0.0, 999.0, 7.29, X_LT_MIN, 0, 0.0 }, + { 4, 1.2, 999.0, 0.2, 999.0, 7.29, OK, 43, -1.1 }, + { 4, 0.5, 999.0, 0.0, 999.0, 7.31, X_LT_MIN, 0, 0.0 }, + { 4, 1.0, 999.0, 0.0, 999.0, 7.31, OK, 43, -0.9 }, + { 4, 0.0, 999.0, 0.0, 999.0, 7.39, X_LT_MIN, 0, 0.0 }, + { 4, 0.2, 999.0, 0.0, 999.0, 7.39, OK, 43, -0.1 }, + { 4, 0.0, 0.0, 0.0, 999.0, 7.41, OK, 43, +0.1 }, + { 4, 0.0, 0.0, 0.0, 999.0, 7.49, OK, 43, +0.9 }, + { 4, 0.0, 0.0, 0.0, 999.0, 7.51, OK, 44, +0.1 }, + { 4, 0.0, 0.0, 0.0, 0.0, 9.81, OK, 67, +0.1 }, + { 4, 0.0, 0.0, 0.0, 0.0, 9.84, OK, 67, +0.4 }, + { 4, 0.0, 0.0, 0.0, 0.0, 9.85, OK, 67, +0.5 }, + { 4, 0.0, 0.0, 0.0, 0.0, 9.86, OK, 67, +0.6 }, + { 4, 0.0, 0.0, 0.0, 0.0, 9.89, OK, 67, +0.9 }, + { 4, 0.0, 0.0, 0.0, 0.0, 13.44, OK, 103, +0.4 }, + { 4, 0.0, 0.0, 0.0, 0.0, 13.49, OK, 103, +0.9 }, + { 4, 0.0, 0.2, 0.0, 0.0, 13.51, OK, 103, +1.1 }, + { 4, 999.0, 0.0, 999.0, 999.0, 13.51, X_GT_MAX, 0, 0.0 }, + { 4, 999.0, 0.8, 999.0, 0.0, 13.59, X_GT_MAX, 0, 0.0 }, + { 4, 0.0, 1.0, 0.0, 0.0, 13.59, OK, 103, +1.9 }, + { 4, 999.0, 999.0, 999.0, 0.0, 13.61, X_GT_MAX, 0, 0.0 }, + { 4, 0.0, 1.0, 999.0, 999.0, 13.61, X_GT_MAX, 0, 0.0 }, + { 4, 0.0, 1.2, 0.0, 0.2, 13.61, OK, 103, +2.1 }, + + /*** molecule size 5 ***/ + /* status */ + /* off_centering extrapolation i_center */ + /* min max min max x x_rel */ + { 5, 1.5, 999.0, 999.0, 999.0, 7.29, X_LT_MIN, 0, 0.0 }, + { 5, 999.0, 999.0, 0.0, 999.0, 7.29, X_LT_MIN, 0, 0.0 }, + { 5, 1.7, 999.0, 0.2, 999.0, 7.29, OK, 44, -2.1 }, + { 5, 0.9, 999.0, 0.0, 999.0, 7.35, X_LT_MIN, 0, 0.0 }, + { 5, 1.1, 999.0, 0.0, 999.0, 7.35, OK, 44, -1.5 }, + { 5, 0.0, 999.0, 999.0, 999.0, 7.44, X_LT_MIN, 0, 0.0 }, + { 5, 0.2, 999.0, 0.0, 999.0, 7.44, OK, 44, -0.6 }, + { 5, 0.0, 0.0, 0.0, 0.0, 7.46, OK, 44, -0.4 }, + { 5, 0.0, 0.0, 0.0, 0.0, 9.81, OK, 67, +0.1 }, + { 5, 0.0, 0.0, 0.0, 0.0, 9.84, OK, 67, +0.4 }, + { 5, 0.0, 0.0, 0.0, 0.0, 9.86, OK, 68, -0.4 }, + { 5, 0.0, 0.0, 0.0, 0.0, 9.89, OK, 68, -0.1 }, + { 5, 0.0, 0.0, 0.0, 0.0, 13.44, OK, 103, +0.4 }, + { 5, 999.0, 0.0, 999.0, 999.0, 13.46, X_GT_MAX, 0, 0.0 }, + { 5, 0.0, 0.2, 0.0, 0.0, 13.46, OK, 103, +0.6 }, + { 5, 0.0, 1.1, 0.0, 0.0, 13.55, OK, 103, +1.5 }, + { 5, 999.0, 0.9, 999.0, 999.0, 13.55, X_GT_MAX, 0, 0.0 }, + { 5, 999.0, 999.0, 999.0, 0.0, 13.61, X_GT_MAX, 0, 0.0 }, + { 5, 999.0, 1.5, 999.0, 999.0, 13.61, X_GT_MAX, 0, 0.0 }, + { 5, 999.0, 1.7, 999.0, 0.2, 13.61, OK, 103, +2.1 }, }; #define N_TESTS ((int) (sizeof(test_data)/sizeof(test_data[0]))) @@ -212,7 +213,10 @@ int main(int argc, const char *const argv[]) { bool N_fail; int molecule_size; -double out_of_range_tolerance_min, out_of_range_tolerance_max; +fp boundary_off_centering_tolerance_min; +fp boundary_off_centering_tolerance_max; +fp boundary_extrapolation_tolerance_min; +fp boundary_extrapolation_tolerance_max; double x; switch (argc) @@ -222,44 +226,34 @@ case 1: N_fail = run_batch_tests(); if (N_fail == 0) then { - printf("*** all tests successful ***\n"); + printf("*** all %d tests successful ***\n", N_TESTS); return 0; } else { - printf("*** %d test(s) failed ***\n", N_fail); + printf("*** %d/%d test(s) failed ***\n", N_fail, N_TESTS); return 1; } -case 5: +case 7: if ( (sscanf(argv[1], "%d", &molecule_size) == 1) - && (sscanf(argv[2], "%lf", &out_of_range_tolerance_min) == 1) - && (sscanf(argv[3], "%lf", &out_of_range_tolerance_max) == 1) - && (sscanf(argv[4], "%lf", &x) == 1) ) + && (sscanf(argv[2], "%lf", &boundary_off_centering_tolerance_min) == 1) + && (sscanf(argv[3], "%lf", &boundary_off_centering_tolerance_max) == 1) + && (sscanf(argv[4], "%lf", &boundary_extrapolation_tolerance_min) == 1) + && (sscanf(argv[5], "%lf", &boundary_extrapolation_tolerance_max) == 1) + && (sscanf(argv[6], "%lf", &x) == 1) ) then { run_interactive_test(molecule_size, - out_of_range_tolerance_min, - out_of_range_tolerance_max, + boundary_off_centering_tolerance_min, + boundary_off_centering_tolerance_max, + boundary_extrapolation_tolerance_min, + boundary_extrapolation_tolerance_max, x); - return 0; + return 0; /*** NORMAL EXIT ***/ } - /* fall through */ + /* error ==> fall through */ default: - fprintf(stderr, - "usage:\n" - "# run a single test as specified:\n" - " %s molecule_size \\\n" - " %*s out_of_range_tolerance_min \\\n" - " %*s out_of_range_tolerance_max \\\n" - " %*s x\n" - "# run a preset set of tests:\n" - " %s\n" - , - argv[0], - (int) strlen(argv[0]), "", - (int) strlen(argv[0]), "", - (int) strlen(argv[0]), "", - argv[0]); + fprintf(stderr, help_msg); return 1; } } @@ -271,33 +265,39 @@ default: */ static void run_interactive_test(int molecule_size, - fp out_of_range_tolerance_min, - fp out_of_range_tolerance_max, + fp boundary_off_centering_tolerance_min, + fp boundary_off_centering_tolerance_max, + fp boundary_extrapolation_tolerance_min, + fp boundary_extrapolation_tolerance_max, fp x) { +int i_center; fp x_rel; -int m_min, m_max; printf("testing with molecule_size=%d\n", molecule_size); -printf(" out_of_range_tolerance_[min,max]=[%g,%g]\n", - (double) out_of_range_tolerance_min, - (double) out_of_range_tolerance_max); +printf(" boundary_off_centering_tolerance_[min,max]=[%g,%g]\n", + (double) boundary_off_centering_tolerance_min, + (double) boundary_off_centering_tolerance_max); +printf(" boundary_extrapolation_tolerance_[min,max]=[%g,%g]\n", + (double) boundary_extrapolation_tolerance_min, + (double) boundary_extrapolation_tolerance_max); printf(" x=%g\n", (double) x); { -const int i_center = LocalInterp_molecule_posn(grid_x0, grid_dx, - grid_i_min, grid_i_max, - molecule_size, - out_of_range_tolerance_min, - out_of_range_tolerance_max, - x, - &x_rel, - &m_min, &m_max); - -if ((i_center == INT_MIN) || (i_center == INT_MAX)) - then printf("i_center=%d\n", i_center); - else printf("i_center=%d x_rel=%g m_[min,max]=[%d,%d] i_[min,max]=[%d,%d]\n", - i_center, x_rel, m_min, m_max, i_center+m_min, i_center+m_max); +const int status + = LocalInterp_molecule_posn(grid_x0, grid_dx, + grid_i_min, grid_i_max, + molecule_size, + boundary_off_centering_tolerance_min, + boundary_off_centering_tolerance_max, + boundary_extrapolation_tolerance_min, + boundary_extrapolation_tolerance_max, + x, + &i_center, &x_rel); + +if (status < 0) + then printf("status=%d\n", status); + else printf("i_center=%d x_rel=%g\n", i_center, x_rel); } } @@ -319,41 +319,48 @@ int failure_count = 0; for (i = 0 ; i < N_TESTS ; ++i) { const struct args_results *p = & test_data[i]; - fp x_rel = 0.0; - int m_min = 0, m_max = 0; - int i_center = LocalInterp_molecule_posn(grid_x0, grid_dx, - grid_i_min, grid_i_max, - p->molecule_size, - p->out_of_range_tolerance_min, - p->out_of_range_tolerance_max, - p->x, - &x_rel, - &m_min, &m_max); - bool ok = ((i_center == INT_MIN) || (i_center == INT_MAX)) - ? (i_center == p->i_center) - : ( (i_center == p->i_center) - && fuzzy_EQ(x_rel, p->x_rel) - && (m_min == p->m_min) - && (m_max == p->m_max) ); - - int msglen = - printf("size=%d tol=[%g,%g] x=%g ==> ", - p->molecule_size, - (double) p->out_of_range_tolerance_min, - (double) p->out_of_range_tolerance_max, - (double) p->x); - printf("i_center=%d x_rel=%g m=[%d,%d]\n", - i_center, (double) x_rel, m_min, m_max); - - if (! ok) - then { + int i_center = 999; + fp x_rel = 999.999; + const int status = LocalInterp_molecule_posn + (grid_x0, grid_dx, + grid_i_min, grid_i_max, + p->molecule_size, + p->boundary_off_centering_tolerance_min, + p->boundary_off_centering_tolerance_max, + p->boundary_extrapolation_tolerance_min, + p->boundary_extrapolation_tolerance_max, + p->x, + &i_center, &x_rel); + bool ok = (status == 0) + ? ( (status == p->status) && (i_center == p->i_center) + && fuzzy_EQ(x_rel, p->x_rel) ) + : (status == p->status); + + printf("size=%d off_centering_tol=[%g,%g] extrapolation_tol=[%g,%g] x=%g", + p->molecule_size, + (double) p->boundary_off_centering_tolerance_min, + (double) p->boundary_off_centering_tolerance_max, + (double) p->boundary_extrapolation_tolerance_min, + (double) p->boundary_extrapolation_tolerance_max, + (double) p->x); + printf(": status=%d", status); + if (status == 0) + then printf(" i_center=%d x_rel=%g: ", + i_center, (double) x_rel); + + if (ok) + then printf(": ok\n"); + else { ++failure_count; - { - int error_msglen = printf("***** FAIL: "); - printf("%-*s", msglen-error_msglen, "expected"); - printf("i_center=%d x_rel=%g m_[min,max]=[%d,%d]\n", - p->i_center, (double) p->x_rel, p->m_min, p->m_max); - } + printf(": FAIL\n"); + if (p->status == 0) + then printf("*** expected status=%d i_center=%d x_rel=%g\n", + p->status, p->i_center, (double) p->x_rel); + else printf("*** expected status=%d\n", p->status); + if (status == 0) + then printf("*** got status=%d i_center=%d x_rel=%g\n", + status, i_center, (double) x_rel); + else printf("*** got status=%d\n", status); } } |