Range Generator

In this assignment we're going to build a generator (as a function) that mimics the well known range function from Python. As you know, in Python 3, range returns an iterator (in Python 2 we have xrange).

The general usage of our range generator is going to be quite similar to the Python's one:

for num in rmotr_range(start=0, end=3):
    print(num)

>>> 0
>>> 1
>>> 2

for num in rmotr_range(start=1, end=5):
    print(num)

>>> 1
>>> 2
>>> 3
>>> 4

for num in rmotr_range(start=0, end=6, step=2):
    print(num)

>>> 0
>>> 2
>>> 4

Extra: Try to solve this assignment also with an Iterator (a class with __next__ and __iter__ method). Check the solutions for both Iterator and generator based solutions.

import unittest


class SimplePasswordGeneratorTestCase(unittest.TestCase):

    def test_range_generator_basics(self):
        gen1 = iter(rmotr_range(0, 3))
        self.assertEqual(next(gen1), 0)
        self.assertEqual(next(gen1), 1)
        self.assertEqual(next(gen1), 2)
        with self.assertRaises(StopIteration):
            next(gen1)

        gen2 = iter(rmotr_range(3, 6))
        self.assertEqual(next(gen2), 3)
        self.assertEqual(next(gen2), 4)
        self.assertEqual(next(gen2), 5)
        with self.assertRaises(StopIteration):
            next(gen2)

    def test_range_generator_with_step(self):
        gen1 = iter(rmotr_range(2, 10, 2))
        self.assertEqual(next(gen1), 2)
        self.assertEqual(next(gen1), 4)
        self.assertEqual(next(gen1), 6)
        self.assertEqual(next(gen1), 8)
        with self.assertRaises(StopIteration):
            next(gen1)