Skip to content

Commit

Permalink
Add more suggestions from coderabbit
Browse files Browse the repository at this point in the history
  • Loading branch information
markriegler committed Feb 7, 2025
1 parent 087d8d1 commit 66f3b8a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
9 changes: 6 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -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

Expand All @@ -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


Expand Down
13 changes: 7 additions & 6 deletions tests/test_microtiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)]}"
)


Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 66f3b8a

Please sign in to comment.