Skip to content

Commit 7ea1fb6

Browse files
Release Managervbraun
Release Manager
authored andcommitted
Trac #24425: Fix inherently failing random_expr doctest
The docs for `random_expr` read: {{{ This function will often raise an error because it tries to create an erroneous expression (such as a division by zero). }}} It has the following doctest: {{{ sage: from sage.symbolic.random_tests import * sage: set_random_seed(53) sage: random_expr(50, nvars=3, coeff_generator=CDF.random_element) # random (v1^(0.97134084277 + 0.195868299334*I)/csc(-pi + v1^2 + v3) + sgn(1/ ... }}} Despite having a random seed the test run changes with every new builtin function introduced in `sage/functions` because the global function list changes. That's why the test was marked random. The problem however is that the test can even raise an error, as the docs state above. The"`random`" keyword does not catch this, and it would make the test useless anyway. Tests are meant to test the functionality of the associated code so the test and perhaps `random_expr` should be rewritten such that it allows a test that does not change with a changed global function list. URL: https://trac.sagemath.org/24425 Reported by: rws Ticket author(s): Ralf Stephan Reviewer(s): Marc Mezzarobba
2 parents 70e6a02 + a17755c commit 7ea1fb6

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/sage/symbolic/random_tests.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ def _mk_full_functions():
4646
integrate, kronecker_delta, log, polylog, real_part, sec,
4747
sech, sgn, sin, sinh, tan, tanh, unit_step, zeta, zetaderiv]
4848
49-
Note that this doctest will fail whenever a Pynac function is added or
50-
removed. In that case, it is very likely that the doctests for
51-
random_expr will fail as well. That's OK; just fix the doctest
52-
to match the new output.
49+
Note that this doctest will produce different output whenever a
50+
symbolic function is added or removed.
5351
"""
5452
items = sorted(symbol_table['functions'].items())
5553
return [(1.0, f, f.number_of_arguments())
@@ -261,14 +259,16 @@ def random_expr(size, nvars=1, ncoeffs=None, var_frac=0.5,
261259
EXAMPLES::
262260
263261
sage: from sage.symbolic.random_tests import *
264-
sage: set_random_seed(53)
265-
sage: random_expr(50, nvars=3, coeff_generator=CDF.random_element) # random
266-
(v1^(0.97134084277 + 0.195868299334*I)/csc(-pi + v1^2 + v3) + sgn(1/
267-
((-v3 - 0.760455994772 - 0.554367254855*I)*erf(v3 + 0.982759757946 -
268-
0.0352136502348*I)) + binomial(arccoth(v1^pi), 0.760455994772 +
269-
0.554367254855*I) + arccosh(2*v2 - (v2 + 0.841911550437 -
270-
0.303757179824*I)/sinh_integral(pi) + arccoth(v3 + 0.530133230474 +
271-
0.532140303485*I))))/v2
262+
sage: some_functions = [arcsinh, arctan, arctan2, arctanh,
263+
....: arg, beta, binomial, ceil, conjugate, cos, cosh, cot, coth,
264+
....: elliptic_pi, erf, exp, factorial, floor, heaviside, imag_part,
265+
....: sech, sgn, sin, sinh, tan, tanh, unit_step, zeta, zetaderiv]
266+
sage: my_internal = [(0.6, full_binary, 2), (0.2, full_unary, 1),
267+
....: (0.2, [(1.0,f,f.number_of_arguments()) for f in some_functions])]
268+
sage: set_random_seed(1)
269+
sage: random_expr(50, nvars=3, internal=my_internal,
270+
....: coeff_generator=CDF.random_element)
271+
(v1^(0.9713408427702117 + 0.195868299334218*I)/cot(-pi + v1^2 + v3) + tan(arctan(v2 + arctan2(-0.35859061674557324 + 0.9407509502498164*I, v3) - 0.8419115504372718 + 0.30375717982404615*I) + arctan2((0.2275357305882964 - 0.8258002386106038*I)/factorial(v2), -v3 - 0.7604559947718565 - 0.5543672548552057*I) + ceil(1/arctan2(v1, v1))))/v2
272272
sage: random_expr(5, verbose=True) # random
273273
About to apply <built-in function inv> to [31]
274274
About to apply sgn to [v1]

0 commit comments

Comments
 (0)