*** test_itertools.py.orig Tue Jun 17 15:52:53 2003 --- test_itertools.py Tue Jun 17 16:48:44 2003 *************** *** 40,45 **** --- 40,53 ---- self.assertEqual(list(chain('')), []) self.assertRaises(TypeError, chain, 2, 3) + def test_roundrobin(self): + self.assertEqual(list(roundrobin('abc', 'def')), list('adbecf')) + self.assertEqual(list(roundrobin('abc', 'd', 'efghi', 'lmnopqr')), + list('adelbfmcgnhoipqr')) + self.assertEqual(list(roundrobin('abc')), list('abc')) + self.assertEqual(list(roundrobin('')), []) + self.assertRaises(TypeError, roundrobin, 2,3) + def test_count(self): self.assertEqual(zip('abc',count()), [('a', 0), ('b', 1), ('c', 2)]) self.assertEqual(zip('abc',count(3)), [('a', 3), ('b', 4), ('c', 5)]) *************** *** 183,188 **** --- 191,203 ---- self.assertRaises(TypeError, dropwhile(10, [(4,5)]).next) self.assertRaises(ValueError, dropwhile(errfunc, [(4,5)]).next) + def test_windowsize(self): + data = range(7) + expected = [(0,1), (1,2), (2,3), (3,4), (4,5), (5,6)] + self.assertEqual(list(window(data, 2)), expected) + self.assertEqual(list(window(data, 1)), map(lambda x:tuple([x]), data)) + self.assertEqual(list(window([], 7)), []) + def test_StopIteration(self): for f in (chain, cycle, izip): self.assertRaises(StopIteration, f([]).next) *************** *** 285,290 **** --- 300,318 ---- self.assertRaises(TypeError, list, chain(N(s))) self.assertRaises(ZeroDivisionError, list, chain(E(s))) + def test_roundrobin(self): + for s in ("123", "", range(1000), ('do', 1.2), xrange(2000,2200,5)): + for g in (G, I, Ig, S, L, R): + self.assertEqual(list(roundrobin(g(s))), list(g(s))) + doubleup = [] + for (x) in g(s): + doubleup.append(x) + doubleup.append(x) + self.assertEqual(list(roundrobin(g(s), g(s))), doubleup) + self.assertRaises(TypeError, roundrobin, X(s)) + self.assertRaises((TypeError, AttributeError), list, roundrobin(N(s))) + self.assertRaises(ZeroDivisionError, list, roundrobin(E(s))) + def test_cycle(self): for s in ("123", "", range(1000), ('do', 1.2), xrange(2000,2200,5)): for g in (G, I, Ig, S, L, R): *************** *** 371,376 **** --- 399,412 ---- self.assertRaises(TypeError, list, dropwhile(isOdd, N(s))) self.assertRaises(ZeroDivisionError, list, dropwhile(isOdd, E(s))) + def test_window(self): + for s in ("12345", "", range(1000), ('do', 1.2), xrange(20,22,5)): + for g in (G, I, Ig, S, L, R): + self.assertEqual(list(window(g(s), 1)), map(lambda x:tuple([x]), g(s))) + self.assertRaises(TypeError, window, X(s), 1) + self.assertRaises(TypeError, list, window(N(s), 69)) + self.assertRaises(ValueError, window, 'abc', -1) + self.assertRaises(ValueError, window, 'abc', 0) libreftest = """ Doctest for examples in the library reference: libitertools.tex