diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-05-04 04:39:21 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-05-04 04:39:21 (GMT) |
commit | 15d81efb8a7045ce2860792f11741965b496a98b (patch) | |
tree | d9fffce067670c536175ebd8f6b81fc9b20976a3 /Lib/test/test_iter.py | |
parent | 8bc10b0c579f740bbdf77a1db90d5de733fcf20e (diff) | |
download | cpython-15d81efb8a7045ce2860792f11741965b496a98b.zip cpython-15d81efb8a7045ce2860792f11741965b496a98b.tar.gz cpython-15d81efb8a7045ce2860792f11741965b496a98b.tar.bz2 |
Generalize reduce() to work with iterators.
NEEDS DOC CHANGES.
Diffstat (limited to 'Lib/test/test_iter.py')
-rw-r--r-- | Lib/test/test_iter.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_iter.py b/Lib/test/test_iter.py index 66f40c1..5584587 100644 --- a/Lib/test/test_iter.py +++ b/Lib/test/test_iter.py @@ -385,4 +385,17 @@ class TestCase(unittest.TestCase): except OSError: pass + # Test reduces()'s use of iterators. + def test_builtin_reduce(self): + from operator import add + self.assertEqual(reduce(add, SequenceClass(5)), 10) + self.assertEqual(reduce(add, SequenceClass(5), 42), 52) + self.assertRaises(TypeError, reduce, add, SequenceClass(0)) + self.assertEqual(reduce(add, SequenceClass(0), 42), 42) + self.assertEqual(reduce(add, SequenceClass(1)), 0) + self.assertEqual(reduce(add, SequenceClass(1), 42), 42) + + d = {"one": 1, "two": 2, "three": 3} + self.assertEqual(reduce(add, d), "".join(d.keys())) + run_unittest(TestCase) |