aboutsummaryrefslogtreecommitdiff
path: root/src/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/test.c')
-rw-r--r--src/test.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/test.c b/src/test.c
index 2645982..20a66ec 100644
--- a/src/test.c
+++ b/src/test.c
@@ -823,7 +823,7 @@ err:
int test_std(char *err)
{
- /* Tests the mean() function. */
+ /* Tests the std() function. */
size_t i, j;
double x[100];
double sigma, expected, mu;
@@ -851,6 +851,34 @@ err:
return 1;
}
+int test_log_norm(char *err)
+{
+ /* Tests the log_norm() function. */
+ size_t i;
+ double x, mu, sigma, logp, expected;
+
+ init_genrand(0);
+
+ for (i = 0; i < 100; i++) {
+ x = randn();
+ mu = randn();
+ sigma = genrand_real2() + 1.0;
+
+ logp = log_norm(x,mu,sigma);
+ expected = log(norm(x,mu,sigma));
+
+ if (!isclose(logp, expected, 0, 1e-9)) {
+ sprintf(err, "log_norm(%.2g,%.2g,%.2g) returned %.5g, but expected %.5g", x, mu, sigma, logp, expected);
+ goto err;
+ }
+ }
+
+ return 0;
+
+err:
+ return 1;
+}
+
struct tests {
testFunction *test;
char *name;
@@ -877,6 +905,7 @@ struct tests {
{test_proton_get_dEdx, "test_proton_get_dEdx"},
{test_proton_get_range, "test_proton_get_range"},
{test_proton_get_energy, "test_proton_get_energy"},
+ {test_log_norm, "test_log_norm"},
};
int main(int argc, char **argv)