aboutsummaryrefslogtreecommitdiff
path: root/src/GeneralizedPolynomial-Uniform/test_molecule_posn.c
diff options
context:
space:
mode:
authorjthorn <jthorn@df1f8a13-aa1d-4dd4-9681-27ded5b42416>2002-02-27 14:28:36 +0000
committerjthorn <jthorn@df1f8a13-aa1d-4dd4-9681-27ded5b42416>2002-02-27 14:28:36 +0000
commit717d39a68230908f36b7098e66d0dd76dd067148 (patch)
tree397cda867657459ef518b65cd87def3517958253 /src/GeneralizedPolynomial-Uniform/test_molecule_posn.c
parentac713b27a07fa17689464ac2e9e7275169f116ea (diff)
initial checkin of new LocalInterp thorn
git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/LocalInterp/trunk@2 df1f8a13-aa1d-4dd4-9681-27ded5b42416
Diffstat (limited to 'src/GeneralizedPolynomial-Uniform/test_molecule_posn.c')
-rw-r--r--src/GeneralizedPolynomial-Uniform/test_molecule_posn.c302
1 files changed, 302 insertions, 0 deletions
diff --git a/src/GeneralizedPolynomial-Uniform/test_molecule_posn.c b/src/GeneralizedPolynomial-Uniform/test_molecule_posn.c
new file mode 100644
index 0000000..fd0b5bc
--- /dev/null
+++ b/src/GeneralizedPolynomial-Uniform/test_molecule_posn.c
@@ -0,0 +1,302 @@
+/* test_molecule_posn -- test driver for LocalInterp_molecule_posn() */
+
+/*
+ * This program is a test driver for LocalInterp_molecule_posn() .
+ *
+ * Usage:
+ * test_molecule_posn # run a preset set of tests
+ * test_molecule_posn molecule_size x # do a single test as specified
+ */
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#ifndef LOCALINTERP_STANDALONE_BUILD
+ #include "cctk.h"
+#endif
+
+#include "InterpLocalUniform.h"
+
+#define fuzzy_EQ(x,y) (fabs(x-y) <= 1.0e-10)
+
+/* prototypes */
+void run_interactive_test(fp out_of_range_tolerance, int molecule_size, fp x);
+int run_batch_tests(void);
+
+/* hard-wired arguments for LocalInterp_molecule_posn() */
+const fp grid_x0 = 3.1;
+const fp grid_dx = 0.1;
+const int grid_i_min = 42; /* x_min = 7.3 */
+const int grid_i_max = 105; /* x_max = 13.6 */
+
+/******************************************************************************/
+
+/*
+ * test data for batch tests
+ */
+
+/* arguments/results structure for LocalInterp_molecule_posn() calls */
+struct args_results
+ {
+ /* args */
+ fp out_of_range_tolerance;
+ int molecule_size;
+ fp x;
+ /* results */
+ int i_center;
+ fp x_rel;
+ int m_min, m_max;
+ };
+
+/* test data */
+static const struct args_results test_data[] =
+ {
+ /* molecule size 2 */
+ { 1.0, 2, 7.19, INT_MIN, -1.1, 0,+1 },
+ { 1.0, 2, 7.21, 42, -0.9, 0,+1 },
+ { 1.0, 2, 7.24, 42, -0.6, 0,+1 },
+ { 1.0, 2, 7.26, 42, -0.4, 0,+1 },
+ { 1.0, 2, 7.29, 42, -0.1, 0,+1 },
+ {-1.0, 2, 7.29, INT_MIN, -0.1, 0,+1 },
+ { 1.0e-12, 2, 7.3, 42, 0.0, 0,+1 }, /* x == grid_x_min */
+ { 1.0e-12, 2, 7.31, 42, +0.1, 0,+1 },
+ {-1.0 , 2, 7.31, 42, +0.1, 0,+1 },
+ { 1.0e-12, 2, 7.35, 42, +0.5, 0,+1 },
+ { 1.0e-12, 2, 7.39, 42, +0.9, 0,+1 },
+ { 1.0e-12, 2, 7.41, 43, 0.1, 0,+1 },
+ { 1.0e-12, 2, 9.81, 67, +0.1, 0,+1 },
+ { 1.0e-12, 2, 9.85, 67, +0.5, 0,+1 },
+ { 1.0e-12, 2, 9.89, 67, +0.9, 0,+1 },
+ { 1.0e-12, 2, 13.45, 103, +0.5, 0,+1 },
+ { 1.0e-12, 2, 13.51, 104, +0.1, 0,+1 },
+ { 1.0e-12, 2, 13.55, 104, +0.5, 0,+1 },
+ { 1.0e-12, 2, 13.59, 104, +0.9, 0,+1 },
+ {-1.0, 2, 13.59, 104, +0.9, 0,+1 },
+ { 1.0e-12, 2, 13.6, 104, +1.0, 0,+1 }, /* x == grid_x_max */
+ { 1.0, 2, 13.61, 104, +1.1, 0,+1 },
+ {-1.0, 2, 13.61, INT_MAX, +1.1, 0,+1 },
+ { 1.0, 2, 13.65, 104, +1.5, 0,+1 },
+ { 1.0, 2, 13.69, 104, +1.9, 0,+1 },
+ { 1.0, 2, 13.71, INT_MAX, +2.1, 0,+1 },
+ /* molecule size 3 */
+ { 1.0, 3, 7.19, INT_MIN, -2.1, -1,+1 },
+ { 1.0, 3, 7.21, 43, -1.9, -1,+1 },
+ { 1.0, 3, 7.24, 43, -1.6, -1,+1 },
+ { 1.0, 3, 7.26, 43, -1.4, -1,+1 },
+ { 1.0, 3, 7.29, 43, -1.1, -1,+1 },
+ {-1.0, 3, 7.29, INT_MIN, -1.1, -1,+1 },
+ { 1.0e-12, 3, 7.3, 43, -1.0, -1,+1 }, /* x == grid_x_min */
+ { 1.0e-12, 3, 7.31, 43, -0.9, -1,+1 },
+ { 1.0e-12, 3, 7.34, 43, -0.6, -1,+1 },
+ {-1.0, 3, 7.34, INT_MIN, -0.6, -1,+1 },
+ { 1.0e-12, 3, 7.36, 43, -0.4, -1,+1 },
+ {-1.0, 3, 7.36, 43, -0.4, -1,+1 },
+ { 1.0e-12, 3, 7.39, 43, -0.1, -1,+1 },
+ { 1.0e-12, 3, 7.4, 43, 0.0, -1,+1 },
+ { 1.0e-12, 3, 7.44, 43, +0.4, -1,+1 },
+ { 1.0e-12, 3, 7.46, 44, -0.4, -1,+1 },
+ { 1.0e-12, 3, 9.8, 67, 0.0, -1,+1 },
+ { 1.0e-12, 3, 9.81, 67, +0.1, -1,+1 },
+ { 1.0e-12, 3, 9.84, 67, +0.4, -1,+1 },
+ { 1.0e-12, 3, 9.86, 68, -0.4, -1,+1 },
+ { 1.0e-12, 3, 9.89, 68, -0.1, -1,+1 },
+ { 1.0e-12, 3, 9.9, 68, 0.0, -1,+1 },
+ { 1.0e-12, 3, 13.44, 103, +0.4, -1,+1 },
+ { 1.0e-12, 3, 13.46, 104, -0.4, -1,+1 },
+ { 1.0e-12, 3, 13.5, 104, 0.0, -1,+1 },
+ { 1.0e-12, 3, 13.51, 104, +0.1, -1,+1 },
+ { 1.0e-12, 3, 13.54, 104, +0.4, -1,+1 },
+ {-1.0, 3, 13.54, 104, +0.4, -1,+1 },
+ { 1.0e-12, 3, 13.56, 104, +0.6, -1,+1 },
+ {-1.0, 3, 13.56, INT_MAX, +0.6, -1,+1 },
+ { 1.0e-12, 3, 13.59, 104, +0.9, -1,+1 },
+ { 1.0e-12, 3, 13.6, 104, +1.0, -1,+1 }, /* x == grid_x_max */
+ { 1.0, 3, 13.61, 104, +1.1, -1,+1 },
+ { 1.0, 3, 13.65, 104, +1.5, -1,+1 },
+ { 1.0, 3, 13.69, 104, +1.9, -1,+1 },
+ { 1.0, 3, 13.71, INT_MAX, +2.1, -1,+1 },
+ /* molecule size 4 */
+ { 0.2, 4, 7.27, INT_MIN, -1.3, -1,+2 },
+ { 0.2, 4, 7.29, 43, -1.1, -1,+2 },
+ { 1.0e-12, 4, 7.3, 43, -1.0, -1,+2 }, /* x == grid_x_min */
+ { 1.0e-12, 4, 7.33, 43, -0.7, -1,+2 },
+ { 1.0e-12, 4, 7.39, 43, -0.1, -1,+2 },
+ {-1.0, 4, 7.39, INT_MIN, -0.1, -1,+2 },
+ { 1.0e-12, 4, 7.4, 43, 0.0, -1,+2 },
+ {-1.0, 4, 7.41, 43, +0.1, -1,+2 },
+ { 1.0e-12, 4, 7.42, 43, +0.2, -1,+2 },
+ { 1.0e-12, 4, 7.48, 43, +0.8, -1,+2 },
+ { 1.0e-12, 4, 7.51, 44, +0.1, -1,+2 },
+ { 1.0e-12, 4, 9.81, 67, +0.1, -1,+2 },
+ { 1.0e-12, 4, 9.85, 67, +0.5, -1,+2 },
+ { 1.0e-12, 4, 9.89, 67, +0.9, -1,+2 },
+ { 1.0e-12, 4, 13.39, 102, +0.9, -1,+2 },
+ { 1.0e-12, 4, 13.41, 103, +0.1, -1,+2 },
+ { 1.0e-12, 4, 13.48, 103, +0.8, -1,+2 },
+ {-1.0, 4, 13.48, 103, +0.8, -1,+2 },
+ { 1.0e-12, 4, 13.5, 103, +1.0, -1,+2 },
+ { 1.0e-12, 4, 13.51, 103, +1.1, -1,+2 },
+ {-1.0, 4, 13.51, INT_MAX, +1.1, -1,+2 },
+ { 1.0e-12, 4, 13.55, 103, +1.5, -1,+2 },
+ { 1.0e-12, 4, 13.59, 103, +1.9, -1,+2 },
+ { 1.0e-12, 4, 13.6, 103, +2.0, -1,+2 }, /* x == grid_x_max */
+ { 2.0, 4, 13.79, 103, +3.9, -1,+2 },
+ { 2.0, 4, 13.81, INT_MAX, +4.1, -1,+2 },
+ /* molecule size 5 */
+ { 3.0, 5, 6.99, INT_MIN, -5.1, -2,+2 },
+ { 3.0, 5, 7.01, 44, -4.9, -2,+2 },
+ { 1.0e-12, 5, 7.3, 44, -2.0, -2,+2 }, /* x == grid_x_min */
+ { 1.0e-12, 5, 7.4, 44, -1.0, -2,+2 },
+ { 1.0e-12, 5, 7.44, 44, -0.6, -2,+2 },
+ {-1.0, 5, 7.44, INT_MIN, -0.6, -2,+2 },
+ { 1.0e-12, 5, 7.46, 44, -0.4, -2,+2 },
+ {-1.0, 5, 7.46, 44, -0.4, -2,+2 },
+ { 1.0e-12, 5, 7.49, 44, -0.1, -2,+2 },
+ { 1.0e-12, 5, 7.5, 44, 0.0, -2,+2 },
+ { 1.0e-12, 5, 7.54, 44, +0.4, -2,+2 },
+ { 1.0e-12, 5, 7.56, 45, -0.4, -2,+2 },
+ { 1.0e-12, 5, 7.6, 45, 0.0, -2,+2 },
+ { 1.0e-12, 5, 7.64, 45, +0.4, -2,+2 },
+ { 1.0e-12, 5, 9.8, 67, 0.0, -2,+2 },
+ { 1.0e-12, 5, 9.81, 67, +0.1, -2,+2 },
+ { 1.0e-12, 5, 9.84, 67, +0.4, -2,+2 },
+ { 1.0e-12, 5, 9.86, 68, -0.4, -2,+2 },
+ { 1.0e-12, 5, 9.89, 68, -0.1, -2,+2 },
+ { 1.0e-12, 5, 9.9, 68, 0.0, -2,+2 },
+ { 1.0e-12, 5, 13.34, 102, +0.4, -2,+2 },
+ { 1.0e-12, 5, 13.36, 103, -0.4, -2,+2 },
+ { 1.0e-12, 5, 13.39, 103, -0.1, -2,+2 },
+ { 1.0e-12, 5, 13.41, 103, +0.1, -2,+2 },
+ { 1.0e-12, 5, 13.44, 103, +0.4, -2,+2 },
+ {-1.0, 5, 13.44, 103, +0.4, -2,+2 },
+ { 1.0e-12, 5, 13.46, 103, +0.6, -2,+2 },
+ {-1.0, 5, 13.46, INT_MAX, +0.6, -2,+2 },
+ { 1.0e-12, 5, 13.48, 103, +0.8, -2,+2 },
+ { 1.0e-12, 5, 13.5, 103, +1.0, -2,+2 },
+ { 1.0e-12, 5, 13.51, 103, +1.1, -2,+2 },
+ { 1.0e-12, 5, 13.54, 103, +1.4, -2,+2 },
+ {-1.0, 5, 13.54, INT_MAX, +1.4, -2,+2 },
+ { 1.0e-12, 5, 13.56, 103, +1.6, -2,+2 },
+ {-1.0, 5, 13.56, INT_MAX, +1.6, -2,+2 },
+ { 1.0e-12, 5, 13.59, 103, +1.9, -2,+2 },
+ { 1.0e-12, 5, 13.6, 103, +2.0, -2,+2 }, /* x == grid_x_max */
+ { 1.5, 5, 13.74, 103, +3.4, -2,+2 },
+ { 1.5, 5, 13.76, INT_MAX, +3.6, -2,+2 },
+ };
+#define N_TESTS ((int) (sizeof(test_data)/sizeof(test_data[0])))
+
+
+/******************************************************************************/
+
+int main(int argc, const char *const argv[])
+{
+bool N_fail;
+fp out_of_range_tolerance;
+int molecule_size;
+fp x;
+
+switch (argc)
+ {
+case 1:
+ /* run batch tests */
+ N_fail = run_batch_tests();
+ if (N_fail == 0)
+ then {
+ printf("*** all tests successful ***\n");
+ return 0;
+ }
+ else {
+ printf("*** %d test(s) failed ***\n", N_fail);
+ return 1;
+ }
+
+case 4:
+ if ( (sscanf(argv[1], "%lf", &out_of_range_tolerance) == 1)
+ && (sscanf(argv[2], "%d", &molecule_size) == 1)
+ && (sscanf(argv[3], "%lf", &x) == 1) )
+ then {
+ run_interactive_test(out_of_range_tolerance, molecule_size, x);
+ return 0;
+ }
+ /* fall through */
+default:
+ fprintf(stderr,
+ "usage:\n"
+ "# run a single test as specified:\n"
+ " %s out_of_range_tolerance molecule_size x\n"
+ "# run a preset set of tests:\n"
+ " %s\n"
+ ,
+ argv[0], argv[0]);
+ return 1;
+ }
+}
+
+/******************************************************************************/
+
+/* run a single test as specified */
+void run_interactive_test(fp out_of_range_tolerance, int molecule_size, fp x)
+{
+fp x_rel;
+int m_min, m_max;
+
+int i_center = LocalInterp_molecule_posn(grid_x0, grid_dx,
+ grid_i_min, grid_i_max,
+ out_of_range_tolerance,
+ molecule_size,
+ 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);
+}
+
+/******************************************************************************/
+
+/* run a preset set of tests, return number of failures */
+int run_batch_tests(void)
+{
+int i;
+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->out_of_range_tolerance,
+ p->molecule_size,
+ 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("tol=%g size=%d x=%g ==> ",
+ p->out_of_range_tolerance, p->molecule_size, p->x);
+ printf("i_center=%d x_rel=%g m_[min,max]=[%d,%d]\n",
+ i_center, x_rel, m_min, m_max);
+ if (! ok)
+ then {
+ ++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, p->x_rel, p->m_min, p->m_max);
+ }
+ }
+ }
+
+return failure_count;
+}