diff options
Diffstat (limited to 'Lib')
-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) |