"""
.. note::

    The following problem was inspired by `Problem 2 at Project Euler`_.

Each new term in the Fibonacci sequence is generated by adding the previous two
terms. By starting with 0 and 1, the first ten terms will be

    0, 1, 1, 2, 3, 5, 8, 13, 21, 34.
    
Define a function according to the following definition:

.. autofunction:: even_fibonacci_numbers

Start by downloading the
:exercise:`exercise template </exercises/even_fibonacci_numbers.py>` and
editing this file. You can run tests via

.. code-block:: console

    $ python even_fibonacci_numbers.py test

to check whether you got a correct solution. You can also take a look at
:solution:`one possible solution </exercises/even_fibonacci_numbers.py>`.

.. _Problem 2 at Project Euler: https://projecteuler.net/problem=2

"""


def even_fibonacci_numbers(n):
    """Return the sum of all even Fibonacci numbers below `n`.

    Parameters
    ----------
    n : int
        The number up to which the sum of Fibonacci numbers is computed.

    Returns
    -------
    int
        The sum of all Fibonacci numbers up to `n`.

    """
    # begin solution
    s = 0
    t_previous = 0
    t = 1
    while t <= n:

        if t % 2 == 0:
            s += t

        t, t_previous = t + t_previous, t

    return s
    # end solution

# -----------------------------------------------------------------------------
# In the following the tests for this exercise are given---do not modify them.
import sys
import pytest


@pytest.mark.parametrize(
    ('n', 'expected'),
    [
        (0, 0),
        (1, 0),
        (2, 2),
        (7, 2),
        (8, 10),
        (33, 10),
        (34, 44)
    ])
def test_correct_result(n, expected):
    assert even_fibonacci_numbers(n) == expected


if __name__ == '__main__':
    if len(sys.argv) == 2 and sys.argv[-1] == 'test':
        pytest.main([__file__])

"""
.. note::

    The following problem was inspired by `Problem 2 at Project Euler`_.

Each new term in the Fibonacci sequence is generated by adding the previous two
terms. By starting with 0 and 1, the first ten terms will be

    0, 1, 1, 2, 3, 5, 8, 13, 21, 34.
    
Define a function according to the following definition:

.. autofunction:: even_fibonacci_numbers

Start by downloading the
:exercise:`exercise template </exercises/even_fibonacci_numbers.py>` and
editing this file. You can run tests via

.. code-block:: console

    $ python even_fibonacci_numbers.py test

to check whether you got a correct solution. You can also take a look at
:solution:`one possible solution </exercises/even_fibonacci_numbers.py>`.

.. _Problem 2 at Project Euler: https://projecteuler.net/problem=2

"""


def even_fibonacci_numbers(n):
    """Return the sum of all even Fibonacci numbers below `n`.

    Parameters
    ----------
    n : int
        The number up to which the sum of Fibonacci numbers is computed.

    Returns
    -------
    int
        The sum of all Fibonacci numbers up to `n`.

    """
    # begin solution
    s = 0
    t_previous = 0
    t = 1
    while t < n:

        if t % 2 == 0:
            s += t

        t, t_previous = t + t_previous, t

    return s
    # end solution

# -----------------------------------------------------------------------------
# In the following the tests for this exercise are given---do not modify them.
import sys
import pytest


@pytest.mark.parametrize(
    ('n', 'expected'),
    [
        (0, 0),
        (2, 0),
        (3, 2),
        (8, 2),
        (9, 10),
        (34, 10),
        (35, 44)
    ])
def test_correct_result(n, expected):
    assert even_fibonacci_numbers(n) == expected


if __name__ == '__main__':
    if len(sys.argv) == 2 and sys.argv[-1] == 'test':
        pytest.main([__file__])

Fix bug summing up the number including n, not up to n