annotate Lib/test/test_b1.py @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents 0ba9f914a708
children 4584f08930ac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
653
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 # Python test set -- part 4a, built-in functions a-m
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 from test_support import *
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
2046
1ce3dbeeb890 Test new __import__ module, test reload of built-in module, test
Guido van Rossum <guido@python.org>
parents: 1998
diff changeset
5 print '__import__'
1ce3dbeeb890 Test new __import__ module, test reload of built-in module, test
Guido van Rossum <guido@python.org>
parents: 1998
diff changeset
6 __import__('sys')
1ce3dbeeb890 Test new __import__ module, test reload of built-in module, test
Guido van Rossum <guido@python.org>
parents: 1998
diff changeset
7 __import__('strop')
1ce3dbeeb890 Test new __import__ module, test reload of built-in module, test
Guido van Rossum <guido@python.org>
parents: 1998
diff changeset
8 __import__('string')
1ce3dbeeb890 Test new __import__ module, test reload of built-in module, test
Guido van Rossum <guido@python.org>
parents: 1998
diff changeset
9 try: __import__('spamspam')
1ce3dbeeb890 Test new __import__ module, test reload of built-in module, test
Guido van Rossum <guido@python.org>
parents: 1998
diff changeset
10 except ImportError: pass
1ce3dbeeb890 Test new __import__ module, test reload of built-in module, test
Guido van Rossum <guido@python.org>
parents: 1998
diff changeset
11 else: raise TestFailed, "__import__('spamspam') should fail"
1ce3dbeeb890 Test new __import__ module, test reload of built-in module, test
Guido van Rossum <guido@python.org>
parents: 1998
diff changeset
12
653
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 print 'abs'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 if abs(0) <> 0: raise TestFailed, 'abs(0)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 if abs(1234) <> 1234: raise TestFailed, 'abs(1234)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 if abs(-1234) <> 1234: raise TestFailed, 'abs(-1234)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 #
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 if abs(0.0) <> 0.0: raise TestFailed, 'abs(0.0)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 if abs(3.14) <> 3.14: raise TestFailed, 'abs(3.14)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 if abs(-3.14) <> 3.14: raise TestFailed, 'abs(-3.14)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 #
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 if abs(0L) <> 0L: raise TestFailed, 'abs(0L)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 if abs(1234L) <> 1234L: raise TestFailed, 'abs(1234L)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 if abs(-1234L) <> 1234L: raise TestFailed, 'abs(-1234L)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
25
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 print 'apply'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 def f0(*args):
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 if args != (): raise TestFailed, 'f0 called with ' + `args`
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 def f1(a1):
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 if a1 != 1: raise TestFailed, 'f1 called with ' + `a1`
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 def f2(a1, a2):
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 if a1 != 1 or a2 != 2:
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 raise TestFailed, 'f2 called with ' + `a1, a2`
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 def f3(a1, a2, a3):
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 if a1 != 1 or a2 != 2 or a3 != 3:
1359
5d74a9873589 added builtin b/w compat module.
Guido van Rossum <guido@python.org>
parents: 1197
diff changeset
36 raise TestFailed, 'f3 called with ' + `a1, a2, a3`
653
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 apply(f0, ())
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 apply(f1, (1,))
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 apply(f2, (1, 2))
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 apply(f3, (1, 2, 3))
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
1998
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
42 print 'callable'
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
43 if not callable(len):raise TestFailed, 'callable(len)'
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
44 def f(): pass
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
45 if not callable(f): raise TestFailed, 'callable(f)'
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
46 class C:
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
47 def meth(self): pass
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
48 if not callable(C): raise TestFailed, 'callable(C)'
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
49 x = C()
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
50 if not callable(x.meth): raise TestFailed, 'callable(x.meth)'
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
51 if callable(x): raise TestFailed, 'callable(x)'
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
52 class D(C):
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
53 def __call__(self): pass
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
54 y = D()
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
55 if not callable(y): raise TestFailed, 'callable(y)'
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
56
653
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 print 'chr'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 if chr(32) <> ' ': raise TestFailed, 'chr(32)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 if chr(65) <> 'A': raise TestFailed, 'chr(65)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 if chr(97) <> 'a': raise TestFailed, 'chr(97)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61
1097
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents: 653
diff changeset
62 print 'cmp'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents: 653
diff changeset
63 if cmp(-1, 1) <> -1: raise TestFailed, 'cmp(-1, 1)'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents: 653
diff changeset
64 if cmp(1, -1) <> 1: raise TestFailed, 'cmp(1, -1)'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents: 653
diff changeset
65 if cmp(1, 1) <> 0: raise TestFailed, 'cmp(1, 1)'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents: 653
diff changeset
66
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents: 653
diff changeset
67 print 'coerce'
1197
675a02820d66 * os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
68 if fcmp(coerce(1, 1.1), (1.0, 1.1)): raise TestFailed, 'coerce(1, 1.1)'
1097
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents: 653
diff changeset
69 if coerce(1, 1L) <> (1L, 1L): raise TestFailed, 'coerce(1, 1L)'
1197
675a02820d66 * os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
70 if fcmp(coerce(1L, 1.1), (1.0, 1.1)): raise TestFailed, 'coerce(1L, 1.1)'
1097
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents: 653
diff changeset
71
1998
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
72 print 'compile'
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
73 compile('print 1\n', '', 'exec')
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
74
5222
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
75 print 'complex'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
76 if complex(1,10) <> 1+10j: raise TestFailed, 'complex(1,10)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
77 if complex(1,10L) <> 1+10j: raise TestFailed, 'complex(1,10L)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
78 if complex(1,10.0) <> 1+10j: raise TestFailed, 'complex(1,10.0)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
79 if complex(1L,10) <> 1+10j: raise TestFailed, 'complex(1L,10)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
80 if complex(1L,10L) <> 1+10j: raise TestFailed, 'complex(1L,10L)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
81 if complex(1L,10.0) <> 1+10j: raise TestFailed, 'complex(1L,10.0)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
82 if complex(1.0,10) <> 1+10j: raise TestFailed, 'complex(1.0,10)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
83 if complex(1.0,10L) <> 1+10j: raise TestFailed, 'complex(1.0,10L)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
84 if complex(1.0,10.0) <> 1+10j: raise TestFailed, 'complex(1.0,10.0)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
85 if complex(3.14+0j) <> 3.14+0j: raise TestFailed, 'complex(3.14)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
86 if complex(3.14) <> 3.14+0j: raise TestFailed, 'complex(3.14)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
87 if complex(314) <> 314.0+0j: raise TestFailed, 'complex(314)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
88 if complex(314L) <> 314.0+0j: raise TestFailed, 'complex(314L)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
89 if complex(3.14+0j, 0j) <> 3.14+0j: raise TestFailed, 'complex(3.14, 0j)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
90 if complex(3.14, 0.0) <> 3.14+0j: raise TestFailed, 'complex(3.14, 0.0)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
91 if complex(314, 0) <> 314.0+0j: raise TestFailed, 'complex(314, 0)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
92 if complex(314L, 0L) <> 314.0+0j: raise TestFailed, 'complex(314L, 0L)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
93 if complex(0j, 3.14j) <> -3.14+0j: raise TestFailed, 'complex(0j, 3.14j)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
94 if complex(0.0, 3.14j) <> -3.14+0j: raise TestFailed, 'complex(0.0, 3.14j)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
95 if complex(0j, 3.14) <> 3.14j: raise TestFailed, 'complex(0j, 3.14)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
96 if complex(0.0, 3.14) <> 3.14j: raise TestFailed, 'complex(0.0, 3.14)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
97 class Z:
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
98 def __complex__(self): return 3.14j
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
99 z = Z()
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
100 if complex(z) <> 3.14j: raise TestFailed, 'complex(classinstance)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
101
1998
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
102 print 'delattr'
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
103 import sys
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
104 sys.spam = 1
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
105 delattr(sys, 'spam')
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
106
653
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 print 'dir'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 x = 1
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 if 'x' not in dir(): raise TestFailed, 'dir()'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 import sys
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 if 'modules' not in dir(sys): raise TestFailed, 'dir(sys)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
112
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 print 'divmod'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 if divmod(12, 7) <> (1, 5): raise TestFailed, 'divmod(12, 7)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 if divmod(-12, 7) <> (-2, 2): raise TestFailed, 'divmod(-12, 7)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 if divmod(12, -7) <> (-2, -2): raise TestFailed, 'divmod(12, -7)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 if divmod(-12, -7) <> (1, -5): raise TestFailed, 'divmod(-12, -7)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 #
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 if divmod(12L, 7L) <> (1L, 5L): raise TestFailed, 'divmod(12L, 7L)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 if divmod(-12L, 7L) <> (-2L, 2L): raise TestFailed, 'divmod(-12L, 7L)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 if divmod(12L, -7L) <> (-2L, -2L): raise TestFailed, 'divmod(12L, -7L)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 if divmod(-12L, -7L) <> (1L, -5L): raise TestFailed, 'divmod(-12L, -7L)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 #
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 if divmod(12, 7L) <> (1, 5L): raise TestFailed, 'divmod(12, 7L)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 if divmod(-12, 7L) <> (-2, 2L): raise TestFailed, 'divmod(-12, 7L)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 if divmod(12L, -7) <> (-2L, -2): raise TestFailed, 'divmod(12L, -7)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 if divmod(-12L, -7) <> (1L, -5): raise TestFailed, 'divmod(-12L, -7)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 #
1197
675a02820d66 * os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
129 if fcmp(divmod(3.25, 1.0), (3.0, 0.25)):
675a02820d66 * os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
130 raise TestFailed, 'divmod(3.25, 1.0)'
675a02820d66 * os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
131 if fcmp(divmod(-3.25, 1.0), (-4.0, 0.75)):
675a02820d66 * os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
132 raise TestFailed, 'divmod(-3.25, 1.0)'
675a02820d66 * os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
133 if fcmp(divmod(3.25, -1.0), (-4.0, -0.75)):
675a02820d66 * os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
134 raise TestFailed, 'divmod(3.25, -1.0)'
675a02820d66 * os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
135 if fcmp(divmod(-3.25, -1.0), (3.0, -0.25)):
675a02820d66 * os.py: _exit doesn't exist in all variations of posix
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
136 raise TestFailed, 'divmod(-3.25, -1.0)'
653
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
137
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 print 'eval'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 if eval('1+1') <> 2: raise TestFailed, 'eval(\'1+1\')'
1097
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents: 653
diff changeset
140 if eval(' 1+1\n') <> 2: raise TestFailed, 'eval(\' 1+1\\n\')'
2051
23dfca8aa73b * Lib/test/test_b1.py: test eval() and execfile() with globals,
Guido van Rossum <guido@python.org>
parents: 2046
diff changeset
141 globals = {'a': 1, 'b': 2}
23dfca8aa73b * Lib/test/test_b1.py: test eval() and execfile() with globals,
Guido van Rossum <guido@python.org>
parents: 2046
diff changeset
142 locals = {'b': 200, 'c': 300}
23dfca8aa73b * Lib/test/test_b1.py: test eval() and execfile() with globals,
Guido van Rossum <guido@python.org>
parents: 2046
diff changeset
143 if eval('a', globals) <> 1: raise TestFailed, "eval(1)"
23dfca8aa73b * Lib/test/test_b1.py: test eval() and execfile() with globals,
Guido van Rossum <guido@python.org>
parents: 2046
diff changeset
144 if eval('a', globals, locals) <> 1: raise TestFailed, "eval(2)"
23dfca8aa73b * Lib/test/test_b1.py: test eval() and execfile() with globals,
Guido van Rossum <guido@python.org>
parents: 2046
diff changeset
145 if eval('b', globals, locals) <> 200: raise TestFailed, "eval(3)"
23dfca8aa73b * Lib/test/test_b1.py: test eval() and execfile() with globals,
Guido van Rossum <guido@python.org>
parents: 2046
diff changeset
146 if eval('c', globals, locals) <> 300: raise TestFailed, "eval(4)"
653
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
147
1097
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents: 653
diff changeset
148 print 'execfile'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents: 653
diff changeset
149 z = 0
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents: 653
diff changeset
150 f = open(TESTFN, 'w')
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents: 653
diff changeset
151 f.write('z = z+1\n')
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents: 653
diff changeset
152 f.write('z = z*2\n')
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents: 653
diff changeset
153 f.close()
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents: 653
diff changeset
154 execfile(TESTFN)
2051
23dfca8aa73b * Lib/test/test_b1.py: test eval() and execfile() with globals,
Guido van Rossum <guido@python.org>
parents: 2046
diff changeset
155 if z <> 2: raise TestFailed, "execfile(1)"
23dfca8aa73b * Lib/test/test_b1.py: test eval() and execfile() with globals,
Guido van Rossum <guido@python.org>
parents: 2046
diff changeset
156 globals['z'] = 0
23dfca8aa73b * Lib/test/test_b1.py: test eval() and execfile() with globals,
Guido van Rossum <guido@python.org>
parents: 2046
diff changeset
157 execfile(TESTFN, globals)
23dfca8aa73b * Lib/test/test_b1.py: test eval() and execfile() with globals,
Guido van Rossum <guido@python.org>
parents: 2046
diff changeset
158 if globals['z'] <> 2: raise TestFailed, "execfile(1)"
23dfca8aa73b * Lib/test/test_b1.py: test eval() and execfile() with globals,
Guido van Rossum <guido@python.org>
parents: 2046
diff changeset
159 locals['z'] = 0
23dfca8aa73b * Lib/test/test_b1.py: test eval() and execfile() with globals,
Guido van Rossum <guido@python.org>
parents: 2046
diff changeset
160 execfile(TESTFN, globals, locals)
23dfca8aa73b * Lib/test/test_b1.py: test eval() and execfile() with globals,
Guido van Rossum <guido@python.org>
parents: 2046
diff changeset
161 if locals['z'] <> 2: raise TestFailed, "execfile(1)"
1097
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents: 653
diff changeset
162 unlink(TESTFN)
653
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
163
1403
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
164 print 'filter'
1416
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents: 1403
diff changeset
165 if filter(lambda c: 'a' <= c <= 'z', 'Hello World') <> 'elloorld':
1403
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
166 raise TestFailed, 'filter (filter a string)'
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
167 if filter(None, [1, 'hello', [], [3], '', None, 9, 0]) <> [1, 'hello', [3], 9]:
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
168 raise TestFailed, 'filter (remove false values)'
1416
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents: 1403
diff changeset
169 if filter(lambda x: x > 0, [1, -3, 9, 0, 2]) <> [1, 9, 2]:
1403
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
170 raise TestFailed, 'filter (keep positives)'
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
171 class Squares:
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
172 def __init__(self, max):
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
173 self.max = max
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
174 self.sofar = []
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
175 def __len__(self): return len(self.sofar)
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
176 def __getitem__(self, i):
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
177 if not 0 <= i < self.max: raise IndexError
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
178 n = len(self.sofar)
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
179 while n <= i:
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
180 self.sofar.append(n*n)
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
181 n = n+1
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
182 return self.sofar[i]
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
183 if filter(None, Squares(10)) != [1, 4, 9, 16, 25, 36, 49, 64, 81]:
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
184 raise TestFailed, 'filter(None, Squares(10))'
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
185 if filter(lambda x: x%2, Squares(10)) != [1, 9, 25, 49, 81]:
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
186 raise TestFailed, 'filter(oddp, Squares(10))'
1403
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
187
653
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 print 'float'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 if float(3.14) <> 3.14: raise TestFailed, 'float(3.14)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 if float(314) <> 314.0: raise TestFailed, 'float(314)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 if float(314L) <> 314.0: raise TestFailed, 'float(314L)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
192
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 print 'getattr'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 import sys
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 if getattr(sys, 'stdout') is not sys.stdout: raise TestFailed, 'getattr'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
196
1998
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
197 print 'hasattr'
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
198 import sys
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
199 if not hasattr(sys, 'stdout'): raise TestFailed, 'hasattr'
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
200
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
201 print 'hash'
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
202 hash(None)
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
203 if not hash(1) == hash(1L) == hash(1.0): raise TestFailed, 'numeric hash()'
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
204 hash('spam')
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
205 hash((0,1,2,3))
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
206 def f(): pass
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
207
653
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 print 'hex'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 if hex(16) != '0x10': raise TestFailed, 'hex(16)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 if hex(16L) != '0x10L': raise TestFailed, 'hex(16L)'
5523
0ba9f914a708 Fix hex tests for 64-bit machines.
Guido van Rossum <guido@python.org>
parents: 5222
diff changeset
211 if len(hex(-1)) != len(hex(sys.maxint)): raise TestFailed, 'len(hex(-1))'
0ba9f914a708 Fix hex tests for 64-bit machines.
Guido van Rossum <guido@python.org>
parents: 5222
diff changeset
212 if hex(-16) not in ('0xfffffff0', '0xfffffffffffffff0'):
0ba9f914a708 Fix hex tests for 64-bit machines.
Guido van Rossum <guido@python.org>
parents: 5222
diff changeset
213 raise TestFailed, 'hex(-16)'
653
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 if hex(-16L) != '-0x10L': raise TestFailed, 'hex(-16L)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
215
1998
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
216 print 'id'
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
217 id(None)
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
218 id(1)
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
219 id(1L)
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
220 id(1.0)
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
221 id('spam')
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
222 id((0,1,2,3))
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
223 id([0,1,2,3])
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
224 id({'spam': 1, 'eggs': 2, 'ham': 3})
cf4d8862f19b more complete tests of built-in functions
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
225
653
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
226 # Test input() later, together with raw_input
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
227
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 print 'int'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
229 if int(314) <> 314: raise TestFailed, 'int(314)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 if int(3.14) <> 3: raise TestFailed, 'int(3.14)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 if int(314L) <> 314: raise TestFailed, 'int(314L)'
5222
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
232 # Check that conversion from float truncates towards zero
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
233 if int(-3.14) <> -3: raise TestFailed, 'int(-3.14)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
234 if int(3.9) <> 3: raise TestFailed, 'int(3.9)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
235 if int(-3.9) <> -3: raise TestFailed, 'int(-3.9)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
236 if int(3.5) <> 3: raise TestFailed, 'int(3.5)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
237 if int(-3.5) <> -3: raise TestFailed, 'int(-3.5)'
653
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
238
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 print 'len'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 if len('123') <> 3: raise TestFailed, 'len(\'123\')'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 if len(()) <> 0: raise TestFailed, 'len(())'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 if len((1, 2, 3, 4)) <> 4: raise TestFailed, 'len((1, 2, 3, 4))'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 if len([1, 2, 3, 4]) <> 4: raise TestFailed, 'len([1, 2, 3, 4])'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 if len({}) <> 0: raise TestFailed, 'len({})'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 if len({'a':1, 'b': 2}) <> 2: raise TestFailed, 'len({\'a\':1, \'b\': 2})'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
246
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 print 'long'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 if long(314) <> 314L: raise TestFailed, 'long(314)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 if long(3.14) <> 3L: raise TestFailed, 'long(3.14)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 if long(314L) <> 314L: raise TestFailed, 'long(314L)'
5222
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
251 # Check that conversion from float truncates towards zero
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
252 if long(-3.14) <> -3L: raise TestFailed, 'long(-3.14)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
253 if long(3.9) <> 3L: raise TestFailed, 'long(3.9)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
254 if long(-3.9) <> -3L: raise TestFailed, 'long(-3.9)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
255 if long(3.5) <> 3L: raise TestFailed, 'long(3.5)'
4d8b7dd5de2a Added test of complex() (that catches a bug in 1.4!).
Guido van Rossum <guido@python.org>
parents: 4946
diff changeset
256 if long(-3.5) <> -3L: raise TestFailed, 'long(-3.5)'
653
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
257
1403
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
258 print 'map'
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
259 if map(None, 'hello world') <> ['h','e','l','l','o',' ','w','o','r','l','d']:
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
260 raise TestFailed, 'map(None, \'hello world\')'
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
261 if map(None, 'abcd', 'efg') <> \
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
262 [('a', 'e'), ('b', 'f'), ('c', 'g'), ('d', None)]:
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
263 raise TestFailed, 'map(None, \'abcd\', \'efg\')'
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
264 if map(None, range(10)) <> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
265 raise TestFailed, 'map(None, range(10))'
1416
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents: 1403
diff changeset
266 if map(lambda x: x*x, range(1,4)) <> [1, 4, 9]:
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents: 1403
diff changeset
267 raise TestFailed, 'map(lambda x: x*x, range(1,4))'
2477
11b937ea0026 avoid math, don't abort when overflow check fails
Guido van Rossum <guido@python.org>
parents: 2051
diff changeset
268 try:
11b937ea0026 avoid math, don't abort when overflow check fails
Guido van Rossum <guido@python.org>
parents: 2051
diff changeset
269 from math import sqrt
11b937ea0026 avoid math, don't abort when overflow check fails
Guido van Rossum <guido@python.org>
parents: 2051
diff changeset
270 except ImportError:
11b937ea0026 avoid math, don't abort when overflow check fails
Guido van Rossum <guido@python.org>
parents: 2051
diff changeset
271 def sqrt(x):
11b937ea0026 avoid math, don't abort when overflow check fails
Guido van Rossum <guido@python.org>
parents: 2051
diff changeset
272 return pow(x, 0.5)
1416
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents: 1403
diff changeset
273 if map(lambda x: map(sqrt,x), [[16, 4], [81, 9]]) <> [[4.0, 2.0], [9.0, 3.0]]:
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents: 1403
diff changeset
274 raise TestFailed, 'map(lambda x: map(sqrt,x), [[16, 4], [81, 9]])'
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents: 1403
diff changeset
275 if map(lambda x, y: x+y, [1,3,2], [9,1,4]) <> [10, 4, 6]:
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents: 1403
diff changeset
276 raise TestFailed, 'map(lambda x,y: x+y, [1,3,2], [9,1,4])'
1403
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
277 def plus(*v):
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
278 accu = 0
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
279 for i in v: accu = accu + i
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
280 return accu
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
281 if map(plus, [1, 3, 7]) <> [1, 3, 7]:
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
282 raise TestFailed, 'map(plus, [1, 3, 7])'
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
283 if map(plus, [1, 3, 7], [4, 9, 2]) <> [1+4, 3+9, 7+2]:
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
284 raise TestFailed, 'map(plus, [1, 3, 7], [4, 9, 2])'
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
285 if map(plus, [1, 3, 7], [4, 9, 2], [1, 1, 0]) <> [1+4+1, 3+9+1, 7+2+0]:
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
286 raise TestFailed, 'map(plus, [1, 3, 7], [4, 9, 2], [1, 1, 0])'
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
287 if map(None, Squares(10)) != [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]:
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
288 raise TestFailed, 'map(None, Squares(10))'
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
289 if map(int, Squares(10)) != [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]:
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
290 raise TestFailed, 'map(int, Squares(10))'
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
291 if map(None, Squares(3), Squares(2)) != [(0,0), (1,1), (4,None)]:
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
292 raise TestFailed, 'map(None: x, Squares(3), Squares(2))'
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
293 if map(max, Squares(3), Squares(2)) != [0, 1, 4]:
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1416
diff changeset
294 raise TestFailed, 'map(None: x, Squares(3), Squares(2))'
1403
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1359
diff changeset
295
653
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
296 print 'max'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 if max('123123') <> '3': raise TestFailed, 'max(\'123123\')'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
298 if max(1, 2, 3) <> 3: raise TestFailed, 'max(1, 2, 3)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
299 if max((1, 2, 3, 1, 2, 3)) <> 3: raise TestFailed, 'max((1, 2, 3, 1, 2, 3))'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
300 if max([1, 2, 3, 1, 2, 3]) <> 3: raise TestFailed, 'max([1, 2, 3, 1, 2, 3])'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
301 #
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
302 if max(1, 2L, 3.0) <> 3.0: raise TestFailed, 'max(1, 2L, 3.0)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
303 if max(1L, 2.0, 3) <> 3: raise TestFailed, 'max(1L, 2.0, 3)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
304 if max(1.0, 2, 3L) <> 3L: raise TestFailed, 'max(1.0, 2, 3L)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
305
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
306 print 'min'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
307 if min('123123') <> '1': raise TestFailed, 'min(\'123123\')'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
308 if min(1, 2, 3) <> 1: raise TestFailed, 'min(1, 2, 3)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
309 if min((1, 2, 3, 1, 2, 3)) <> 1: raise TestFailed, 'min((1, 2, 3, 1, 2, 3))'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
310 if min([1, 2, 3, 1, 2, 3]) <> 1: raise TestFailed, 'min([1, 2, 3, 1, 2, 3])'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
311 #
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
312 if min(1, 2L, 3.0) <> 1: raise TestFailed, 'min(1, 2L, 3.0)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
313 if min(1L, 2.0, 3) <> 1L: raise TestFailed, 'min(1L, 2.0, 3)'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
314 if min(1.0, 2, 3L) <> 1.0: raise TestFailed, 'min(1.0, 2, 3L)'