"""
Tests for ivp_4_ode.py
"""
from nma.ivp_4_ode import runge_kutta_o4
from numpy.testing import assert_almost_equal


def test_runge_kutta_o4():
    """
    This test is Example 3 in chapter 5 of the textbook.
    """

    # setup
    f = lambda t, y: y - t ** 2 + 1
    a = 0
    b = 2
    N = 10
    y_initial = 0.5

    # exercise
    result, _ = runge_kutta_o4(f, a, b, N, y_initial)
    actual = 5.305363000692653  # @ t = 2

    # verify
    assert_almost_equal(result, actual, 6)

    # teardown - no needed
