Fix the availability statement for the spawn*() functions to reflect the
[python/dscho.git] / Lib / test / test_b1.py
blobf2d0c24d4cc56edc9cab10abe609235e73533764
1 # Python test set -- part 4a, built-in functions a-m
3 from test_support import *
5 print '__import__'
6 __import__('sys')
7 __import__('time')
8 __import__('string')
9 try: __import__('spamspam')
10 except ImportError: pass
11 else: raise TestFailed, "__import__('spamspam') should fail"
13 print 'abs'
14 if abs(0) != 0: raise TestFailed, 'abs(0)'
15 if abs(1234) != 1234: raise TestFailed, 'abs(1234)'
16 if abs(-1234) != 1234: raise TestFailed, 'abs(-1234)'
18 if abs(0.0) != 0.0: raise TestFailed, 'abs(0.0)'
19 if abs(3.14) != 3.14: raise TestFailed, 'abs(3.14)'
20 if abs(-3.14) != 3.14: raise TestFailed, 'abs(-3.14)'
22 if abs(0L) != 0L: raise TestFailed, 'abs(0L)'
23 if abs(1234L) != 1234L: raise TestFailed, 'abs(1234L)'
24 if abs(-1234L) != 1234L: raise TestFailed, 'abs(-1234L)'
26 try: abs('a')
27 except TypeError: pass
28 else: raise TestFailed, 'abs("a")'
30 print 'apply'
31 def f0(*args):
32 if args != (): raise TestFailed, 'f0 called with ' + `args`
33 def f1(a1):
34 if a1 != 1: raise TestFailed, 'f1 called with ' + `a1`
35 def f2(a1, a2):
36 if a1 != 1 or a2 != 2:
37 raise TestFailed, 'f2 called with ' + `a1, a2`
38 def f3(a1, a2, a3):
39 if a1 != 1 or a2 != 2 or a3 != 3:
40 raise TestFailed, 'f3 called with ' + `a1, a2, a3`
41 apply(f0, ())
42 apply(f1, (1,))
43 apply(f2, (1, 2))
44 apply(f3, (1, 2, 3))
46 # A PyCFunction that takes only positional parameters should allow an
47 # empty keyword dictionary to pass without a complaint, but raise a
48 # TypeError if the dictionary is non-empty.
49 apply(id, (1,), {})
50 try:
51 apply(id, (1,), {"foo": 1})
52 except TypeError:
53 pass
54 else:
55 raise TestFailed, 'expected TypeError; no exception raised'
57 print 'callable'
58 if not callable(len):raise TestFailed, 'callable(len)'
59 def f(): pass
60 if not callable(f): raise TestFailed, 'callable(f)'
61 class C:
62 def meth(self): pass
63 if not callable(C): raise TestFailed, 'callable(C)'
64 x = C()
65 if not callable(x.meth): raise TestFailed, 'callable(x.meth)'
66 if callable(x): raise TestFailed, 'callable(x)'
67 class D(C):
68 def __call__(self): pass
69 y = D()
70 if not callable(y): raise TestFailed, 'callable(y)'
71 y()
73 print 'chr'
74 if chr(32) != ' ': raise TestFailed, 'chr(32)'
75 if chr(65) != 'A': raise TestFailed, 'chr(65)'
76 if chr(97) != 'a': raise TestFailed, 'chr(97)'
78 # cmp
79 print 'cmp'
80 if cmp(-1, 1) != -1: raise TestFailed, 'cmp(-1, 1)'
81 if cmp(1, -1) != 1: raise TestFailed, 'cmp(1, -1)'
82 if cmp(1, 1) != 0: raise TestFailed, 'cmp(1, 1)'
83 # verify that circular objects are handled
84 a = []; a.append(a)
85 b = []; b.append(b)
86 from UserList import UserList
87 c = UserList(); c.append(c)
88 if cmp(a, b) != 0: raise TestFailed, "cmp(%s, %s)" % (a, b)
89 if cmp(b, c) != 0: raise TestFailed, "cmp(%s, %s)" % (b, c)
90 if cmp(c, a) != 0: raise TestFailed, "cmp(%s, %s)" % (c, a)
91 if cmp(a, c) != 0: raise TestFailed, "cmp(%s, %s)" % (a, c)
92 # okay, now break the cycles
93 a.pop(); b.pop(); c.pop()
95 print 'coerce'
96 if fcmp(coerce(1, 1.1), (1.0, 1.1)): raise TestFailed, 'coerce(1, 1.1)'
97 if coerce(1, 1L) != (1L, 1L): raise TestFailed, 'coerce(1, 1L)'
98 if fcmp(coerce(1L, 1.1), (1.0, 1.1)): raise TestFailed, 'coerce(1L, 1.1)'
100 print 'compile'
101 compile('print 1\n', '', 'exec')
103 print 'complex'
104 if complex(1,10) != 1+10j: raise TestFailed, 'complex(1,10)'
105 if complex(1,10L) != 1+10j: raise TestFailed, 'complex(1,10L)'
106 if complex(1,10.0) != 1+10j: raise TestFailed, 'complex(1,10.0)'
107 if complex(1L,10) != 1+10j: raise TestFailed, 'complex(1L,10)'
108 if complex(1L,10L) != 1+10j: raise TestFailed, 'complex(1L,10L)'
109 if complex(1L,10.0) != 1+10j: raise TestFailed, 'complex(1L,10.0)'
110 if complex(1.0,10) != 1+10j: raise TestFailed, 'complex(1.0,10)'
111 if complex(1.0,10L) != 1+10j: raise TestFailed, 'complex(1.0,10L)'
112 if complex(1.0,10.0) != 1+10j: raise TestFailed, 'complex(1.0,10.0)'
113 if complex(3.14+0j) != 3.14+0j: raise TestFailed, 'complex(3.14)'
114 if complex(3.14) != 3.14+0j: raise TestFailed, 'complex(3.14)'
115 if complex(314) != 314.0+0j: raise TestFailed, 'complex(314)'
116 if complex(314L) != 314.0+0j: raise TestFailed, 'complex(314L)'
117 if complex(3.14+0j, 0j) != 3.14+0j: raise TestFailed, 'complex(3.14, 0j)'
118 if complex(3.14, 0.0) != 3.14+0j: raise TestFailed, 'complex(3.14, 0.0)'
119 if complex(314, 0) != 314.0+0j: raise TestFailed, 'complex(314, 0)'
120 if complex(314L, 0L) != 314.0+0j: raise TestFailed, 'complex(314L, 0L)'
121 if complex(0j, 3.14j) != -3.14+0j: raise TestFailed, 'complex(0j, 3.14j)'
122 if complex(0.0, 3.14j) != -3.14+0j: raise TestFailed, 'complex(0.0, 3.14j)'
123 if complex(0j, 3.14) != 3.14j: raise TestFailed, 'complex(0j, 3.14)'
124 if complex(0.0, 3.14) != 3.14j: raise TestFailed, 'complex(0.0, 3.14)'
125 if complex("1") != 1+0j: raise TestFailed, 'complex("1")'
126 if complex("1j") != 1j: raise TestFailed, 'complex("1j")'
127 try: complex("1", "1")
128 except TypeError: pass
129 else: raise TestFailed, 'complex("1", "1")'
130 try: complex(1, "1")
131 except TypeError: pass
132 else: raise TestFailed, 'complex(1, "1")'
133 if complex(" 3.14+J ") != 3.14+1j: raise TestFailed, 'complex(" 3.14+J )"'
134 if have_unicode:
135 if complex(unicode(" 3.14+J ")) != 3.14+1j:
136 raise TestFailed, 'complex(u" 3.14+J )"'
137 class Z:
138 def __complex__(self): return 3.14j
139 z = Z()
140 if complex(z) != 3.14j: raise TestFailed, 'complex(classinstance)'
142 print 'delattr'
143 import sys
144 sys.spam = 1
145 delattr(sys, 'spam')
147 print 'dir'
148 x = 1
149 if 'x' not in dir(): raise TestFailed, 'dir()'
150 import sys
151 if 'modules' not in dir(sys): raise TestFailed, 'dir(sys)'
153 print 'divmod'
154 if divmod(12, 7) != (1, 5): raise TestFailed, 'divmod(12, 7)'
155 if divmod(-12, 7) != (-2, 2): raise TestFailed, 'divmod(-12, 7)'
156 if divmod(12, -7) != (-2, -2): raise TestFailed, 'divmod(12, -7)'
157 if divmod(-12, -7) != (1, -5): raise TestFailed, 'divmod(-12, -7)'
159 if divmod(12L, 7L) != (1L, 5L): raise TestFailed, 'divmod(12L, 7L)'
160 if divmod(-12L, 7L) != (-2L, 2L): raise TestFailed, 'divmod(-12L, 7L)'
161 if divmod(12L, -7L) != (-2L, -2L): raise TestFailed, 'divmod(12L, -7L)'
162 if divmod(-12L, -7L) != (1L, -5L): raise TestFailed, 'divmod(-12L, -7L)'
164 if divmod(12, 7L) != (1, 5L): raise TestFailed, 'divmod(12, 7L)'
165 if divmod(-12, 7L) != (-2, 2L): raise TestFailed, 'divmod(-12, 7L)'
166 if divmod(12L, -7) != (-2L, -2): raise TestFailed, 'divmod(12L, -7)'
167 if divmod(-12L, -7) != (1L, -5): raise TestFailed, 'divmod(-12L, -7)'
169 if fcmp(divmod(3.25, 1.0), (3.0, 0.25)):
170 raise TestFailed, 'divmod(3.25, 1.0)'
171 if fcmp(divmod(-3.25, 1.0), (-4.0, 0.75)):
172 raise TestFailed, 'divmod(-3.25, 1.0)'
173 if fcmp(divmod(3.25, -1.0), (-4.0, -0.75)):
174 raise TestFailed, 'divmod(3.25, -1.0)'
175 if fcmp(divmod(-3.25, -1.0), (3.0, -0.25)):
176 raise TestFailed, 'divmod(-3.25, -1.0)'
178 print 'eval'
179 if eval('1+1') != 2: raise TestFailed, 'eval(\'1+1\')'
180 if eval(' 1+1\n') != 2: raise TestFailed, 'eval(\' 1+1\\n\')'
181 globals = {'a': 1, 'b': 2}
182 locals = {'b': 200, 'c': 300}
183 if eval('a', globals) != 1:
184 raise TestFailed, "eval(1) == %s" % eval('a', globals)
185 if eval('a', globals, locals) != 1:
186 raise TestFailed, "eval(2)"
187 if eval('b', globals, locals) != 200:
188 raise TestFailed, "eval(3)"
189 if eval('c', globals, locals) != 300:
190 raise TestFailed, "eval(4)"
191 if have_unicode:
192 if eval(unicode('1+1')) != 2: raise TestFailed, 'eval(u\'1+1\')'
193 if eval(unicode(' 1+1\n')) != 2: raise TestFailed, 'eval(u\' 1+1\\n\')'
194 globals = {'a': 1, 'b': 2}
195 locals = {'b': 200, 'c': 300}
196 if have_unicode:
197 if eval(unicode('a'), globals) != 1:
198 raise TestFailed, "eval(1) == %s" % eval(unicode('a'), globals)
199 if eval(unicode('a'), globals, locals) != 1:
200 raise TestFailed, "eval(2)"
201 if eval(unicode('b'), globals, locals) != 200:
202 raise TestFailed, "eval(3)"
203 if eval(unicode('c'), globals, locals) != 300:
204 raise TestFailed, "eval(4)"
206 print 'execfile'
207 z = 0
208 f = open(TESTFN, 'w')
209 f.write('z = z+1\n')
210 f.write('z = z*2\n')
211 f.close()
212 execfile(TESTFN)
213 if z != 2: raise TestFailed, "execfile(1)"
214 globals['z'] = 0
215 execfile(TESTFN, globals)
216 if globals['z'] != 2: raise TestFailed, "execfile(1)"
217 locals['z'] = 0
218 execfile(TESTFN, globals, locals)
219 if locals['z'] != 2: raise TestFailed, "execfile(1)"
220 unlink(TESTFN)
222 print 'filter'
223 if filter(lambda c: 'a' <= c <= 'z', 'Hello World') != 'elloorld':
224 raise TestFailed, 'filter (filter a string)'
225 if filter(None, [1, 'hello', [], [3], '', None, 9, 0]) != [1, 'hello', [3], 9]:
226 raise TestFailed, 'filter (remove false values)'
227 if filter(lambda x: x > 0, [1, -3, 9, 0, 2]) != [1, 9, 2]:
228 raise TestFailed, 'filter (keep positives)'
229 class Squares:
230 def __init__(self, max):
231 self.max = max
232 self.sofar = []
233 def __len__(self): return len(self.sofar)
234 def __getitem__(self, i):
235 if not 0 <= i < self.max: raise IndexError
236 n = len(self.sofar)
237 while n <= i:
238 self.sofar.append(n*n)
239 n = n+1
240 return self.sofar[i]
241 if filter(None, Squares(10)) != [1, 4, 9, 16, 25, 36, 49, 64, 81]:
242 raise TestFailed, 'filter(None, Squares(10))'
243 if filter(lambda x: x%2, Squares(10)) != [1, 9, 25, 49, 81]:
244 raise TestFailed, 'filter(oddp, Squares(10))'
245 class StrSquares:
246 def __init__(self, max):
247 self.max = max
248 self.sofar = []
249 def __len__(self):
250 return len(self.sofar)
251 def __getitem__(self, i):
252 if not 0 <= i < self.max:
253 raise IndexError
254 n = len(self.sofar)
255 while n <= i:
256 self.sofar.append(str(n*n))
257 n = n+1
258 return self.sofar[i]
259 def identity(item):
260 return 1
261 filter(identity, Squares(5))
263 print 'float'
264 if float(3.14) != 3.14: raise TestFailed, 'float(3.14)'
265 if float(314) != 314.0: raise TestFailed, 'float(314)'
266 if float(314L) != 314.0: raise TestFailed, 'float(314L)'
267 if float(" 3.14 ") != 3.14: raise TestFailed, 'float(" 3.14 ")'
268 if have_unicode:
269 if float(unicode(" 3.14 ")) != 3.14:
270 raise TestFailed, 'float(u" 3.14 ")'
271 if float(unicode(" \u0663.\u0661\u0664 ",'raw-unicode-escape')) != 3.14:
272 raise TestFailed, 'float(u" \u0663.\u0661\u0664 ")'
274 print 'getattr'
275 import sys
276 if getattr(sys, 'stdout') is not sys.stdout: raise TestFailed, 'getattr'
277 try:
278 getattr(sys, 1)
279 except TypeError:
280 pass
281 else:
282 raise TestFailed, "getattr(sys, 1) should raise an exception"
283 try:
284 getattr(sys, 1, "foo")
285 except TypeError:
286 pass
287 else:
288 raise TestFailed, 'getattr(sys, 1, "foo") should raise an exception'
290 print 'hasattr'
291 import sys
292 if not hasattr(sys, 'stdout'): raise TestFailed, 'hasattr'
293 try:
294 hasattr(sys, 1)
295 except TypeError:
296 pass
297 else:
298 raise TestFailed, "hasattr(sys, 1) should raise an exception"
300 print 'hash'
301 hash(None)
302 if not hash(1) == hash(1L) == hash(1.0): raise TestFailed, 'numeric hash()'
303 hash('spam')
304 hash((0,1,2,3))
305 def f(): pass
306 try: hash([])
307 except TypeError: pass
308 else: raise TestFailed, "hash([]) should raise an exception"
309 try: hash({})
310 except TypeError: pass
311 else: raise TestFailed, "hash({}) should raise an exception"
313 print 'hex'
314 if hex(16) != '0x10': raise TestFailed, 'hex(16)'
315 if hex(16L) != '0x10L': raise TestFailed, 'hex(16L)'
316 if len(hex(-1)) != len(hex(sys.maxint)): raise TestFailed, 'len(hex(-1))'
317 if hex(-16) not in ('0xfffffff0', '0xfffffffffffffff0'):
318 raise TestFailed, 'hex(-16)'
319 if hex(-16L) != '-0x10L': raise TestFailed, 'hex(-16L)'
321 print 'id'
322 id(None)
323 id(1)
324 id(1L)
325 id(1.0)
326 id('spam')
327 id((0,1,2,3))
328 id([0,1,2,3])
329 id({'spam': 1, 'eggs': 2, 'ham': 3})
331 # Test input() later, together with raw_input
333 print 'int'
334 if int(314) != 314: raise TestFailed, 'int(314)'
335 if int(3.14) != 3: raise TestFailed, 'int(3.14)'
336 if int(314L) != 314: raise TestFailed, 'int(314L)'
337 # Check that conversion from float truncates towards zero
338 if int(-3.14) != -3: raise TestFailed, 'int(-3.14)'
339 if int(3.9) != 3: raise TestFailed, 'int(3.9)'
340 if int(-3.9) != -3: raise TestFailed, 'int(-3.9)'
341 if int(3.5) != 3: raise TestFailed, 'int(3.5)'
342 if int(-3.5) != -3: raise TestFailed, 'int(-3.5)'
343 # Different base:
344 if int("10",16) != 16L: raise TestFailed, 'int("10",16)'
345 if have_unicode:
346 if int(unicode("10"),16) != 16L:
347 raise TestFailed, 'int(u"10",16)'
348 # Test conversion from strings and various anomalies
349 L = [
350 ('0', 0),
351 ('1', 1),
352 ('9', 9),
353 ('10', 10),
354 ('99', 99),
355 ('100', 100),
356 ('314', 314),
357 (' 314', 314),
358 ('314 ', 314),
359 (' \t\t 314 \t\t ', 314),
360 (`sys.maxint`, sys.maxint),
361 (' 1x', ValueError),
362 (' 1 ', 1),
363 (' 1\02 ', ValueError),
364 ('', ValueError),
365 (' ', ValueError),
366 (' \t\t ', ValueError)
368 if have_unicode:
369 L += [
370 (unicode('0'), 0),
371 (unicode('1'), 1),
372 (unicode('9'), 9),
373 (unicode('10'), 10),
374 (unicode('99'), 99),
375 (unicode('100'), 100),
376 (unicode('314'), 314),
377 (unicode(' 314'), 314),
378 (unicode('\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
379 (unicode(' \t\t 314 \t\t '), 314),
380 (unicode(' 1x'), ValueError),
381 (unicode(' 1 '), 1),
382 (unicode(' 1\02 '), ValueError),
383 (unicode(''), ValueError),
384 (unicode(' '), ValueError),
385 (unicode(' \t\t '), ValueError),
387 for s, v in L:
388 for sign in "", "+", "-":
389 for prefix in "", " ", "\t", " \t\t ":
390 ss = prefix + sign + s
391 vv = v
392 if sign == "-" and v is not ValueError:
393 vv = -v
394 try:
395 if int(ss) != vv:
396 raise TestFailed, "int(%s)" % `ss`
397 except v:
398 pass
399 except ValueError, e:
400 raise TestFailed, "int(%s) raised ValueError: %s" % (`ss`, e)
401 s = `-1-sys.maxint`
402 if int(s)+1 != -sys.maxint:
403 raise TestFailed, "int(%s)" % `s`
404 try:
405 int(s[1:])
406 except ValueError:
407 pass
408 else:
409 raise TestFailed, "int(%s)" % `s[1:]` + " should raise ValueError"
410 try:
411 int(1e100)
412 except OverflowError:
413 pass
414 else:
415 raise TestFailed("int(1e100) expected OverflowError")
416 try:
417 int(-1e100)
418 except OverflowError:
419 pass
420 else:
421 raise TestFailed("int(-1e100) expected OverflowError")
424 # SF bug 434186: 0x80000000/2 != 0x80000000>>1.
425 # Worked by accident in Windows release build, but failed in debug build.
426 # Failed in all Linux builds.
427 x = -1-sys.maxint
428 if x >> 1 != x//2:
429 raise TestFailed("x >> 1 != x/2 when x == -1-sys.maxint")
431 try: int('123\0')
432 except ValueError: pass
433 else: raise TestFailed("int('123\0') didn't raise exception")
435 print 'isinstance'
436 class C:
437 pass
438 class D(C):
439 pass
440 class E:
441 pass
442 c = C()
443 d = D()
444 e = E()
445 if not isinstance(c, C): raise TestFailed, 'isinstance(c, C)'
446 if not isinstance(d, C): raise TestFailed, 'isinstance(d, C)'
447 if isinstance(e, C): raise TestFailed, 'isinstance(e, C)'
448 if isinstance(c, D): raise TestFailed, 'isinstance(c, D)'
449 if isinstance('foo', E): raise TestFailed, 'isinstance("Foo", E)'
450 try:
451 isinstance(E, 'foo')
452 raise TestFailed, 'isinstance(E, "foo")'
453 except TypeError:
454 pass
456 print 'issubclass'
457 if not issubclass(D, C): raise TestFailed, 'issubclass(D, C)'
458 if not issubclass(C, C): raise TestFailed, 'issubclass(C, C)'
459 if issubclass(C, D): raise TestFailed, 'issubclass(C, D)'
460 try:
461 issubclass('foo', E)
462 raise TestFailed, 'issubclass("foo", E)'
463 except TypeError:
464 pass
465 try:
466 issubclass(E, 'foo')
467 raise TestFailed, 'issubclass(E, "foo")'
468 except TypeError:
469 pass
471 print 'len'
472 if len('123') != 3: raise TestFailed, 'len(\'123\')'
473 if len(()) != 0: raise TestFailed, 'len(())'
474 if len((1, 2, 3, 4)) != 4: raise TestFailed, 'len((1, 2, 3, 4))'
475 if len([1, 2, 3, 4]) != 4: raise TestFailed, 'len([1, 2, 3, 4])'
476 if len({}) != 0: raise TestFailed, 'len({})'
477 if len({'a':1, 'b': 2}) != 2: raise TestFailed, 'len({\'a\':1, \'b\': 2})'
479 print 'long'
480 if long(314) != 314L: raise TestFailed, 'long(314)'
481 if long(3.14) != 3L: raise TestFailed, 'long(3.14)'
482 if long(314L) != 314L: raise TestFailed, 'long(314L)'
483 # Check that conversion from float truncates towards zero
484 if long(-3.14) != -3L: raise TestFailed, 'long(-3.14)'
485 if long(3.9) != 3L: raise TestFailed, 'long(3.9)'
486 if long(-3.9) != -3L: raise TestFailed, 'long(-3.9)'
487 if long(3.5) != 3L: raise TestFailed, 'long(3.5)'
488 if long(-3.5) != -3L: raise TestFailed, 'long(-3.5)'
489 if long("-3") != -3L: raise TestFailed, 'long("-3")'
490 if have_unicode:
491 if long(unicode("-3")) != -3L:
492 raise TestFailed, 'long(u"-3")'
493 # Different base:
494 if long("10",16) != 16L: raise TestFailed, 'long("10",16)'
495 if have_unicode:
496 if long(unicode("10"),16) != 16L:
497 raise TestFailed, 'long(u"10",16)'
498 # Check conversions from string (same test set as for int(), and then some)
499 LL = [
500 ('1' + '0'*20, 10L**20),
501 ('1' + '0'*100, 10L**100)
503 if have_unicode:
504 L+=[
505 (unicode('1') + unicode('0')*20, 10L**20),
506 (unicode('1') + unicode('0')*100, 10L**100),
508 for s, v in L + LL:
509 for sign in "", "+", "-":
510 for prefix in "", " ", "\t", " \t\t ":
511 ss = prefix + sign + s
512 vv = v
513 if sign == "-" and v is not ValueError:
514 vv = -v
515 try:
516 if long(ss) != long(vv):
517 raise TestFailed, "long(%s)" % `ss`
518 except v:
519 pass
520 except ValueError, e:
521 raise TestFailed, "long(%s) raised ValueError: %s" % (`ss`, e)
523 try: long('123\0')
524 except ValueError: pass
525 else: raise TestFailed("long('123\0') didn't raise exception")
527 print 'map'
528 if map(None, 'hello world') != ['h','e','l','l','o',' ','w','o','r','l','d']:
529 raise TestFailed, 'map(None, \'hello world\')'
530 if map(None, 'abcd', 'efg') != \
531 [('a', 'e'), ('b', 'f'), ('c', 'g'), ('d', None)]:
532 raise TestFailed, 'map(None, \'abcd\', \'efg\')'
533 if map(None, range(10)) != [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
534 raise TestFailed, 'map(None, range(10))'
535 if map(lambda x: x*x, range(1,4)) != [1, 4, 9]:
536 raise TestFailed, 'map(lambda x: x*x, range(1,4))'
537 try:
538 from math import sqrt
539 except ImportError:
540 def sqrt(x):
541 return pow(x, 0.5)
542 if map(lambda x: map(sqrt,x), [[16, 4], [81, 9]]) != [[4.0, 2.0], [9.0, 3.0]]:
543 raise TestFailed, 'map(lambda x: map(sqrt,x), [[16, 4], [81, 9]])'
544 if map(lambda x, y: x+y, [1,3,2], [9,1,4]) != [10, 4, 6]:
545 raise TestFailed, 'map(lambda x,y: x+y, [1,3,2], [9,1,4])'
546 def plus(*v):
547 accu = 0
548 for i in v: accu = accu + i
549 return accu
550 if map(plus, [1, 3, 7]) != [1, 3, 7]:
551 raise TestFailed, 'map(plus, [1, 3, 7])'
552 if map(plus, [1, 3, 7], [4, 9, 2]) != [1+4, 3+9, 7+2]:
553 raise TestFailed, 'map(plus, [1, 3, 7], [4, 9, 2])'
554 if map(plus, [1, 3, 7], [4, 9, 2], [1, 1, 0]) != [1+4+1, 3+9+1, 7+2+0]:
555 raise TestFailed, 'map(plus, [1, 3, 7], [4, 9, 2], [1, 1, 0])'
556 if map(None, Squares(10)) != [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]:
557 raise TestFailed, 'map(None, Squares(10))'
558 if map(int, Squares(10)) != [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]:
559 raise TestFailed, 'map(int, Squares(10))'
560 if map(None, Squares(3), Squares(2)) != [(0,0), (1,1), (4,None)]:
561 raise TestFailed, 'map(None, Squares(3), Squares(2))'
562 if map(max, Squares(3), Squares(2)) != [0, 1, 4]:
563 raise TestFailed, 'map(max, Squares(3), Squares(2))'
565 print 'max'
566 if max('123123') != '3': raise TestFailed, 'max(\'123123\')'
567 if max(1, 2, 3) != 3: raise TestFailed, 'max(1, 2, 3)'
568 if max((1, 2, 3, 1, 2, 3)) != 3: raise TestFailed, 'max((1, 2, 3, 1, 2, 3))'
569 if max([1, 2, 3, 1, 2, 3]) != 3: raise TestFailed, 'max([1, 2, 3, 1, 2, 3])'
571 if max(1, 2L, 3.0) != 3.0: raise TestFailed, 'max(1, 2L, 3.0)'
572 if max(1L, 2.0, 3) != 3: raise TestFailed, 'max(1L, 2.0, 3)'
573 if max(1.0, 2, 3L) != 3L: raise TestFailed, 'max(1.0, 2, 3L)'
575 print 'min'
576 if min('123123') != '1': raise TestFailed, 'min(\'123123\')'
577 if min(1, 2, 3) != 1: raise TestFailed, 'min(1, 2, 3)'
578 if min((1, 2, 3, 1, 2, 3)) != 1: raise TestFailed, 'min((1, 2, 3, 1, 2, 3))'
579 if min([1, 2, 3, 1, 2, 3]) != 1: raise TestFailed, 'min([1, 2, 3, 1, 2, 3])'
581 if min(1, 2L, 3.0) != 1: raise TestFailed, 'min(1, 2L, 3.0)'
582 if min(1L, 2.0, 3) != 1L: raise TestFailed, 'min(1L, 2.0, 3)'
583 if min(1.0, 2, 3L) != 1.0: raise TestFailed, 'min(1.0, 2, 3L)'