commit 52bd005f7c9c4fdf74fdd06493182d7ffa8108d0
parent 80f8d923cf9757a81ad990dd652d6fc04d402087
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Thu, 8 Sep 2016 12:17:16 +0200
Improve solver test
Add a postprocess and check mean and std error.
Diffstat:
2 files changed, 63 insertions(+), 0 deletions(-)
diff --git a/src/test_ssol_postprocess.h b/src/test_ssol_postprocess.h
@@ -0,0 +1,53 @@
+/* Copyright (C) CNRS 2016
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef TEST_SSOL_POSTPROCESS_H
+#define TEST_SSOL_POSTPROCESS_H
+
+#include <stdio.h>
+#include <math.h>
+
+static INLINE res_T
+pp_sum(FILE* f, const char* target, double* mean, double* std)
+{
+ double sum = 0, sum2 = 0, var;
+ size_t cpt = 0;
+ char expect_tok2[256];
+ ASSERT(f && target && mean && std);
+ snprintf(expect_tok2, 256, "'%s':", target);
+ rewind(f);
+ while (!feof(f)) {
+ char buf[256];
+ if (fgets(buf, 256, f)) {
+ char tok1[256], tok2[256];
+ double w;
+ if(3 != sscanf(buf, "%s %s %*f %*f %*f %lf", tok1, tok2, &w)) continue;
+ if (strcmp(tok1, "Receiver")) continue;
+ if (strcmp(tok2, expect_tok2)) continue;
+ sum += w;
+ sum2 += w * w;
+ cpt++;
+ }
+ }
+ if (cpt) {
+ *mean = sum / cpt;
+ var = (sum2 / cpt - *mean * *mean);
+ *std = var > 0 ? sqrt(var / cpt) : 0;
+ return RES_OK;
+ }
+ return RES_UNKNOWN_ERR;
+}
+
+#endif /* TEST_SSOL_POSTPROCESS_H */
diff --git a/src/test_ssol_solver1.c b/src/test_ssol_solver1.c
@@ -17,6 +17,7 @@
#include "test_ssol_utils.h"
#include "test_ssol_geometries.h"
#include "test_ssol_materials.h"
+#include "test_ssol_postprocess.h"
#include "ssol_solver_c.h"
@@ -54,6 +55,8 @@ main(int argc, char** argv)
double intensities[3] = { 1, 0.8, 1 };
double transform1[12]; /* 3x4 column major matrix */
double transform2[12]; /* 3x4 column major matrix */
+ FILE* tmp = NULL;
+ double m, std;
(void) argc, (void) argv;
@@ -128,6 +131,13 @@ main(int argc, char** argv)
CHECK(ssol_scene_attach_instance(scene, target), RES_OK);
CHECK(ssol_solve(scene, rng, 20, stdout), RES_OK);
+
+ tmp = tmpfile();
+ CHECK(!tmp, 0);
+ CHECK(ssol_solve(scene, rng, 1000, tmp), RES_OK);
+ CHECK(pp_sum(tmp, "cible", &m, &std), RES_OK);
+ CHECK(eq_eps(m, 1000 / sqrt(2), 1e-3), 1);
+ CHECK(eq_eps(std, 0, 1e-6), 1);
/* free data */