diff options
author | Alex Martelli <aleaxit@gmail.com> | 2003-04-22 08:12:33 (GMT) |
---|---|---|
committer | Alex Martelli <aleaxit@gmail.com> | 2003-04-22 08:12:33 (GMT) |
commit | a70b19147fd163744be34745d393af7be603629f (patch) | |
tree | 8ec1a2ae14cfae5fb3a3f14af05a9c9f60b3d739 /Lib | |
parent | 060641d51160f6bf49a049bb677f8412b5a19de3 (diff) | |
download | cpython-a70b19147fd163744be34745d393af7be603629f.zip cpython-a70b19147fd163744be34745d393af7be603629f.tar.gz cpython-a70b19147fd163744be34745d393af7be603629f.tar.bz2 |
Adding new built-in function sum, with docs and tests.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_builtin.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 3956214..e5c9770 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -1099,6 +1099,27 @@ class BuiltinTest(unittest.TestCase): a[0] = a self.assertEqual(str(a), '{0: {...}}') + def test_sum(self): + self.assertEqual(sum([]), 0) + self.assertEqual(sum(range(2,8)), 27) + self.assertEqual(sum(iter(range(2,8))), 27) + self.assertEqual(sum(Squares(10)), 285) + self.assertEqual(sum(iter(Squares(10))), 285) + self.assertEqual(sum([[1], [2], [3]], []), [1, 2, 3]) + + self.assertRaises(TypeError, sum) + self.assertRaises(TypeError, sum, 42) + self.assertRaises(TypeError, sum, ['a', 'b', 'c']) + self.assertRaises(TypeError, sum, ['a', 'b', 'c'], '') + self.assertRaises(TypeError, sum, [[1], [2], [3]]) + self.assertRaises(TypeError, sum, [{2:3}]) + self.assertRaises(TypeError, sum, [{2:3}]*2, {2:3}) + + class BadSeq: + def __getitem__(self, index): + raise ValueError + self.assertRaises(ValueError, sum, BadSeq()) + def test_tuple(self): self.assertEqual(tuple(()), ()) t0_3 = (0, 1, 2, 3) |