home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / !!!python!!! / BeOpen-Python-2.0.exe / TEST_B1.PY < prev    next >
Encoding:
Python Source  |  2000-09-28  |  17.4 KB  |  489 lines

  1. # Python test set -- part 4a, built-in functions a-m
  2.  
  3. from test_support import *
  4.  
  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"
  12.  
  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)'
  17. #
  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)'
  21. #
  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)'
  25.  
  26. print 'apply'
  27. def f0(*args):
  28.     if args != (): raise TestFailed, 'f0 called with ' + `args`
  29. def f1(a1):
  30.     if a1 != 1: raise TestFailed, 'f1 called with ' + `a1`
  31. def f2(a1, a2):
  32.     if a1 != 1 or a2 != 2:
  33.         raise TestFailed, 'f2 called with ' + `a1, a2`
  34. def f3(a1, a2, a3):
  35.     if a1 != 1 or a2 != 2 or a3 != 3:
  36.         raise TestFailed, 'f3 called with ' + `a1, a2, a3`
  37. apply(f0, ())
  38. apply(f1, (1,))
  39. apply(f2, (1, 2))
  40. apply(f3, (1, 2, 3))
  41.  
  42. print 'callable'
  43. if not callable(len):raise TestFailed, 'callable(len)'
  44. def f(): pass
  45. if not callable(f): raise TestFailed, 'callable(f)'
  46. class C:
  47.     def meth(self): pass
  48. if not callable(C): raise TestFailed, 'callable(C)'
  49. x = C()
  50. if not callable(x.meth): raise TestFailed, 'callable(x.meth)'
  51. if callable(x): raise TestFailed, 'callable(x)'
  52. class D(C):
  53.     def __call__(self): pass
  54. y = D()
  55. if not callable(y): raise TestFailed, 'callable(y)'
  56.  
  57. print 'chr'
  58. if chr(32) <> ' ': raise TestFailed, 'chr(32)'
  59. if chr(65) <> 'A': raise TestFailed, 'chr(65)'
  60. if chr(97) <> 'a': raise TestFailed, 'chr(97)'
  61.  
  62. print 'cmp'
  63. if cmp(-1, 1) <> -1: raise TestFailed, 'cmp(-1, 1)'
  64. if cmp(1, -1) <> 1: raise TestFailed, 'cmp(1, -1)'
  65. if cmp(1, 1) <> 0: raise TestFailed, 'cmp(1, 1)'
  66. # verify that circular objects are handled
  67. a = []; a.append(a)
  68. b = []; b.append(b)
  69. from UserList import UserList
  70. c = UserList(); c.append(c)
  71. if cmp(a, b) != 0: raise TestFailed, "cmp(%s, %s)" % (a, b)
  72. if cmp(b, c) != 0: raise TestFailed, "cmp(%s, %s)" % (b, c)
  73. if cmp(c, a) != 0: raise TestFailed, "cmp(%s, %s)" % (c, a)
  74. if cmp(a, c) != 0: raise TestFailed, "cmp(%s, %s)" % (a, c)
  75. # okay, now break the cycles
  76. a.pop(); b.pop(); c.pop()
  77.  
  78. print 'coerce'
  79. if fcmp(coerce(1, 1.1), (1.0, 1.1)): raise TestFailed, 'coerce(1, 1.1)'
  80. if coerce(1, 1L) <> (1L, 1L): raise TestFailed, 'coerce(1, 1L)'
  81. if fcmp(coerce(1L, 1.1), (1.0, 1.1)): raise TestFailed, 'coerce(1L, 1.1)'
  82.  
  83. print 'compile'
  84. compile('print 1\n', '', 'exec')
  85.  
  86. print 'complex'
  87. if complex(1,10) <> 1+10j: raise TestFailed, 'complex(1,10)'
  88. if complex(1,10L) <> 1+10j: raise TestFailed, 'complex(1,10L)'
  89. if complex(1,10.0) <> 1+10j: raise TestFailed, 'complex(1,10.0)'
  90. if complex(1L,10) <> 1+10j: raise TestFailed, 'complex(1L,10)'
  91. if complex(1L,10L) <> 1+10j: raise TestFailed, 'complex(1L,10L)'
  92. if complex(1L,10.0) <> 1+10j: raise TestFailed, 'complex(1L,10.0)'
  93. if complex(1.0,10) <> 1+10j: raise TestFailed, 'complex(1.0,10)'
  94. if complex(1.0,10L) <> 1+10j: raise TestFailed, 'complex(1.0,10L)'
  95. if complex(1.0,10.0) <> 1+10j: raise TestFailed, 'complex(1.0,10.0)'
  96. if complex(3.14+0j) <> 3.14+0j: raise TestFailed, 'complex(3.14)'
  97. if complex(3.14) <> 3.14+0j: raise TestFailed, 'complex(3.14)'
  98. if complex(314) <> 314.0+0j: raise TestFailed, 'complex(314)'
  99. if complex(314L) <> 314.0+0j: raise TestFailed, 'complex(314L)'
  100. if complex(3.14+0j, 0j) <> 3.14+0j: raise TestFailed, 'complex(3.14, 0j)'
  101. if complex(3.14, 0.0) <> 3.14+0j: raise TestFailed, 'complex(3.14, 0.0)'
  102. if complex(314, 0) <> 314.0+0j: raise TestFailed, 'complex(314, 0)'
  103. if complex(314L, 0L) <> 314.0+0j: raise TestFailed, 'complex(314L, 0L)'
  104. if complex(0j, 3.14j) <> -3.14+0j: raise TestFailed, 'complex(0j, 3.14j)'
  105. if complex(0.0, 3.14j) <> -3.14+0j: raise TestFailed, 'complex(0.0, 3.14j)'
  106. if complex(0j, 3.14) <> 3.14j: raise TestFailed, 'complex(0j, 3.14)'
  107. if complex(0.0, 3.14) <> 3.14j: raise TestFailed, 'complex(0.0, 3.14)'
  108. if complex("  3.14+J  ") <> 3.14+1j:  raise TestFailed, 'complex("  3.14+J  )"'
  109. if complex(u"  3.14+J  ") <> 3.14+1j:  raise TestFailed, 'complex(u"  3.14+J  )"'
  110. class Z:
  111.     def __complex__(self): return 3.14j
  112. z = Z()
  113. if complex(z) <> 3.14j: raise TestFailed, 'complex(classinstance)'
  114.  
  115. print 'delattr'
  116. import sys
  117. sys.spam = 1
  118. delattr(sys, 'spam')
  119.  
  120. print 'dir'
  121. x = 1
  122. if 'x' not in dir(): raise TestFailed, 'dir()'
  123. import sys
  124. if 'modules' not in dir(sys): raise TestFailed, 'dir(sys)'
  125.  
  126. print 'divmod'
  127. if divmod(12, 7) <> (1, 5): raise TestFailed, 'divmod(12, 7)'
  128. if divmod(-12, 7) <> (-2, 2): raise TestFailed, 'divmod(-12, 7)'
  129. if divmod(12, -7) <> (-2, -2): raise TestFailed, 'divmod(12, -7)'
  130. if divmod(-12, -7) <> (1, -5): raise TestFailed, 'divmod(-12, -7)'
  131. #
  132. if divmod(12L, 7L) <> (1L, 5L): raise TestFailed, 'divmod(12L, 7L)'
  133. if divmod(-12L, 7L) <> (-2L, 2L): raise TestFailed, 'divmod(-12L, 7L)'
  134. if divmod(12L, -7L) <> (-2L, -2L): raise TestFailed, 'divmod(12L, -7L)'
  135. if divmod(-12L, -7L) <> (1L, -5L): raise TestFailed, 'divmod(-12L, -7L)'
  136. #
  137. if divmod(12, 7L) <> (1, 5L): raise TestFailed, 'divmod(12, 7L)'
  138. if divmod(-12, 7L) <> (-2, 2L): raise TestFailed, 'divmod(-12, 7L)'
  139. if divmod(12L, -7) <> (-2L, -2): raise TestFailed, 'divmod(12L, -7)'
  140. if divmod(-12L, -7) <> (1L, -5): raise TestFailed, 'divmod(-12L, -7)'
  141. #
  142. if fcmp(divmod(3.25, 1.0), (3.0, 0.25)):
  143.     raise TestFailed, 'divmod(3.25, 1.0)'
  144. if fcmp(divmod(-3.25, 1.0), (-4.0, 0.75)):
  145.     raise TestFailed, 'divmod(-3.25, 1.0)'
  146. if fcmp(divmod(3.25, -1.0), (-4.0, -0.75)):
  147.     raise TestFailed, 'divmod(3.25, -1.0)'
  148. if fcmp(divmod(-3.25, -1.0), (3.0, -0.25)):
  149.     raise TestFailed, 'divmod(-3.25, -1.0)'
  150.  
  151. print 'eval'
  152. if eval('1+1') <> 2: raise TestFailed, 'eval(\'1+1\')'
  153. if eval(' 1+1\n') <> 2: raise TestFailed, 'eval(\' 1+1\\n\')'
  154. globals = {'a': 1, 'b': 2}
  155. locals = {'b': 200, 'c': 300}
  156. if eval('a', globals) <> 1:
  157.     raise TestFailed, "eval(1) == %s" % eval('a', globals)
  158. if eval('a', globals, locals) <> 1:
  159.     raise TestFailed, "eval(2)"
  160. if eval('b', globals, locals) <> 200:
  161.     raise TestFailed, "eval(3)"
  162. if eval('c', globals, locals) <> 300:
  163.     raise TestFailed, "eval(4)"
  164. if eval(u'1+1') <> 2: raise TestFailed, 'eval(u\'1+1\')'
  165. if eval(u' 1+1\n') <> 2: raise TestFailed, 'eval(u\' 1+1\\n\')'
  166. globals = {'a': 1, 'b': 2}
  167. locals = {'b': 200, 'c': 300}
  168. if eval(u'a', globals) <> 1:
  169.     raise TestFailed, "eval(1) == %s" % eval(u'a', globals)
  170. if eval(u'a', globals, locals) <> 1:
  171.     raise TestFailed, "eval(2)"
  172. if eval(u'b', globals, locals) <> 200:
  173.     raise TestFailed, "eval(3)"
  174. if eval(u'c', globals, locals) <> 300:
  175.     raise TestFailed, "eval(4)"
  176.  
  177. print 'execfile'
  178. z = 0
  179. f = open(TESTFN, 'w')
  180. f.write('z = z+1\n')
  181. f.write('z = z*2\n')
  182. f.close()
  183. execfile(TESTFN)
  184. if z <> 2: raise TestFailed, "execfile(1)"
  185. globals['z'] = 0
  186. execfile(TESTFN, globals)
  187. if globals['z'] <> 2: raise TestFailed, "execfile(1)"
  188. locals['z'] = 0
  189. execfile(TESTFN, globals, locals)
  190. if locals['z'] <> 2: raise TestFailed, "execfile(1)"
  191. unlink(TESTFN)
  192.  
  193. print 'filter'
  194. if filter(lambda c: 'a' <= c <= 'z', 'Hello World') <> 'elloorld':
  195.     raise TestFailed, 'filter (filter a string)'
  196. if filter(None, [1, 'hello', [], [3], '', None, 9, 0]) <> [1, 'hello', [3], 9]:
  197.     raise TestFailed, 'filter (remove false values)'
  198. if filter(lambda x: x > 0, [1, -3, 9, 0, 2]) <> [1, 9, 2]:
  199.     raise TestFailed, 'filter (keep positives)'
  200. class Squares:
  201.     def __init__(self, max):
  202.         self.max = max
  203.         self.sofar = []
  204.     def __len__(self): return len(self.sofar)
  205.     def __getitem__(self, i):
  206.         if not 0 <= i < self.max: raise IndexError
  207.         n = len(self.sofar)
  208.         while n <= i:
  209.             self.sofar.append(n*n)
  210.             n = n+1
  211.         return self.sofar[i]
  212. if filter(None, Squares(10)) != [1, 4, 9, 16, 25, 36, 49, 64, 81]:
  213.     raise TestFailed, 'filter(None, Squares(10))'
  214. if filter(lambda x: x%2, Squares(10)) != [1, 9, 25, 49, 81]:
  215.     raise TestFailed, 'filter(oddp, Squares(10))'
  216. class StrSquares:
  217.     def __init__(self, max):
  218.         self.max = max
  219.         self.sofar = []
  220.     def __len__(self):
  221.         return len(self.sofar)
  222.     def __getitem__(self, i):
  223.         if not 0 <= i < self.max:
  224.             raise IndexError
  225.         n = len(self.sofar)
  226.         while n <= i:
  227.             self.sofar.append(str(n*n))
  228.             n = n+1
  229.         return self.sofar[i]
  230. def identity(item):
  231.     return 1
  232. filter(identity, Squares(5))
  233.  
  234. print 'float'
  235. if float(3.14) <> 3.14: raise TestFailed, 'float(3.14)'
  236. if float(314) <> 314.0: raise TestFailed, 'float(314)'
  237. if float(314L) <> 314.0: raise TestFailed, 'float(314L)'
  238. if float("  3.14  ") <> 3.14:  raise TestFailed, 'float("  3.14  ")'
  239. if float(u"  3.14  ") <> 3.14:  raise TestFailed, 'float(u"  3.14  ")'
  240. if float(u"  \u0663.\u0661\u0664  ") <> 3.14:
  241.     raise TestFailed, 'float(u"  \u0663.\u0661\u0664  ")'
  242.  
  243. print 'getattr'
  244. import sys
  245. if getattr(sys, 'stdout') is not sys.stdout: raise TestFailed, 'getattr'
  246.  
  247. print 'hasattr'
  248. import sys
  249. if not hasattr(sys, 'stdout'): raise TestFailed, 'hasattr'
  250.  
  251. print 'hash'
  252. hash(None)
  253. if not hash(1) == hash(1L) == hash(1.0): raise TestFailed, 'numeric hash()'
  254. hash('spam')
  255. hash((0,1,2,3))
  256. def f(): pass
  257.  
  258. print 'hex'
  259. if hex(16) != '0x10': raise TestFailed, 'hex(16)'
  260. if hex(16L) != '0x10L': raise TestFailed, 'hex(16L)'
  261. if len(hex(-1)) != len(hex(sys.maxint)): raise TestFailed, 'len(hex(-1))'
  262. if hex(-16) not in ('0xfffffff0', '0xfffffffffffffff0'):
  263.     raise TestFailed, 'hex(-16)'
  264. if hex(-16L) != '-0x10L': raise TestFailed, 'hex(-16L)'
  265.  
  266. print 'id'
  267. id(None)
  268. id(1)
  269. id(1L)
  270. id(1.0)
  271. id('spam')
  272. id((0,1,2,3))
  273. id([0,1,2,3])
  274. id({'spam': 1, 'eggs': 2, 'ham': 3})
  275.  
  276. # Test input() later, together with raw_input
  277.  
  278. print 'int'
  279. if int(314) <> 314: raise TestFailed, 'int(314)'
  280. if int(3.14) <> 3: raise TestFailed, 'int(3.14)'
  281. if int(314L) <> 314: raise TestFailed, 'int(314L)'
  282. # Check that conversion from float truncates towards zero
  283. if int(-3.14) <> -3: raise TestFailed, 'int(-3.14)'
  284. if int(3.9) <> 3: raise TestFailed, 'int(3.9)'
  285. if int(-3.9) <> -3: raise TestFailed, 'int(-3.9)'
  286. if int(3.5) <> 3: raise TestFailed, 'int(3.5)'
  287. if int(-3.5) <> -3: raise TestFailed, 'int(-3.5)'
  288. # Different base:
  289. if int("10",16) <> 16L: raise TestFailed, 'int("10",16)'
  290. if int(u"10",16) <> 16L: raise TestFailed, 'int(u"10",16)'
  291. # Test conversion from strings and various anomalies
  292. L = [
  293.         ('0', 0),
  294.         ('1', 1),
  295.         ('9', 9),
  296.         ('10', 10),
  297.         ('99', 99),
  298.         ('100', 100),
  299.         ('314', 314),
  300.         (' 314', 314),
  301.         ('314 ', 314),
  302.         ('  \t\t  314  \t\t  ', 314),
  303.         (`sys.maxint`, sys.maxint),
  304.         ('  1x', ValueError),
  305.         ('  1  ', 1),
  306.         ('  1\02  ', ValueError),
  307.         ('', ValueError),
  308.         (' ', ValueError),
  309.         ('  \t\t  ', ValueError),
  310.         (u'0', 0),
  311.         (u'1', 1),
  312.         (u'9', 9),
  313.         (u'10', 10),
  314.         (u'99', 99),
  315.         (u'100', 100),
  316.         (u'314', 314),
  317.         (u' 314', 314),
  318.         (u'\u0663\u0661\u0664 ', 314),
  319.         (u'  \t\t  314  \t\t  ', 314),
  320.         (u'  1x', ValueError),
  321.         (u'  1  ', 1),
  322.         (u'  1\02  ', ValueError),
  323.         (u'', ValueError),
  324.         (u' ', ValueError),
  325.         (u'  \t\t  ', ValueError),
  326. ]
  327. for s, v in L:
  328.     for sign in "", "+", "-":
  329.         for prefix in "", " ", "\t", "  \t\t  ":
  330.             ss = prefix + sign + s
  331.             vv = v
  332.             if sign == "-" and v is not ValueError:
  333.                 vv = -v
  334.             try:
  335.                 if int(ss) != vv:
  336.                     raise TestFailed, "int(%s)" % `ss`
  337.             except v:
  338.                 pass
  339.             except ValueError, e:
  340.                 raise TestFailed, "int(%s) raised ValueError: %s" % (`ss`, e)
  341. s = `-1-sys.maxint`
  342. if int(s)+1 != -sys.maxint:
  343.     raise TestFailed, "int(%s)" % `s`
  344. try:
  345.     int(s[1:])
  346. except ValueError:
  347.     pass
  348. else:
  349.     raise TestFailed, "int(%s)" % `s[1:]` + " should raise ValueError"
  350.  
  351. print 'isinstance'
  352. class C:
  353.     pass
  354. class D(C):
  355.     pass
  356. class E:
  357.     pass
  358. c = C()
  359. d = D()
  360. e = E()
  361. if not isinstance(c, C): raise TestFailed, 'isinstance(c, C)'
  362. if not isinstance(d, C): raise TestFailed, 'isinstance(d, C)'
  363. if isinstance(e, C): raise TestFailed, 'isinstance(e, C)'
  364. if isinstance(c, D): raise TestFailed, 'isinstance(c, D)'
  365. if isinstance('foo', E): raise TestFailed, 'isinstance("Foo", E)'
  366. try:
  367.     isinstance(E, 'foo')
  368.     raise TestFailed, 'isinstance(E, "foo")'
  369. except TypeError:
  370.     pass
  371.  
  372. print 'issubclass'
  373. if not issubclass(D, C): raise TestFailed, 'issubclass(D, C)'
  374. if not issubclass(C, C): raise TestFailed, 'issubclass(C, C)'
  375. if issubclass(C, D): raise TestFailed, 'issubclass(C, D)'
  376. try:
  377.     issubclass('foo', E)
  378.     raise TestFailed, 'issubclass("foo", E)'
  379. except TypeError:
  380.     pass
  381. try:
  382.     issubclass(E, 'foo')
  383.     raise TestFailed, 'issubclass(E, "foo")'
  384. except TypeError:
  385.     pass
  386.  
  387. print 'len'
  388. if len('123') <> 3: raise TestFailed, 'len(\'123\')'
  389. if len(()) <> 0: raise TestFailed, 'len(())'
  390. if len((1, 2, 3, 4)) <> 4: raise TestFailed, 'len((1, 2, 3, 4))'
  391. if len([1, 2, 3, 4]) <> 4: raise TestFailed, 'len([1, 2, 3, 4])'
  392. if len({}) <> 0: raise TestFailed, 'len({})'
  393. if len({'a':1, 'b': 2}) <> 2: raise TestFailed, 'len({\'a\':1, \'b\': 2})'
  394.  
  395. print 'long'
  396. if long(314) <> 314L: raise TestFailed, 'long(314)'
  397. if long(3.14) <> 3L: raise TestFailed, 'long(3.14)'
  398. if long(314L) <> 314L: raise TestFailed, 'long(314L)'
  399. # Check that conversion from float truncates towards zero
  400. if long(-3.14) <> -3L: raise TestFailed, 'long(-3.14)'
  401. if long(3.9) <> 3L: raise TestFailed, 'long(3.9)'
  402. if long(-3.9) <> -3L: raise TestFailed, 'long(-3.9)'
  403. if long(3.5) <> 3L: raise TestFailed, 'long(3.5)'
  404. if long(-3.5) <> -3L: raise TestFailed, 'long(-3.5)'
  405. if long("-3") <> -3L: raise TestFailed, 'long("-3")'
  406. if long(u"-3") <> -3L: raise TestFailed, 'long(u"-3")'
  407. # Different base:
  408. if long("10",16) <> 16L: raise TestFailed, 'long("10",16)'
  409. if long(u"10",16) <> 16L: raise TestFailed, 'long(u"10",16)'
  410. # Check conversions from string (same test set as for int(), and then some)
  411. LL = [
  412.         ('1' + '0'*20, 10L**20),
  413.         ('1' + '0'*100, 10L**100),
  414.         (u'1' + u'0'*20, 10L**20),
  415.         (u'1' + u'0'*100, 10L**100),
  416. ]
  417. for s, v in L + LL:
  418.     for sign in "", "+", "-":
  419.         for prefix in "", " ", "\t", "  \t\t  ":
  420.             ss = prefix + sign + s
  421.             vv = v
  422.             if sign == "-" and v is not ValueError:
  423.                 vv = -v
  424.             try:
  425.                 if long(ss) != long(vv):
  426.                     raise TestFailed, "long(%s)" % `ss`
  427.             except v:
  428.                 pass
  429.             except ValueError, e:
  430.                 raise TestFailed, "long(%s) raised ValueError: %s" % (`ss`, e)
  431.  
  432. print 'map'
  433. if map(None, 'hello world') <> ['h','e','l','l','o',' ','w','o','r','l','d']:
  434.     raise TestFailed, 'map(None, \'hello world\')'
  435. if map(None, 'abcd', 'efg') <> \
  436.    [('a', 'e'), ('b', 'f'), ('c', 'g'), ('d', None)]:
  437.     raise TestFailed, 'map(None, \'abcd\', \'efg\')'
  438. if map(None, range(10)) <> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
  439.     raise TestFailed, 'map(None, range(10))'
  440. if map(lambda x: x*x, range(1,4)) <> [1, 4, 9]:
  441.     raise TestFailed, 'map(lambda x: x*x, range(1,4))'
  442. try:
  443.     from math import sqrt
  444. except ImportError:
  445.     def sqrt(x):
  446.         return pow(x, 0.5)
  447. if map(lambda x: map(sqrt,x), [[16, 4], [81, 9]]) <> [[4.0, 2.0], [9.0, 3.0]]:
  448.     raise TestFailed, 'map(lambda x: map(sqrt,x), [[16, 4], [81, 9]])'
  449. if map(lambda x, y: x+y, [1,3,2], [9,1,4]) <> [10, 4, 6]:
  450.     raise TestFailed, 'map(lambda x,y: x+y, [1,3,2], [9,1,4])'
  451. def plus(*v):
  452.     accu = 0
  453.     for i in v: accu = accu + i
  454.     return accu
  455. if map(plus, [1, 3, 7]) <> [1, 3, 7]:
  456.     raise TestFailed, 'map(plus, [1, 3, 7])'
  457. if map(plus, [1, 3, 7], [4, 9, 2]) <> [1+4, 3+9, 7+2]:
  458.     raise TestFailed, 'map(plus, [1, 3, 7], [4, 9, 2])'
  459. if map(plus, [1, 3, 7], [4, 9, 2], [1, 1, 0]) <> [1+4+1, 3+9+1, 7+2+0]:
  460.     raise TestFailed, 'map(plus, [1, 3, 7], [4, 9, 2], [1, 1, 0])'
  461. if map(None, Squares(10)) != [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]:
  462.     raise TestFailed, 'map(None, Squares(10))'
  463. if map(int, Squares(10)) != [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]:
  464.     raise TestFailed, 'map(int, Squares(10))'
  465. if map(None, Squares(3), Squares(2)) != [(0,0), (1,1), (4,None)]:
  466.     raise TestFailed, 'map(None, Squares(3), Squares(2))'
  467. if map(max, Squares(3), Squares(2)) != [0, 1, None]:
  468.     raise TestFailed, 'map(max, Squares(3), Squares(2))'
  469.  
  470. print 'max'
  471. if max('123123') <> '3': raise TestFailed, 'max(\'123123\')'
  472. if max(1, 2, 3) <> 3: raise TestFailed, 'max(1, 2, 3)'
  473. if max((1, 2, 3, 1, 2, 3)) <> 3: raise TestFailed, 'max((1, 2, 3, 1, 2, 3))'
  474. if max([1, 2, 3, 1, 2, 3]) <> 3: raise TestFailed, 'max([1, 2, 3, 1, 2, 3])'
  475. #
  476. if max(1, 2L, 3.0) <> 3.0: raise TestFailed, 'max(1, 2L, 3.0)'
  477. if max(1L, 2.0, 3) <> 3: raise TestFailed, 'max(1L, 2.0, 3)'
  478. if max(1.0, 2, 3L) <> 3L: raise TestFailed, 'max(1.0, 2, 3L)'
  479.  
  480. print 'min'
  481. if min('123123') <> '1': raise TestFailed, 'min(\'123123\')'
  482. if min(1, 2, 3) <> 1: raise TestFailed, 'min(1, 2, 3)'
  483. if min((1, 2, 3, 1, 2, 3)) <> 1: raise TestFailed, 'min((1, 2, 3, 1, 2, 3))'
  484. if min([1, 2, 3, 1, 2, 3]) <> 1: raise TestFailed, 'min([1, 2, 3, 1, 2, 3])'
  485. #
  486. if min(1, 2L, 3.0) <> 1: raise TestFailed, 'min(1, 2L, 3.0)'
  487. if min(1L, 2.0, 3) <> 1L: raise TestFailed, 'min(1L, 2.0, 3)'
  488. if min(1.0, 2, 3L) <> 1.0: raise TestFailed, 'min(1.0, 2, 3L)'
  489.