Make numerical and probability doctests ready for random seeds
Closed this issue · 15 comments
This ticket makes
sage -t --long --random-seed=n src/sage/numerical/
sage -t --long --random-seed=n src/sage/probabilty/
pass for different values n than just 0.
Depends on #29962
Component: doctest framework
Author: Jonathan Kliem
Branch/Commit: b6bef4b
Reviewer: Markus Wageringel
Issue created by migration from https://trac.sagemath.org/ticket/29975
sage -t --long --random-seed=151058820726654196682836430928254760259 src/sage/numerical/optimize.py # 2 doctests failed
sage -t --long --random-seed=151058820726654196682836430928254760259 src/sage/probability/probability_distribution.pyx # 18 doctests failed
Branch: public/29975
Author: Jonathan Kliem
Although this is unlikely to fail, the test should agree with the documentation, so please apply this change for the uniform distribution:
Uniform distribution on the interval ``[a, b]``::
sage: a = 0
sage: b = 2
sage: T = RealDistribution('uniform', [a, b])
- sage: a <= T.get_random_element() < b
+ sage: a <= T.get_random_element() <= b
TrueFor the Pareto distribution, you could also add a test that s >= b. Similarly, the Rayleigh, Lognormal, F, Chisquared and Weibull distributions are ≥ 0, and the Beta distribution lives on [0,1].
Finally, I think this test should document the expected outcome, for clarity:
sage: [1.0*x/nr_samples for x in counts] # abs tol 1e-1
- [0.304200000000000, 0.397300000000000, 0.298500000000000]
+ [0.3, 0.4, 0.3]I hope it is sufficiently unlikely that this test fails, but it is not impossible.
Reviewer: Markus Wageringel
Branch pushed to git repo; I updated commit sha1. New commits:
c79005a | more precices doctests |
Thanks for improving the doctests.
Replying to @mwageringel:
Finally, I think this test should document the expected outcome, for clarity:
sage: [1.0*x/nr_samples for x in counts] # abs tol 1e-1 - [0.304200000000000, 0.397300000000000, 0.298500000000000] + [0.3, 0.4, 0.3]I hope it is sufficiently unlikely that this test fails, but it is not impossible.
I even modified it down to 3e-2. I tested it and the maximal difference is 0.0192 in 10 000 runs. So I guess it is much less likely than 1 in 10 000 that this test will fail.
Thanks for the updates. The change to multigraphics seems unintentional – I have removed it from your commit. I have also fixed another doctest:
sage -t --long --warn-long 55.4 --random-seed=2001 src/sage/numerical/optimize.py
**********************************************************************
File "src/sage/numerical/optimize.py", line 264, in sage.numerical.optimize.find_local_minimum
Failed example:
plot(f, (x,-2.5, 2)).ymin()
Expected:
-2.1827...
Got:
-2.182677572710766
You can set this to positive if you agree with my changes.
Thank you. Yes, agreed.
Changed branch from public/29975 to b6bef4b