style: reformat assertion blocks in test files

This commit is contained in:
2026-09-29 13:06:22 +03:00
parent be3e288e0d
commit 687e05cbe2
2 changed files with 20 additions and 22 deletions
+16 -19
View File
@@ -82,9 +82,9 @@ def _test_positive_values(component, W, component_name="Component"):
f"W range: [{W_arr.min():.3f}, {W_arr.max():.3f}], "
f"result range: [{np.nanmin(result):.6f}, {np.nanmax(result):.6f}]"
)
assert not np.any(
np.isinf(result)
), f"{component_name}: Inf values found in output."
assert not np.any(np.isinf(result)), (
f"{component_name}: Inf values found in output."
)
assert np.all(result > 0), (
f"{component_name}: non-positive values found. "
f"Min = {np.min(result):.10f} at W = {W_arr[np.argmin(result)][0]:.4f}"
@@ -108,21 +108,20 @@ def _test_non_negative_values(
W_arr = np.asarray(W, dtype=float)
result = component(W_arr)
assert not np.any(
np.isnan(result)
), f"{component_name}: NaN values found in output."
assert not np.any(
np.isinf(result)
), f"{component_name}: Inf values found in output."
assert not np.any(np.isnan(result)), (
f"{component_name}: NaN values found in output."
)
assert not np.any(np.isinf(result)), (
f"{component_name}: Inf values found in output."
)
if allow_zero:
assert np.all(result >= 0), (
f"{component_name}: negative values found. " f"Min = {np.min(result):.10f}"
f"{component_name}: negative values found. Min = {np.min(result):.10f}"
)
else:
assert np.all(result > 0), (
f"{component_name}: non-positive values found. "
f"Min = {np.min(result):.10f}"
f"{component_name}: non-positive values found. Min = {np.min(result):.10f}"
)
@@ -137,12 +136,11 @@ def _test_output_shape_preserved(component, W, component_name="Component"):
W_arr = np.asarray(W, dtype=float)
result = component(W_arr)
assert isinstance(
result, np.ndarray
), f"{component_name}: output is {type(result)}, expected np.ndarray"
assert isinstance(result, np.ndarray), (
f"{component_name}: output is {type(result)}, expected np.ndarray"
)
assert result.shape == W_arr.shape, (
f"{component_name}: shape mismatch. "
f"Input {W_arr.shape} → Output {result.shape}"
f"{component_name}: shape mismatch. Input {W_arr.shape} → Output {result.shape}"
)
@@ -217,8 +215,7 @@ def _test_output_is_ndarray(component, W, component_name="Component"):
result = component(W_arr)
assert isinstance(result, np.ndarray), (
f"{component_name}: output type is {type(result).__name__}, "
f"expected np.ndarray"
f"{component_name}: output type is {type(result).__name__}, expected np.ndarray"
)