info_outline

Solutions will be available when this assignment is resolved, or after a few failing attempts.

Count Up to X

Build a CountUpToIterator that receives a number and counts from 0 up to that number. Example:

iterator = iter(CountUpToIterator(up_to=10))
next(iterator) # 0
next(iterator) # 1
next(iterator) # 2
next(iterator) # 3
# ... Fast Forward ...
next(iterator) # 9
next(iterator) # 10
next(iterator) # StopIteration() Raised!

Test Cases

test count up to 1 - Run Test

import pytest

def test_count_up_to_1():
    iterator = iter(CountUpToIterator(up_to=1))

    assert next(iterator) == 0
    assert next(iterator) == 1

    with pytest.raises(StopIteration):
        next(iterator)

test count up to 3 - Run Test

import pytest

def test_count_up_to_3():
    iterator = iter(CountUpToIterator(up_to=3))

    assert next(iterator) == 0
    assert next(iterator) == 1
    assert next(iterator) == 2
    assert next(iterator) == 3

    with pytest.raises(StopIteration):
        next(iterator)
class CountUpToIterator(object): pass