diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-05-03 07:00:32 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-05-03 07:00:32 (GMT) |
commit | c30745316258adc66a3c45f45e8fd0148038622a (patch) | |
tree | 2ca22a6b69ee08bc21853117e467b8911a49e40c /Lib/test/test_iter.py | |
parent | c7745d4b54f020e60ad3b56efd6e775d9d4873d4 (diff) | |
download | cpython-c30745316258adc66a3c45f45e8fd0148038622a.zip cpython-c30745316258adc66a3c45f45e8fd0148038622a.tar.gz cpython-c30745316258adc66a3c45f45e8fd0148038622a.tar.bz2 |
Generalize max(seq) and min(seq) to work with iterators.
NEEDS DOC CHANGES.
Diffstat (limited to 'Lib/test/test_iter.py')
-rw-r--r-- | Lib/test/test_iter.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_iter.py b/Lib/test/test_iter.py index 952ab66..64fc01e 100644 --- a/Lib/test/test_iter.py +++ b/Lib/test/test_iter.py @@ -319,4 +319,39 @@ class TestCase(unittest.TestCase): self.assertEqual(filter(lambda x: not x, seq), [False]*25) self.assertEqual(filter(lambda x: not x, iter(seq)), [False]*25) + # Test max() and min()'s use of iterators. + def test_builtin_max_min(self): + self.assertEqual(max(SequenceClass(5)), 4) + self.assertEqual(min(SequenceClass(5)), 0) + self.assertEqual(max(8, -1), 8) + self.assertEqual(min(8, -1), -1) + + d = {"one": 1, "two": 2, "three": 3} + self.assertEqual(max(d), "two") + self.assertEqual(min(d), "one") + self.assertEqual(max(d.itervalues()), 3) + self.assertEqual(min(iter(d.itervalues())), 1) + + self.assertRaises(TypeError, list, list) + self.assertRaises(TypeError, list, 42) + + f = open(TESTFN, "w") + try: + f.write("medium line\n") + f.write("xtra large line\n") + f.write("itty-bitty line\n") + finally: + f.close() + f = open(TESTFN, "r") + try: + self.assertEqual(min(f), "itty-bitty line\n") + f.seek(0, 0) + self.assertEqual(max(f), "xtra large line\n") + finally: + f.close() + try: + unlink(TESTFN) + except OSError: + pass + run_unittest(TestCase) |