From 767b2d74bfb76d84d112f513e500a2210171c269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Thu, 7 Mar 2024 10:57:50 +0100 Subject: [PATCH 1/2] enrich the test_karatsuba failure message with explicit elements --- src/sage/rings/tests.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/sage/rings/tests.py b/src/sage/rings/tests.py index 3eed7e1aa31..7d0d2f1f90b 100644 --- a/src/sage/rings/tests.py +++ b/src/sage/rings/tests.py @@ -416,8 +416,9 @@ def test_random_arith(level=MAX_LEVEL, trials=1): @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. @@ -469,16 +470,20 @@ def test_karatsuba_multiplication(base_ring, maxdeg1, maxdeg2, """ 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 i in range(numtests): f = R.random_element(randint(0, maxdeg1), *base_ring_random_elt_args) g = R.random_element(randint(0, maxdeg2), *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"f = {sage_input(f)}\n" + msg += f"g = {sage_input(g)}" + raise ValueError(msg) return From 2525402500b2432bccd8819058c28ed68cc80ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Thu, 7 Mar 2024 11:00:31 +0100 Subject: [PATCH 2/2] tweak message --- src/sage/rings/tests.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sage/rings/tests.py b/src/sage/rings/tests.py index 7d0d2f1f90b..ad57abb5d16 100644 --- a/src/sage/rings/tests.py +++ b/src/sage/rings/tests.py @@ -482,8 +482,9 @@ def test_karatsuba_multiplication(base_ring, maxdeg1, maxdeg2, if verbose: print(" ({})*({})".format(f, g)) if ref_mul(f, g) - f._mul_karatsuba(g, threshold) != 0: - msg = "Multiplication failed for elements defined by:\n" - msg += f"f = {sage_input(f)}\n" - msg += f"g = {sage_input(g)}" + 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) return