Skip to content

Commit 644ba54

Browse files
author
Release Manager
committed
gh-37561: enrich the test_karatsuba failure message with explicit elements To help debug the random failure in `test_karatsuba_multiplication`, let us have a more precise error message in case of failure there. cf #35715 ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #37561 Reported by: Frédéric Chapoton Reviewer(s): Martin Rubey
2 parents e087e70 + 9f15505 commit 644ba54

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/sage/rings/tests.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,9 @@ def test_random_arith(level=MAX_LEVEL, trials=1):
416416

417417
@random_testing
418418
def test_karatsuba_multiplication(base_ring, maxdeg1, maxdeg2,
419-
ref_mul=lambda f, g: f._mul_generic(g), base_ring_random_elt_args=[],
420-
numtests=10, verbose=False):
419+
ref_mul=lambda f, g: f._mul_generic(g),
420+
base_ring_random_elt_args=[],
421+
numtests=10, verbose=False):
421422
"""
422423
Test univariate Karatsuba multiplication against other multiplication algorithms.
423424
@@ -469,16 +470,21 @@ def test_karatsuba_multiplication(base_ring, maxdeg1, maxdeg2,
469470
470471
"""
471472
from sage.misc.prandom import randint
473+
from sage.misc.sage_input import sage_input
472474
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
473475
threshold = randint(0, min(maxdeg1, maxdeg2))
474476
R = PolynomialRing(base_ring, 'x')
475477
if verbose:
476-
print("test_karatsuba_multiplication: ring={}, threshold={}".format(R, threshold))
478+
print(f"test_karatsuba_multiplication: ring={R}, threshold={threshold}")
477479
for _ in range(numtests):
478480
f = R.random_element(randint(0, maxdeg1), False, *base_ring_random_elt_args)
479481
g = R.random_element(randint(0, maxdeg2), False, *base_ring_random_elt_args)
480482
if verbose:
481483
print(" ({})*({})".format(f, g))
482484
if ref_mul(f, g) - f._mul_karatsuba(g, threshold) != 0:
483-
raise ValueError("Multiplication failed")
485+
msg = "Multiplication failed for elements defined by\n"
486+
msg += f"{sage_input(f)}\n"
487+
msg += "and\n"
488+
msg += f"{sage_input(g)}"
489+
raise ValueError(msg)
484490
return

0 commit comments

Comments
 (0)