From 66f3b8a846876b478f2e0bdda378b753896d404c Mon Sep 17 00:00:00 2001 From: markriegler Date: Fri, 7 Feb 2025 13:55:07 +0100 Subject: [PATCH] Add more suggestions from coderabbit --- tests/conftest.py | 9 ++++++--- tests/test_microtiles.py | 13 +++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 2d3c46e45..3bb99cd62 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -47,7 +47,7 @@ def heps(): """ Perturbation/step size for finite difference evaluation of derivative/sensitivity. - The value 1e-5 is arbitrary, but is a a compromise between: + The value 1e-5 is arbitrary, but is a compromise between: - Being small enough to ensure the finite difference calculation being accurate - Being large enough to avoid round-off error in floating-point arithmetic """ @@ -59,7 +59,8 @@ def n_test_points(): """ Number of random testing points (in parametric domain) - The number 10 is arbitrary and should ensure to have good test coverage + The number 10 is arbitrary and should ensure to have good test coverage. Increasing + this number could yield more thorough tests at the cost of longer runtime. """ return 10 @@ -68,7 +69,9 @@ def n_test_points(): def big_perturbation(): """Value for perturbation of parameters value - The number 0.1 is small enough to fit the range of most tile parameters""" + The number 0.1 is chosen arbitrarily. This value is for testing out of bounds + parameter values. It is designed to add to the maximum or subtract from the + minimum bound to delibarately make the values out of the bounds.""" return 0.1 diff --git a/tests/test_microtiles.py b/tests/test_microtiles.py index 126f58ecf..48ae1e508 100644 --- a/tests/test_microtiles.py +++ b/tests/test_microtiles.py @@ -6,6 +6,7 @@ import splinepy.microstructure as ms from splinepy.utils.data import cartesian_product as _cartesian_product +# Tolerance value for checking control points EPS = 1e-8 all_tile_classes = list(ms.tiles.everything().values()) @@ -31,14 +32,14 @@ def check_control_points(tile_patches): """Helper function. Check if all of tile's control points all lie within unit - square/cube""" + square/cube. The tolerance is defined by EPS""" # Go through all patches for tile_patch in tile_patches: cps = tile_patch.control_points - assert np.all((cps >= 0.0 - EPS) & (cps <= 1.0 + EPS)), ( + valid_cp_indices = (cps >= 0.0 - EPS) & (cps <= 1.0 + EPS) + assert np.all(valid_cp_indices), ( "Control points of tile must lie inside the unit square/cube. " - + "Found points outside bounds: " - f"{cps[~((cps >= 0.0 - EPS) & (cps <= 1.0 + EPS))]}" + + f"Found points outside bounds: {cps[~(valid_cp_indices)]}" ) @@ -121,8 +122,8 @@ def test_tile_class(tile_class): assert isinstance( getattr(tile_instance, required_variable), var_type ), ( - f"Variable {required_variable} needs to be of type {var_type} and not" - f"{required_variable}" + f"Variable {required_variable} must be of type {var_type}, but found type " + f"{type(getattr(tile_instance, required_variable))}" ) # Check default parameter value if there is one