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

enrich the test_karatsuba failure message with explicit elements #37561

Merged
merged 3 commits into from
Mar 31, 2024
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
14 changes: 10 additions & 4 deletions src/sage/rings/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,9 @@

@random_testing
def test_karatsuba_multiplication(base_ring, maxdeg1, maxdeg2,
ref_mul=lambda f, g: f._mul_generic(g), base_ring_random_elt_args=[],
numtests=10, verbose=False):
ref_mul=lambda f, g: f._mul_generic(g),
base_ring_random_elt_args=[],
numtests=10, verbose=False):
"""
Test univariate Karatsuba multiplication against other multiplication algorithms.

Expand Down Expand Up @@ -469,16 +470,21 @@

"""
from sage.misc.prandom import randint
from sage.misc.sage_input import sage_input
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
threshold = randint(0, min(maxdeg1, maxdeg2))
R = PolynomialRing(base_ring, 'x')
if verbose:
print("test_karatsuba_multiplication: ring={}, threshold={}".format(R, threshold))
print(f"test_karatsuba_multiplication: ring={R}, threshold={threshold}")
for _ in range(numtests):
f = R.random_element(randint(0, maxdeg1), False, *base_ring_random_elt_args)
g = R.random_element(randint(0, maxdeg2), False, *base_ring_random_elt_args)
if verbose:
print(" ({})*({})".format(f, g))
if ref_mul(f, g) - f._mul_karatsuba(g, threshold) != 0:
raise ValueError("Multiplication failed")
msg = "Multiplication failed for elements defined by\n"
msg += f"{sage_input(f)}\n"
msg += "and\n"
msg += f"{sage_input(g)}"
raise ValueError(msg)

Check warning on line 489 in src/sage/rings/tests.py

View check run for this annotation

Codecov / codecov/patch

src/sage/rings/tests.py#L485-L489

Added lines #L485 - L489 were not covered by tests
return
Loading