## "Fossies" - the Fresh Open Source Software Archive

### Source code changes of the file "mpmath/tests/test_rootfinding.py" betweenmpmath-1.0.0.tar.gz and mpmath-1.1.0.tar.gz

About: mpmath is a Python library for arbitrary-precision floating-point arithmetic.

test_rootfinding.py  (mpmath-1.0.0):test_rootfinding.py  (mpmath-1.1.0)
import pytest
from mpmath import * from mpmath import *
from mpmath.calculus.optimization import Secant, Muller, Bisection, Illinois, \ from mpmath.calculus.optimization import Secant, Muller, Bisection, Illinois, \
Pegasus, Anderson, Ridder, ANewton, Newton, MNewton, MDNewton Pegasus, Anderson, Ridder, ANewton, Newton, MNewton, MDNewton
def test_findroot(): def test_findroot():
# old tests, assuming secant # old tests, assuming secant
mp.dps = 15 mp.dps = 15
assert findroot(lambda x: 4*x-3, mpf(5)).ae(0.75) assert findroot(lambda x: 4*x-3, mpf(5)).ae(0.75)
assert findroot(sin, mpf(3)).ae(pi) assert findroot(sin, mpf(3)).ae(pi)
assert findroot(sin, (mpf(3), mpf(3.14))).ae(pi) assert findroot(sin, (mpf(3), mpf(3.14))).ae(pi)
skipping to change at line 31 skipping to change at line 32
assert abs(f(x)) < eps assert abs(f(x)) < eps
# test types # test types
f = lambda x: (x - 2)**2 f = lambda x: (x - 2)**2
#assert isinstance(findroot(f, 1, force_type=mpf, tol=1e-10), mpf) #assert isinstance(findroot(f, 1, force_type=mpf, tol=1e-10), mpf)
#assert isinstance(findroot(f, 1., force_type=None, tol=1e-10), float) #assert isinstance(findroot(f, 1., force_type=None, tol=1e-10), float)
#assert isinstance(findroot(f, 1, force_type=complex, tol=1e-10), complex) #assert isinstance(findroot(f, 1, force_type=complex, tol=1e-10), complex)
assert isinstance(fp.findroot(f, 1, tol=1e-10), float) assert isinstance(fp.findroot(f, 1, tol=1e-10), float)
assert isinstance(fp.findroot(f, 1+0j, tol=1e-10), complex) assert isinstance(fp.findroot(f, 1+0j, tol=1e-10), complex)
# issue 401
with pytest.raises(ValueError):
with workprec(2):
findroot(lambda x: x**2 - 4456178*x + 60372201703370,
mpc(real='5.278e+13', imag='-5.278e+13'))
# issue 192
with pytest.raises(ValueError):
findroot(lambda x: -1, 0)
# issue 387
with pytest.raises(ValueError):
findroot(lambda p: (1 - p)**30 - 1, 0.9)
def test_bisection(): def test_bisection():
# issue 273 # issue 273
assert findroot(lambda x: x**2-1,(0,2),solver='bisect') == 1 assert findroot(lambda x: x**2-1,(0,2),solver='bisect') == 1
def test_mnewton(): def test_mnewton():
f = lambda x: polyval([1,3,3,1],x) f = lambda x: polyval([1,3,3,1],x)
x = findroot(f, -0.9, solver='mnewton') x = findroot(f, -0.9, solver='mnewton')
assert abs(f(x)) < eps assert abs(f(x)) < eps
def test_anewton(): def test_anewton():
End of changes. 2 change blocks.
0 lines changed or deleted 15 lines changed or added