diff options
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_b1.py | 24 | ||||
-rw-r--r-- | Lib/test/test_b2.py | 19 | ||||
-rw-r--r-- | Lib/test/test_grammar.py | 120 | ||||
-rw-r--r-- | Lib/test/test_types.py | 6 | ||||
-rw-r--r-- | Lib/test/testall.out | 11 |
5 files changed, 152 insertions, 28 deletions
diff --git a/Lib/test/test_b1.py b/Lib/test/test_b1.py index 434b379..5eb4f09 100644 --- a/Lib/test/test_b1.py +++ b/Lib/test/test_b1.py @@ -97,6 +97,22 @@ if filter(None, [1, 'hello', [], [3], '', None, 9, 0]) <> [1, 'hello', [3], 9]: raise TestFailed, 'filter (remove false values)' if filter(lambda x: x > 0, [1, -3, 9, 0, 2]) <> [1, 9, 2]: raise TestFailed, 'filter (keep positives)' +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 filter(None, Squares(10)) != [1, 4, 9, 16, 25, 36, 49, 64, 81]: + raise TestFailed, 'filter(None, Squares(10))' +if filter(lambda x: x%2, Squares(10)) != [1, 9, 25, 49, 81]: + raise TestFailed, 'filter(oddp, Squares(10))' print 'float' if float(3.14) <> 3.14: raise TestFailed, 'float(3.14)' @@ -158,6 +174,14 @@ if map(plus, [1, 3, 7], [4, 9, 2]) <> [1+4, 3+9, 7+2]: raise TestFailed, 'map(plus, [1, 3, 7], [4, 9, 2])' if map(plus, [1, 3, 7], [4, 9, 2], [1, 1, 0]) <> [1+4+1, 3+9+1, 7+2+0]: raise TestFailed, 'map(plus, [1, 3, 7], [4, 9, 2], [1, 1, 0])' +if map(None, Squares(10)) != [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]: + raise TestFailed, 'map(None, Squares(10))' +if map(int, Squares(10)) != [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]: + raise TestFailed, 'map(int, Squares(10))' +if map(None, Squares(3), Squares(2)) != [(0,0), (1,1), (4,None)]: + raise TestFailed, 'map(None: x, Squares(3), Squares(2))' +if map(max, Squares(3), Squares(2)) != [0, 1, 4]: + raise TestFailed, 'map(None: x, Squares(3), Squares(2))' print 'max' if max('123123') <> '3': raise TestFailed, 'max(\'123123\')' 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 diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index 0988574..67baf09 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -41,7 +41,7 @@ if maxint == 2147483647: raise TestFailed, \ 'No OverflowError on huge integer literal ' + `s` elif eval('maxint == 9223372036854775807'): - if eval('9223372036854775807-1 != -01000000000000000000000'): + if eval('-9223372036854775807-1 != 01000000000000000000000'): raise TestFailed, 'max negative int' if eval('01777777777777777777777') != -1: raise TestFailed, 'oct -1' if eval('0xffffffffffffffff') != -1: raise TestFailed, 'hex -1' @@ -91,9 +91,35 @@ x = '"'; y = "\""; assert(len(x) == 1 and x == y and ord(x) == 34) x = "doesn't \"shrink\" does it" y = 'doesn\'t "shrink" does it' assert(len(x) == 24 and x == y) -x = "doesn \"shrink\" doesn't it" -y = 'doesn "shrink" doesn\'t it' -assert(len(x) == 25 and x == y) +x = "does \"shrink\" doesn't it" +y = 'does "shrink" doesn\'t it' +assert(len(x) == 24 and x == y) +x = """ +The "quick" +brown fox +jumps over +the 'lazy' dog. +""" +y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n' +assert(x == y) +y = ''' +The "quick" +brown fox +jumps over +the 'lazy' dog. +'''; assert(x == y) +y = "\n\ +The \"quick\"\n\ +brown fox\n\ +jumps over\n\ +the 'lazy' dog.\n\ +"; assert(x == y) +y = '\n\ +The \"quick\"\n\ +brown fox\n\ +jumps over\n\ +the \'lazy\' dog.\n\ +'; assert(x == y) print '1.2 Grammar' @@ -113,7 +139,8 @@ x = eval('1, 0 or 1') print 'funcdef' ### 'def' NAME parameters ':' suite ### parameters: '(' [varargslist] ')' -### varargslist: (fpdef ',')* '*' NAME | fpdef (',' fpdef)* [','] +### varargslist: (fpdef ['=' test] ',')* '*' NAME +### | fpdef ['=' test] (',' fpdef ['=' test])* [','] ### fpdef: NAME | '(' fplist ')' ### fplist: fpdef (',' fpdef)* [','] def f1(): pass @@ -126,6 +153,54 @@ def v0(*rest): pass def v1(a, *rest): pass def v2(a, b, *rest): pass def v3(a, (b, c), *rest): pass +def d01(a=1): pass +d01() +d01(1) +def d11(a, b=1): pass +d11(1) +d11(1, 2) +def d21(a, b, c=1): pass +d21(1, 2) +d21(1, 2, 3) +def d02(a=1, b=2): pass +d02() +d02(1) +d02(1, 2) +def d12(a, b=1, c=2): pass +d12(1) +d12(1, 2) +d12(1, 2, 3) +def d22(a, b, c=1, d=2): pass +d22(1, 2) +d22(1, 2, 3) +d22(1, 2, 3, 4) +def d01v(a=1, *rest): pass +d01v() +d01v(1) +d01v(1, 2) +def d11v(a, b=1, *rest): pass +d11v(1) +d11v(1, 2) +d11v(1, 2, 3) +def d21v(a, b, c=1, *rest): pass +d21v(1, 2) +d21v(1, 2, 3) +d21v(1, 2, 3, 4) +def d02v(a=1, b=2, *rest): pass +d02v() +d02v(1) +d02v(1, 2) +d02v(1, 2, 3) +def d12v(a, b=1, c=2, *rest): pass +d12v(1) +d12v(1, 2) +d12v(1, 2, 3) +d12v(1, 2, 3, 4) +def d22v(a, b, c=1, d=2, *rest): pass +d22v(1, 2) +d22v(1, 2, 3) +d22v(1, 2, 3, 4) +d22v(1, 2, 3, 4, 5) ### stmt: simple_stmt | compound_stmt # Tested below @@ -184,17 +259,11 @@ try: raise KeyboardInterrupt except KeyboardInterrupt: pass print 'import_stmt' # 'import' NAME (',' NAME)* | 'from' NAME 'import' ('*' | NAME (',' NAME)*) -[1] import sys -[2] import time, math -[3] -from time import sleep -[4] +from time import time from sys import * -[5] from math import sin, cos -[6] print 'global_stmt' # 'global' NAME (',' NAME)* def f(): @@ -242,24 +311,41 @@ while 0: pass else: pass print 'for_stmt' # 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite] -[1] for i in 1, 2, 3: pass -[2] for i, j, k in (): pass else: pass -[3] - -print 'try_stmt' # 'try' ':' suite (except_clause ':' suite)+ | 'try' ':' suite 'finally' ':' suite +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] +n = 0 +for x in Squares(10): n = n+x +if n != 285: raise TestFailed, 'for over growing sequence' + +print 'try_stmt' +### try_stmt: 'try' ':' suite (except_clause ':' suite)+ ['else' ':' suite] +### | 'try' ':' suite 'finally' ':' suite ### except_clause: 'except' [expr [',' expr]] try: 1/0 except ZeroDivisionError: pass +else: + pass try: 1/0 except EOFError: pass except TypeError, msg: pass except RuntimeError, msg: pass except: pass +else: pass try: 1/0 except (EOFError, TypeError, ZeroDivisionError): pass try: 1/0 diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index 0a43de3..6a3f772 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -67,6 +67,10 @@ if (-12) + 24 <> 12: raise TestFailed, 'int op' if (-12) + (-24) <> -36: raise TestFailed, 'int op' if not 12 < 24: raise TestFailed, 'int op' if not -24 < -12: raise TestFailed, 'int op' +# Test for a particular bug in integer multiply +xsize, ysize, zsize = 238, 356, 4 +if not (xsize*ysize*zsize == zsize*xsize*ysize == 338912): + raise TestFailed, 'int mul commutativity' print '6.4.2 Long integers' if 12L + 24L <> 36L: raise TestFailed, 'long op' if 12L + (-24L) <> -12L: raise TestFailed, 'long op' @@ -94,6 +98,8 @@ if 0*'abcde' <> '': raise TestFailed, 'string repetition 0*' if min('abc') <> 'a' or max('abc') <> 'c': raise TestFailed, 'min/max string' if 'a' in 'abc' and 'b' in 'abc' and 'c' in 'abc' and 'd' not in 'abc': pass else: raise TestFailed, 'in/not in string' +x = 'x'*103 +if '%s!'%x != x+'!': raise TestFailed, 'nasty string formatting bug' print '6.5.2 Tuples' if len(()) <> 0: raise TestFailed, 'len(())' diff --git a/Lib/test/testall.out b/Lib/test/testall.out index 46a728e..b921512 100644 --- a/Lib/test/testall.out +++ b/Lib/test/testall.out @@ -15,8 +15,6 @@ eval_input funcdef simple_stmt expr_stmt -1 -(1, 2, 3) print_stmt 1 2 3 1 2 3 @@ -29,20 +27,11 @@ continue_stmt return_stmt raise_stmt import_stmt -[1] -[2] -[3] -[4] -[5] -[6] global_stmt exec_stmt if_stmt while_stmt for_stmt -[1] -[2] -[3] try_stmt suite test |