aboutsummaryrefslogtreecommitdiff
path: root/src/jtutil/test_modulo.cc
diff options
context:
space:
mode:
authorjthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5>2001-08-09 14:48:11 +0000
committerjthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5>2001-08-09 14:48:11 +0000
commit1be7596b795dd5a5abb75f914fee9b2ff1228393 (patch)
tree8b3b1eec928732c4d1efbc5aba2fad843a216b9f /src/jtutil/test_modulo.cc
parent1d9365e4d61b2211bf4f4253de6977aa1a41983e (diff)
add test driver for modulo_reduce()
git-svn-id: http://svn.einsteintoolkit.org/cactus/EinsteinAnalysis/AHFinderDirect/trunk@255 f88db872-0e4f-0410-b76b-b9085cfa78c5
Diffstat (limited to 'src/jtutil/test_modulo.cc')
-rw-r--r--src/jtutil/test_modulo.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/jtutil/test_modulo.cc b/src/jtutil/test_modulo.cc
new file mode 100644
index 0000000..f964532
--- /dev/null
+++ b/src/jtutil/test_modulo.cc
@@ -0,0 +1,42 @@
+// test_modulo -- quick-n-dirty test of modulo_reduce()
+// $Id$
+
+#include <stdio.h>
+#include <assert.h>
+#include "jt/stdc.h"
+#include "jt/util.hh"
+using jtutil::error_exit;
+
+// prototypes
+void tryit(double x, double xmod, double xmin, double xmax, double correct);
+
+int main()
+{
+// x xmod xmin xmax correct
+tryit( 0.5, 1.0, 0.0, 1.0, 0.5);
+tryit( 0.0, 1.0, 0.0, 1.0, 0.0);
+tryit( 1.0, 1.0, 0.0, 1.0, 1.0);
+tryit( 2.0, 1.0, 0.0, 1.0, 1.0);
+tryit( 1.5, 1.0, 0.0, 1.0, 0.5);
+tryit( -0.6, 1.0, 0.0, 1.0, 0.4);
+tryit( -3.6, 1.0, 0.0, 1.0, 0.4);
+
+tryit(-145.0, 360.0, 180.0, 270.0, 215.0);
+
+printf("all ok!\n");
+}
+
+void tryit(double x, double xmod, double xmin, double xmax, double correct)
+{
+printf("trying %g mod %g [%g,%g] ==> ",
+ x, xmod, xmin, xmax);
+
+double got = jtutil::modulo_reduce(x, xmod, xmin, xmax);
+
+if (fuzzy<double>::EQ(got, correct))
+ then printf("ok\n");
+ else {
+ error_exit(ERROR_EXIT,
+ "no: got %g, correct %g\n", got, correct); /*NOTREACHED*/
+ }
+}