Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add message to assertion error in tests. #319

Merged
merged 2 commits into from
Apr 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions discretize/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,12 @@ class in older versions of `discretize`.
if test_type == "mean":
np.testing.assert_allclose(np.mean(orders), expected_order, rtol=rtol)
elif test_type == "mean_at_least":
assert np.mean(orders) > expected_order * (1 - rtol)
test = np.mean(orders) > expected_order * (1 - rtol)
if not test:
raise AssertionError(
f"\nOrder mean {np.mean(orders)} is not greater than the expected order "
f"{expected_order} within the tolerance {rtol}."
)
elif test_type == "min":
np.testing.assert_allclose(np.min(orders), expected_order, rtol=rtol)
elif test_type == "last":
Expand Down Expand Up @@ -680,11 +685,17 @@ def _plot_it(axes, passed):
# passTest = belowTol or correctOrder
try:
if order1.size == 0:
# This should happen if the original function was a linear function
# This should happen if all of the 1st order taylor approximation errors
# were below epsilon, common if the original function was linear.
# Thus it has no higher order derivatives.
assert order0.size >= 0
pass
else:
assert np.mean(order1) > tolerance * expectedOrder
test = np.mean(order1) > tolerance * expectedOrder
if not test:
raise AssertionError(
f"\n Order mean {np.mean(order1)} is not greater than"
f" {tolerance} of the expected order {expectedOrder}."
)
print("{0!s} PASS! {1!s}".format("=" * 25, "=" * 25))
print(np.random.choice(happiness) + "\n")
if plotIt:
Expand Down