diff options
| author | Raymond Hettinger <python@rcn.com> | 2014-06-25 04:53:45 (GMT) |
|---|---|---|
| committer | Raymond Hettinger <python@rcn.com> | 2014-06-25 04:53:45 (GMT) |
| commit | 58ad24512a60694486ba50302cc1e805a84e7f94 (patch) | |
| tree | b73ffeabfe7a5d7655b7b57f3ab5e529f6c21464 /Lib/test/test_itertools.py | |
| parent | 3fecd48bded335cf79851a23c66fd8e8195f9516 (diff) | |
| download | cpython-58ad24512a60694486ba50302cc1e805a84e7f94.zip cpython-58ad24512a60694486ba50302cc1e805a84e7f94.tar.gz cpython-58ad24512a60694486ba50302cc1e805a84e7f94.tar.bz2 | |
Issue #19145: Fix handling of negative values for a "times" keyword argument to itertools.repeat()>
(Patch contributed by Vajrasky Kok.)
Diffstat (limited to 'Lib/test/test_itertools.py')
| -rw-r--r-- | Lib/test/test_itertools.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index 291aeb0..1bf6c53 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -698,6 +698,9 @@ class TestBasicOps(unittest.TestCase): def test_repeat(self): self.assertEqual(list(repeat(object='a', times=3)), ['a', 'a', 'a']) + self.assertEqual(list(repeat(object='a', times=0)), []) + self.assertEqual(list(repeat(object='a', times=-1)), []) + self.assertEqual(list(repeat(object='a', times=-2)), []) self.assertEqual(zip(xrange(3),repeat('a')), [(0, 'a'), (1, 'a'), (2, 'a')]) self.assertEqual(list(repeat('a', 3)), ['a', 'a', 'a']) @@ -714,6 +717,12 @@ class TestBasicOps(unittest.TestCase): list(r) self.assertEqual(repr(r), 'repeat((1+0j), 0)') + def test_repeat_with_negative_times(self): + self.assertEqual(repr(repeat('a', -1)), "repeat('a', 0)") + self.assertEqual(repr(repeat('a', -2)), "repeat('a', 0)") + self.assertEqual(repr(repeat('a', times=-1)), "repeat('a', 0)") + self.assertEqual(repr(repeat('a', times=-2)), "repeat('a', 0)") + def test_imap(self): self.assertEqual(list(imap(operator.pow, range(3), range(1,7))), [0**1, 1**2, 2**3]) |
