diff options
author | Raymond Hettinger <python@rcn.com> | 2003-02-09 06:40:58 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-02-09 06:40:58 (GMT) |
commit | 60eca9331a1c2594b1331678d715e6177386c3a4 (patch) | |
tree | fe68e9debd8adce5a689842d2d465d892a20b7ea /Lib/test/test_itertools.py | |
parent | cb3319f61e94af8794a51f51730dce4a9d512af3 (diff) | |
download | cpython-60eca9331a1c2594b1331678d715e6177386c3a4.zip cpython-60eca9331a1c2594b1331678d715e6177386c3a4.tar.gz cpython-60eca9331a1c2594b1331678d715e6177386c3a4.tar.bz2 |
C Code:
* Removed the ifilter flag wart by splitting it into two simpler functions.
* Fixed comment tabbing in C code.
* Factored module start-up code into a loop.
Documentation:
* Re-wrote introduction.
* Addede examples for quantifiers.
* Simplified python equivalent for islice().
* Documented split of ifilter().
Sets.py:
* Replace old ifilter() usage with new.
Diffstat (limited to 'Lib/test/test_itertools.py')
-rw-r--r-- | Lib/test/test_itertools.py | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index cef1718..09b7d13 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -13,12 +13,19 @@ class TestBasicOps(unittest.TestCase): def isEven(x): return x%2==0 self.assertEqual(list(ifilter(isEven, range(6))), [0,2,4]) - self.assertEqual(list(ifilter(isEven, range(6), True)), [1,3,5]) self.assertEqual(list(ifilter(None, [0,1,0,2,0])), [1,2]) self.assertRaises(TypeError, ifilter) self.assertRaises(TypeError, ifilter, 3) self.assertRaises(TypeError, ifilter, isEven, 3) - self.assertRaises(TypeError, ifilter, isEven, [3], True, 4) + + def test_ifilterfalse(self): + def isEven(x): + return x%2==0 + self.assertEqual(list(ifilterfalse(isEven, range(6))), [1,3,5]) + self.assertEqual(list(ifilterfalse(None, [0,1,0,2,0])), [0,0,0]) + self.assertRaises(TypeError, ifilterfalse) + self.assertRaises(TypeError, ifilterfalse, 3) + self.assertRaises(TypeError, ifilterfalse, isEven, 3) def test_izip(self): ans = [(x,y) for x, y in izip('abc',count())] @@ -133,7 +140,19 @@ Samuele >>> def nth(iterable, n): ... "Returns the nth item" -... return islice(iterable, n, n+1).next() +... return list(islice(iterable, n, n+1)) + +>>> def all(pred, seq): +... "Returns True if pred(x) is True for every element in the iterable" +... return not nth(ifilterfalse(pred, seq), 0) + +>>> def some(pred, seq): +... "Returns True if pred(x) is True at least one element in the iterable" +... return bool(nth(ifilter(pred, seq), 0)) + +>>> def no(pred, seq): +... "Returns True if pred(x) is False for every element in the iterable" +... return not nth(ifilter(pred, seq), 0) """ |