Ejemplo n.º 1
0
def test_success():
    f.calls = 0

    result = rootfinding.bracket_root(f, (0, -0.1))

    check_result(result, f, f_calls=f.calls, has_bracket=True, has_root=False)
    assert result.iterations >= 1
    rootfinding.bisect(f, result.bracket, f_bracket=result.f_bracket)
Ejemplo n.º 2
0
def test_instant2():
    bracket = (1, -1.00001)
    f_bracket = (f(bracket[0]), None)
    f.calls = 0

    result = rootfinding.bisect(f, bracket, f_bracket=f_bracket, maxiter=0)

    assert f.calls == 1
    check_result(result, f, f_calls=f.calls, has_bracket=True, has_root=True)
    assert result.root == 1
Ejemplo n.º 3
0
def test_growth_factor2():
    growth_factor = 3.14
    interval = (0, -0.1)
    f.calls = 0

    result = rootfinding.bracket_root(f, interval, growth_factor=growth_factor)

    check_result(result, f, f_calls=f.calls, has_bracket=True, has_root=False)

    assert result.bracket[1] - result.bracket[0] == pytest.approx(
        (interval[1] - interval[0]) * growth_factor**result.iterations)
Ejemplo n.º 4
0
def test_instantbracket():
    interval = (0, 2)
    f_interval = (None, f(interval[1]))
    f.calls = 0

    result = rootfinding.bracket_root(f,
                                      interval,
                                      f_interval=f_interval,
                                      maxiter=0)

    assert f.calls == 1
    check_result(result, f, f_calls=f.calls, has_bracket=True, has_root=False)
    rootfinding.bisect(f, result.bracket, f_bracket=result.f_bracket)
Ejemplo n.º 5
0
def test_success():
    ftol = 4 * sys.float_info.epsilon
    f.calls = 0

    result = rootfinding.bisect(f, (0.1, -1.5), ftol=ftol)

    check_result(result,
                 f,
                 ftol=ftol,
                 f_calls=f.calls,
                 has_bracket=True,
                 has_root=True)
    assert result.root == pytest.approx(-1)
Ejemplo n.º 6
0
def test_instantroot2():
    interval = (-1, 0)
    f_interval = (f(interval[0]), None)
    ftol = 0
    f.calls = 0

    result = rootfinding.bracket_root(f,
                                      interval,
                                      f_interval=f_interval,
                                      ftol=ftol,
                                      maxiter=0)

    assert f.calls == 1
    check_result(result,
                 f,
                 ftol=ftol,
                 f_calls=f.calls,
                 has_bracket=False,
                 has_root=True)
Ejemplo n.º 7
0
def test_instantrootwithbracket():
    interval = (0, -1.00001)
    f_interval = (f(interval[0]), None)
    ftol = 1e-3
    f.calls = 0

    result = rootfinding.bracket_root(f,
                                      interval,
                                      f_interval=f_interval,
                                      ftol=ftol,
                                      maxiter=0)

    assert f.calls == 1
    check_result(result,
                 f,
                 ftol=ftol,
                 f_calls=f.calls,
                 has_bracket=True,
                 has_root=True)
    rootfinding.bisect(f, result.bracket)