diff options
author | Guido van Rossum <guido@python.org> | 1994-08-01 11:34:53 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1994-08-01 11:34:53 (GMT) |
commit | b6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af (patch) | |
tree | 9362939305b2d088b8f19a530c9015d886bc2801 /Lib/test/test_b2.py | |
parent | 2979b01ff88ac4c5b316d9bf98edbaaaffac8e24 (diff) | |
download | cpython-b6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af.zip cpython-b6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af.tar.gz cpython-b6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af.tar.bz2 |
Merge alpha100 branch back to main trunk
Diffstat (limited to 'Lib/test/test_b2.py')
-rw-r--r-- | Lib/test/test_b2.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_b2.py b/Lib/test/test_b2.py index 7118b08..10c0bfb 100644 --- a/Lib/test/test_b2.py +++ b/Lib/test/test_b2.py @@ -121,6 +121,25 @@ if reduce(lambda x, y: x*y, range(2,8), 1) <> 5040: raise TestFailed, 'reduce(): compute 7!' if reduce(lambda x, y: x*y, range(2,21), 1L) <> 2432902008176640000L: raise TestFailed, 'reduce(): compute 20!, use long' +class Squares: + def __init__(self, max): + self.max = max + self.sofar = [] + def __len__(self): return len(self.sofar) + def __getitem__(self, i): + if not 0 <= i < self.max: raise IndexError + n = len(self.sofar) + while n <= i: + self.sofar.append(n*n) + n = n+1 + return self.sofar[i] +if reduce(lambda x, y: x+y, Squares(10)) != 285: + raise TestFailed, 'reduce(<+>, Squares(10))' +if reduce(lambda x, y: x+y, Squares(10), 0) != 285: + raise TestFailed, 'reduce(<+>, Squares(10), 0)' +if reduce(lambda x, y: x+y, Squares(0), 0) != 0: + raise TestFailed, 'reduce(<+>, Squares(0), 0)' + print 'reload' import string |