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