commit fb230c8aa8888b0ad3fe89d1527cbfcfd7313103
parent 371f9140aefa1ea78b2924c7232ecde875cd2d79
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date: Wed, 19 Mar 2025 11:33:02 +0100
Replace hard coded numerical checks by eq_eps from rsys/math
Ensure consistent naming for testing functions
Diffstat:
4 files changed, 33 insertions(+), 37 deletions(-)
diff --git a/src/test_sphin_load_geometry.c b/src/test_sphin_load_geometry.c
@@ -1,5 +1,4 @@
/* Copyright (C) 2024-2025 Centre National de la Recherche Scientifique
-
* Copyright (C) 2024-2025 Clermont Auvergne INP
* Copyright (C) 2024-2025 INSA Lyon
* Copyright (C) 2024-2025 Institut Mines Télécom Albi-Carmaux
diff --git a/src/test_sphin_load_source.c b/src/test_sphin_load_source.c
@@ -25,7 +25,7 @@
#include "sphin.h"
#include "test_sphin_utils.h"
-#include <math.h>
+#include <rsys/math.h>
#include <rsys/mem_allocator.h>
#include <string.h>
@@ -101,7 +101,7 @@ test_source_api
CHK(sphin_source_surface_get_flux_density(NULL, &flux_density) == RES_BAD_ARG);
CHK(sphin_source_surface_get_flux_density(source, NULL) == RES_BAD_ARG);
CHK(sphin_source_surface_get_flux_density(source, &flux_density) == RES_OK);
- CHK(fabs(flux_density.flux_density - 200) < 1e-15);
+ CHK(eq_eps(flux_density.flux_density, 200, 1e-15));
CHK(flux_density.unit == SPHIN_PHOTON_UNIT_MOL);
CHK(sphin_source_ref_get(NULL) == RES_BAD_ARG);
CHK(sphin_source_ref_put(NULL) == RES_BAD_ARG);
@@ -117,19 +117,19 @@ test_source_api
CHK(dir_dist.collim.direction[1] == 0);
CHK(dir_dist.collim.direction[2] == 0);
CHK(sphin_source_surface_get_flux_density(source, &flux_density) == RES_OK);
- CHK(fabs(flux_density.flux_density - 1000) < 1e-15);
+ CHK(eq_eps(flux_density.flux_density, 1000, 1e-15));
CHK(flux_density.unit == SPHIN_PHOTON_UNIT_MOL);
CHK(sphin_config_get_surface(config, 2, &surface) == RES_OK);
CHK(sphin_surface_get_source(surface, &source) == RES_OK);
CHK(sphin_source_get_direction_distribution(source, &dir_dist) == RES_OK);
CHK(dir_dist.type == SPHIN_SOURCE_DIRECTION_COS_POW_N);
- CHK(fabs(dir_dist.cos_pow_n.collimation_degree - 1) < 1e-15);
+ CHK(eq_eps(dir_dist.cos_pow_n.collimation_degree, 1, 1e-15));
CHK(dir_dist.collim.direction[0] == SPHIN_SOURCE_DIRECTION_DISTRIBUTION_COLLIM_NULL.direction[0]);
CHK(dir_dist.collim.direction[1] == SPHIN_SOURCE_DIRECTION_DISTRIBUTION_COLLIM_NULL.direction[1]);
CHK(dir_dist.collim.direction[2] == SPHIN_SOURCE_DIRECTION_DISTRIBUTION_COLLIM_NULL.direction[2]);
CHK(sphin_source_surface_get_flux_density(source, &flux_density) == RES_OK);
- CHK(fabs(flux_density.flux_density - 200) < 1e-15);
+ CHK(eq_eps(flux_density.flux_density, 200, 1e-15));
CHK(flux_density.unit == SPHIN_PHOTON_UNIT_JOULE);
CHK(sphin_config_ref_put(config) == RES_OK);
diff --git a/src/test_sphin_load_surface.c b/src/test_sphin_load_surface.c
@@ -1,5 +1,4 @@
/* Copyright (C) 2024-2025 Centre National de la Recherche Scientifique
-
* Copyright (C) 2024-2025 Clermont Auvergne INP
* Copyright (C) 2024-2025 INSA Lyon
* Copyright (C) 2024-2025 Institut Mines Télécom Albi-Carmaux
@@ -26,7 +25,7 @@
#include "sphin.h"
#include "test_sphin_utils.h"
-#include <math.h>
+#include <rsys/math.h>
#include <rsys/mem_allocator.h>
#include <string.h>
@@ -88,7 +87,7 @@ write_stl_test_files
}
static void
-test_load_surface
+test_surface_api
(struct sphin* sphin)
{
struct sphin_config* config = NULL;
@@ -136,7 +135,7 @@ test_load_surface
CHK(sphin_brdf_lambertian_get_reflectivity(NULL, &reflectivity) == RES_BAD_ARG);
CHK(sphin_brdf_lambertian_get_reflectivity(brdf, NULL) == RES_BAD_ARG);
CHK(sphin_brdf_lambertian_get_reflectivity(brdf, &reflectivity) == RES_OK);
- CHK(fabs(reflectivity) < 1e-15);
+ CHK(eq_eps(reflectivity, 0, 1e-15));
/* Test surface 1 */
CHK(sphin_config_get_surface(config, 1, &surface) == RES_OK);
@@ -146,7 +145,7 @@ test_load_surface
CHK(sphin_brdf_specular_get_reflectivity(brdf, NULL) == RES_BAD_ARG);
CHK(sphin_brdf_specular_get_reflectivity(NULL, &reflectivity) == RES_BAD_ARG);
CHK(sphin_brdf_specular_get_reflectivity(brdf, &reflectivity) == RES_OK);
- CHK(fabs(reflectivity - 0.5) < 1e-15);
+ CHK(eq_eps(reflectivity, 0.5, 1e-15));
CHK(sphin_brdf_ref_get(brdf) == RES_OK);
CHK(sphin_brdf_ref_put(brdf) == RES_OK);
CHK(sphin_surface_ref_get(surface) == RES_OK);
@@ -159,7 +158,7 @@ test_load_surface
}
static void
-test_load_surface_bad_brdf_key
+test_surface_api_bad_brdf_key
(struct sphin* sphin)
{
struct sphin_config* config = NULL;
@@ -176,7 +175,7 @@ test_load_surface_bad_brdf_key
}
static void
-test_load_surface_bad_brdf_value
+test_surface_api_bad_brdf_value
(struct sphin* sphin)
{
struct sphin_config* config = NULL;
@@ -193,7 +192,7 @@ test_load_surface_bad_brdf_value
}
static void
-test_load_surface_bad_name
+test_surface_api_bad_name
(struct sphin* sphin)
{
struct sphin_config* config = NULL;
@@ -209,7 +208,7 @@ test_load_surface_bad_name
}
static void
-test_load_surface_bad_geometry
+test_surface_api_bad_geometry
(struct sphin* sphin)
{
struct sphin_config* config = NULL;
@@ -240,11 +239,11 @@ main(int argc, char** argv)
sphin_create(&args, &sphin);
write_stl_test_files();
- test_load_surface(sphin);
- test_load_surface_bad_brdf_key(sphin);
- test_load_surface_bad_brdf_value(sphin);
- test_load_surface_bad_name(sphin);
- test_load_surface_bad_geometry(sphin);
+ test_surface_api(sphin);
+ test_surface_api_bad_brdf_key(sphin);
+ test_surface_api_bad_brdf_value(sphin);
+ test_surface_api_bad_name(sphin);
+ test_surface_api_bad_geometry(sphin);
CHK(sphin_ref_put(sphin) == RES_OK);
diff --git a/src/test_sphin_load_volume.c b/src/test_sphin_load_volume.c
@@ -25,7 +25,7 @@
#include "sphin.h"
#include "test_sphin_utils.h"
-#include <math.h>
+#include <rsys/math.h>
#include <rsys/mem_allocator.h>
#include <string.h>
@@ -87,7 +87,7 @@ write_stl_test_files
}
static void
-test_load_volume
+test_volume_api
(struct sphin* sphin)
{
struct sphin_config* config = NULL;
@@ -100,7 +100,7 @@ test_load_volume
CHK(fp = fopen(path, "w+"));
fprintf(fp, "#Mot Clé Nom\n");
fprintf(fp, "volume: \"reaction volume\"\n");
- fprintf(fp, "\tka: 1 m^-1\n");
+ fprintf(fp, "\tka: 2.11 m^-1\n");
fprintf(fp, "\tsensor:\n");
fprintf(fp, "\t\tresponse_function: 1\n");
fprintf(fp, "\tgeometry: FRONT test_0.stl\n");
@@ -111,7 +111,7 @@ test_load_volume
fprintf(fp, "volume: \"my reaction volume\"\n");
fprintf(fp, "\tka: 1e-1 cm^-1\n");
fprintf(fp, "volume: \"my last volume\"\n");
- fprintf(fp, "\tka: 1 mm^-1\n");
+ fprintf(fp, "\tka: 1.935 mm^-1\n");
fclose(fp);
CHK(sphin_load(sphin, path, &config) == RES_OK);
@@ -131,7 +131,7 @@ test_load_volume
CHK(sphin_volume_get_ka(NULL, &ka) == RES_BAD_ARG);
CHK(sphin_volume_get_ka(volume, NULL) == RES_BAD_ARG);
CHK(sphin_volume_get_ka(volume, &ka) == RES_OK);
- CHK(fabs(ka-1) < 1e-15);
+ CHK(eq_eps(ka, 2.11, 1e-15));
CHK(sphin_volume_get_sensor(NULL, NULL) == RES_BAD_ARG);
CHK(sphin_volume_get_sensor(NULL, &sensor) == RES_BAD_ARG);
CHK(sphin_volume_get_sensor(volume, NULL) == RES_BAD_ARG);
@@ -140,32 +140,30 @@ test_load_volume
CHK(sphin_sensor_get_response_function(NULL, &response_function) == RES_BAD_ARG);
CHK(sphin_sensor_get_response_function(sensor, NULL) == RES_BAD_ARG);
CHK(sphin_sensor_get_response_function(sensor, &response_function) == RES_OK);
- CHK(fabs(response_function-1) < 1e-15);
+ CHK(eq_eps(response_function, 1, 1e-15));
CHK(sphin_volume_ref_get(volume) == RES_OK);
CHK(sphin_volume_ref_put(volume) == RES_OK);
/* Test volume 1 */
CHK(sphin_config_get_volume(config, 1, &volume) == RES_OK);
CHK(sphin_volume_get_ka(volume, &ka) == RES_OK);
- CHK(fabs(ka-10) < 1e-15);
+ CHK(eq_eps(ka, 10, 1e-15));
CHK(sphin_volume_get_sensor(volume, &sensor) == RES_BAD_ARG); /* Volume has no sensor */
- CHK(fabs(response_function-1) < 1e-15);
/* Test volume 2 */
CHK(sphin_config_get_volume(config, 2, &volume) == RES_OK);
CHK(sphin_volume_get_ka(volume, &ka) == RES_OK);
- CHK(fabs(ka-1000) < 1e-15);
+ CHK(eq_eps(ka, 1935, 1e-15));
CHK(sphin_config_get_volume(config, 1, &volume) == RES_OK);
CHK(sphin_volume_ref_get(volume) == RES_OK);
CHK(sphin_config_ref_put(config) == RES_OK);
CHK(volume != NULL);
CHK(sphin_volume_ref_put(volume) == RES_OK);
-
}
static void
-test_load_volume_bad_geometry
+test_volume_api_bad_geometry
(struct sphin* sphin)
{
struct sphin_config* config = NULL;
@@ -185,7 +183,7 @@ test_load_volume_bad_geometry
}
static void
-test_load_volume_bad_sensor
+test_volume_api_bad_sensor
(struct sphin* sphin)
{
struct sphin_config* config = NULL;
@@ -204,7 +202,7 @@ test_load_volume_bad_sensor
CHK(sphin_load(sphin, path, &config) == RES_BAD_ARG);
}
static void
-test_load_empty_file
+test_volume_api_empty_file
(struct sphin* sphin)
{
struct sphin_config* config = NULL;
@@ -233,10 +231,10 @@ main(int argc, char** argv)
sphin_create(&args, &sphin);
write_stl_test_files();
- test_load_empty_file(sphin);
- test_load_volume(sphin);
- test_load_volume_bad_geometry(sphin);
- test_load_volume_bad_sensor(sphin);
+ test_volume_api(sphin);
+ test_volume_api_empty_file(sphin);
+ test_volume_api_bad_geometry(sphin);
+ test_volume_api_bad_sensor(sphin);
CHK(sphin_ref_put(sphin) == RES_OK);