def test_yield_iterator_big(self): iter = yield_iterator(Pair(4, Pair(3, Pair(2, Pair(1, None))))) self.assertEqual(next(iter), 4) self.assertEqual(next(iter), 3) self.assertEqual(next(iter), 2) self.assertEqual(next(iter), 1) self.assertRaises(StopIteration, next, iter)
def test_yield_iterator2(self): myList = linked_list.Pair( 4, linked_list.Pair(5, linked_list.Pair(6, None))) y = linked_list.yield_iterator(myList) next(y) #4 next(y) #5 next(y) #6 with self.assertRaises(StopIteration): next(y)
def test_yield_iterator(self): lister = Pair(1, Pair(4, Pair(7, Pair(2, Pair(1, None))))) yielder = yield_iterator(lister) self.assertEqual(next(yielder), 1) self.assertEqual(next(yielder), 4) self.assertEqual(next(yielder), 7) self.assertEqual(next(yielder), 2) self.assertEqual(next(yielder), 1) self.assertRaises(StopIteration, next, yielder)
def test_yield_iterator(self): list = None for i in range(5): list = Pair(i, list) iter = yield_iterator(list) self.assertEqual(next(iter), 4) self.assertEqual(next(iter), 3) self.assertEqual(next(iter), 2) self.assertEqual(next(iter), 1) self.assertEqual(next(iter), 0) self.assertRaises(StopIteration, next, iter)
def test_yield_iterator(self): myList = linked_list.Pair( 4, linked_list.Pair(5, linked_list.Pair(6, None))) y = linked_list.yield_iterator(myList) self.assertEqual(next(y), 4)
def test_yield_iterator_short(self): iter = yield_iterator(Pair(1, None)) self.assertEqual(next(iter), 1) self.assertRaises(StopIteration, next, iter)
def test_yield_iterator_empty(self): lister = None yielder = yield_iterator(lister) self.assertRaises(StopIteration, next, yielder)
def test_yield_iterator(self): gen = yield_iterator(Pair(3, Pair(6, Pair(9, Pair(14, None))))) self.assertEqual(next(gen), 3) self.assertEqual(next(gen), 6) self.assertEqual(next(gen), 9) self.assertEqual(next(gen), 14)