Skip to content

Instantly share code, notes, and snippets.

@serbernar serbernar/

Created Jan 17, 2018
What would you like to do?
count up
from unittest import TestCase
class CountUp:
def __init__(self, *args):
if not args:
n = 0
n = args[0]
if not isinstance(n, (int, float)):
raise TypeError('Must be number')
self.n = n
def __call__(self, *args, **kwargs):
return next(self.__iter__())
def __iter__(self):
self.n += 1
while True:
yield self.n
def __str__(self):
return str(self.n)
class TestCountUp(TestCase):
def setUp(self):
self.c = CountUp(5)
def test_first(self):
self.assertEqual(self.c.n, 5)
def test_count_up(self):
self.assertEqual(self.c.n, 6)
def test_count_up_loop(self):
x = (i for i in range(5))
for i, _ in enumerate(x, 6):
self.assertEqual(self.c.n, i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.