diff options
Diffstat (limited to 'test.c')
-rw-r--r-- | test.c | 64 |
1 files changed, 53 insertions, 11 deletions
@@ -2,6 +2,9 @@ #include <math.h> #include <stdio.h> #include "refractive_index.h" +#include "muon.h" + +typedef int testFunction(char *err); /* Table of some of the tabulated values of the refractive index of water as a * function of wavelength and temperature. In all cases, I just used the values @@ -106,6 +109,36 @@ int isclose(double a, double b, double rel_tol, double abs_tol) return fabs(a-b) <= fmax(rel_tol*fmax(fabs(a),fabs(b)),abs_tol); } +int test_muon_get_range(char *err) +{ + /* A very simple test to make sure we read in the PDG table correctly. */ + double value; + + value = get_range(1.0,1.0); + + if (!isclose(value, 1.863e-3, 1e-5, 0)) { + sprintf(err, "range = %.5f, but expected %.5f", value, 1.863e-3); + return 1; + } + + return 0; +} + +int test_muon_get_dEdx(char *err) +{ + /* A very simple test to make sure we read in the PDG table correctly. */ + double value; + + value = get_dEdx(1.0,1.0); + + if (!isclose(value, 6.097, 1e-5, 0)) { + sprintf(err, "dE/dx = %.5f, but expected %.5f", value, 6.097); + return 1; + } + + return 0; +} + int test_refractive_index(char *err) { /* Tests the get_index() function. */ @@ -158,23 +191,32 @@ int test_solid_angle(char *err) return 0; } +struct tests { + testFunction *test; + char *name; +} tests[] = { + {test_solid_angle, "test_solid_angle"}, + {test_refractive_index, "test_refractive_index"}, + {test_muon_get_dEdx, "test_muon_get_dEdx"}, + {test_muon_get_range, "test_muon_get_range"} +}; + int main(int argc, char **argv) { + int i; char err[256]; int retval = 0; + struct tests test; - if (!test_solid_angle(err)) { - printf("[\033[92mok\033[0m] test_solid_angle\n"); - } else { - printf("[\033[91mfail\033[0m] test_solid_angle: %s\n", err); - retval = 1; - } + for (i = 0; i < sizeof(tests)/sizeof(struct tests); i++) { + test = tests[i]; - if (!test_refractive_index(err)) { - printf("[\033[92mok\033[0m] test_refractive_index\n"); - } else { - printf("[\033[91mfail\033[0m] test_refractive_index: %s\n", err); - retval = 1; + if (!test.test(err)) { + printf("[\033[92mok\033[0m] %s\n", test.name); + } else { + printf("[\033[91mfail\033[0m] %s: %s\n", test.name, err); + retval = 1; + } } return retval; |