Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 1 | # Python test set -- part 6, built-in types |
| 2 | |
| 3 | from test_support import * |
| 4 | |
| 5 | print '6. Built-in types' |
| 6 | |
| 7 | print '6.1 Truth value testing' |
| 8 | if None: raise TestFailed, 'None is true instead of false' |
| 9 | if 0: raise TestFailed, '0 is true instead of false' |
| 10 | if 0L: raise TestFailed, '0L is true instead of false' |
| 11 | if 0.0: raise TestFailed, '0.0 is true instead of false' |
| 12 | if '': raise TestFailed, '\'\' is true instead of false' |
| 13 | if (): raise TestFailed, '() is true instead of false' |
| 14 | if []: raise TestFailed, '[] is true instead of false' |
| 15 | if {}: raise TestFailed, '{} is true instead of false' |
| 16 | if not 1: raise TestFailed, '1 is false instead of true' |
| 17 | if not 1L: raise TestFailed, '1L is false instead of true' |
| 18 | if not 1.0: raise TestFailed, '1.0 is false instead of true' |
| 19 | if not 'x': raise TestFailed, '\'x\' is false instead of true' |
| 20 | if not (1, 1): raise TestFailed, '(1, 1) is false instead of true' |
| 21 | if not [1]: raise TestFailed, '[1] is false instead of true' |
| 22 | if not {'x': 1}: raise TestFailed, '{\'x\': 1} is false instead of true' |
| 23 | def f(): pass |
Guido van Rossum | d316607 | 1993-05-24 14:16:22 +0000 | [diff] [blame] | 24 | class C: pass |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 25 | import sys |
| 26 | x = C() |
| 27 | if not f: raise TestFailed, 'f is false instead of true' |
| 28 | if not C: raise TestFailed, 'C is false instead of true' |
| 29 | if not sys: raise TestFailed, 'sys is false instead of true' |
| 30 | if not x: raise TestFailed, 'x is false instead of true' |
| 31 | |
| 32 | print '6.2 Boolean operations' |
| 33 | if 0 or 0: raise TestFailed, '0 or 0 is true instead of false' |
| 34 | if 1 and 1: pass |
| 35 | else: raise TestFailed, '1 and 1 is false instead of false' |
| 36 | if not 1: raise TestFailed, 'not 1 is true instead of false' |
| 37 | |
| 38 | print '6.3 Comparisons' |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 39 | if 0 < 1 <= 1 == 1 >= 1 > 0 != 1: pass |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 40 | else: raise TestFailed, 'int comparisons failed' |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 41 | if 0L < 1L <= 1L == 1L >= 1L > 0L != 1L: pass |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 42 | else: raise TestFailed, 'long int comparisons failed' |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 43 | if 0.0 < 1.0 <= 1.0 == 1.0 >= 1.0 > 0.0 != 1.0: pass |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 44 | else: raise TestFailed, 'float comparisons failed' |
| 45 | if '' < 'a' <= 'a' == 'a' < 'abc' < 'abd' < 'b': pass |
| 46 | else: raise TestFailed, 'string comparisons failed' |
| 47 | if 0 in [0] and 0 not in [1]: pass |
| 48 | else: raise TestFailed, 'membership test failed' |
| 49 | if None is None and [] is not []: pass |
| 50 | else: raise TestFailed, 'identity test failed' |
| 51 | |
Neil Schemenauer | eff7244 | 2002-03-24 01:24:54 +0000 | [diff] [blame] | 52 | try: float('') |
| 53 | except ValueError: pass |
| 54 | else: raise TestFailed, "float('') didn't raise ValueError" |
| 55 | |
| 56 | try: float('5\0') |
| 57 | except ValueError: pass |
| 58 | else: raise TestFailed, "float('5\0') didn't raise ValueError" |
| 59 | |
| 60 | try: 5.0 / 0.0 |
| 61 | except ZeroDivisionError: pass |
| 62 | else: raise TestFailed, "5.0 / 0.0 didn't raise ZeroDivisionError" |
| 63 | |
| 64 | try: 5.0 // 0.0 |
| 65 | except ZeroDivisionError: pass |
| 66 | else: raise TestFailed, "5.0 // 0.0 didn't raise ZeroDivisionError" |
| 67 | |
| 68 | try: 5.0 % 0.0 |
| 69 | except ZeroDivisionError: pass |
| 70 | else: raise TestFailed, "5.0 % 0.0 didn't raise ZeroDivisionError" |
| 71 | |
| 72 | try: 5 / 0L |
| 73 | except ZeroDivisionError: pass |
| 74 | else: raise TestFailed, "5 / 0L didn't raise ZeroDivisionError" |
| 75 | |
| 76 | try: 5 // 0L |
| 77 | except ZeroDivisionError: pass |
| 78 | else: raise TestFailed, "5 // 0L didn't raise ZeroDivisionError" |
| 79 | |
| 80 | try: 5 % 0L |
| 81 | except ZeroDivisionError: pass |
| 82 | else: raise TestFailed, "5 % 0L didn't raise ZeroDivisionError" |
| 83 | |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 84 | print '6.4 Numeric types (mostly conversions)' |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 85 | if 0 != 0L or 0 != 0.0 or 0L != 0.0: raise TestFailed, 'mixed comparisons' |
| 86 | if 1 != 1L or 1 != 1.0 or 1L != 1.0: raise TestFailed, 'mixed comparisons' |
| 87 | if -1 != -1L or -1 != -1.0 or -1L != -1.0: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 88 | raise TestFailed, 'int/long/float value not equal' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 89 | if int(1.9) == 1 == int(1.1) and int(-1.1) == -1 == int(-1.9): pass |
| 90 | else: raise TestFailed, 'int() does not round properly' |
| 91 | if long(1.9) == 1L == long(1.1) and long(-1.1) == -1L == long(-1.9): pass |
| 92 | else: raise TestFailed, 'long() does not round properly' |
| 93 | if float(1) == 1.0 and float(-1) == -1.0 and float(0) == 0.0: pass |
| 94 | else: raise TestFailed, 'float() does not work properly' |
Guido van Rossum | 80530ce | 1993-01-21 15:36:40 +0000 | [diff] [blame] | 95 | print '6.4.1 32-bit integers' |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 96 | if 12 + 24 != 36: raise TestFailed, 'int op' |
| 97 | if 12 + (-24) != -12: raise TestFailed, 'int op' |
| 98 | if (-12) + 24 != 12: raise TestFailed, 'int op' |
| 99 | if (-12) + (-24) != -36: raise TestFailed, 'int op' |
Guido van Rossum | 80530ce | 1993-01-21 15:36:40 +0000 | [diff] [blame] | 100 | if not 12 < 24: raise TestFailed, 'int op' |
| 101 | if not -24 < -12: raise TestFailed, 'int op' |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 102 | # Test for a particular bug in integer multiply |
| 103 | xsize, ysize, zsize = 238, 356, 4 |
| 104 | if not (xsize*ysize*zsize == zsize*xsize*ysize == 338912): |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 105 | raise TestFailed, 'int mul commutativity' |
Tim Peters | a3c01ce | 2001-12-04 23:05:10 +0000 | [diff] [blame] | 106 | # And another. |
| 107 | m = -sys.maxint - 1 |
| 108 | for divisor in 1, 2, 4, 8, 16, 32: |
Tim Peters | 6d30c3e | 2001-12-05 00:30:09 +0000 | [diff] [blame] | 109 | j = m // divisor |
Tim Peters | a3c01ce | 2001-12-04 23:05:10 +0000 | [diff] [blame] | 110 | prod = divisor * j |
| 111 | if prod != m: |
| 112 | raise TestFailed, "%r * %r == %r != %r" % (divisor, j, prod, m) |
| 113 | if type(prod) is not int: |
| 114 | raise TestFailed, ("expected type(prod) to be int, not %r" % |
| 115 | type(prod)) |
| 116 | # Check for expected * overflow to long. |
| 117 | for divisor in 1, 2, 4, 8, 16, 32: |
Tim Peters | 6d30c3e | 2001-12-05 00:30:09 +0000 | [diff] [blame] | 118 | j = m // divisor - 1 |
Tim Peters | a3c01ce | 2001-12-04 23:05:10 +0000 | [diff] [blame] | 119 | prod = divisor * j |
| 120 | if type(prod) is not long: |
| 121 | raise TestFailed, ("expected type(%r) to be long, not %r" % |
| 122 | (prod, type(prod))) |
| 123 | # Check for expected * overflow to long. |
| 124 | m = sys.maxint |
| 125 | for divisor in 1, 2, 4, 8, 16, 32: |
Tim Peters | 6d30c3e | 2001-12-05 00:30:09 +0000 | [diff] [blame] | 126 | j = m // divisor + 1 |
Tim Peters | a3c01ce | 2001-12-04 23:05:10 +0000 | [diff] [blame] | 127 | prod = divisor * j |
| 128 | if type(prod) is not long: |
| 129 | raise TestFailed, ("expected type(%r) to be long, not %r" % |
| 130 | (prod, type(prod))) |
| 131 | |
Guido van Rossum | 80530ce | 1993-01-21 15:36:40 +0000 | [diff] [blame] | 132 | print '6.4.2 Long integers' |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 133 | if 12L + 24L != 36L: raise TestFailed, 'long op' |
| 134 | if 12L + (-24L) != -12L: raise TestFailed, 'long op' |
| 135 | if (-12L) + 24L != 12L: raise TestFailed, 'long op' |
| 136 | if (-12L) + (-24L) != -36L: raise TestFailed, 'long op' |
Guido van Rossum | 80530ce | 1993-01-21 15:36:40 +0000 | [diff] [blame] | 137 | if not 12L < 24L: raise TestFailed, 'long op' |
| 138 | if not -24L < -12L: raise TestFailed, 'long op' |
Guido van Rossum | 7462942 | 1998-05-26 14:51:55 +0000 | [diff] [blame] | 139 | x = sys.maxint |
| 140 | if int(long(x)) != x: raise TestFailed, 'long op' |
| 141 | try: int(long(x)+1L) |
| 142 | except OverflowError: pass |
| 143 | else:raise TestFailed, 'long op' |
| 144 | x = -x |
| 145 | if int(long(x)) != x: raise TestFailed, 'long op' |
| 146 | x = x-1 |
| 147 | if int(long(x)) != x: raise TestFailed, 'long op' |
| 148 | try: int(long(x)-1L) |
| 149 | except OverflowError: pass |
| 150 | else:raise TestFailed, 'long op' |
Neil Schemenauer | eff7244 | 2002-03-24 01:24:54 +0000 | [diff] [blame] | 151 | |
| 152 | try: 5 << -5 |
| 153 | except ValueError: pass |
| 154 | else: raise TestFailed, 'int negative shift <<' |
| 155 | |
| 156 | try: 5L << -5L |
| 157 | except ValueError: pass |
| 158 | else: raise TestFailed, 'long negative shift <<' |
| 159 | |
| 160 | try: 5 >> -5 |
| 161 | except ValueError: pass |
| 162 | else: raise TestFailed, 'int negative shift >>' |
| 163 | |
| 164 | try: 5L >> -5L |
| 165 | except ValueError: pass |
| 166 | else: raise TestFailed, 'long negative shift >>' |
| 167 | |
Guido van Rossum | 80530ce | 1993-01-21 15:36:40 +0000 | [diff] [blame] | 168 | print '6.4.3 Floating point numbers' |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 169 | if 12.0 + 24.0 != 36.0: raise TestFailed, 'float op' |
| 170 | if 12.0 + (-24.0) != -12.0: raise TestFailed, 'float op' |
| 171 | if (-12.0) + 24.0 != 12.0: raise TestFailed, 'float op' |
| 172 | if (-12.0) + (-24.0) != -36.0: raise TestFailed, 'float op' |
Guido van Rossum | 80530ce | 1993-01-21 15:36:40 +0000 | [diff] [blame] | 173 | if not 12.0 < 24.0: raise TestFailed, 'float op' |
| 174 | if not -24.0 < -12.0: raise TestFailed, 'float op' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 175 | |
| 176 | print '6.5 Sequence types' |
| 177 | |
| 178 | print '6.5.1 Strings' |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 179 | if len('') != 0: raise TestFailed, 'len(\'\')' |
| 180 | if len('a') != 1: raise TestFailed, 'len(\'a\')' |
| 181 | if len('abcdef') != 6: raise TestFailed, 'len(\'abcdef\')' |
| 182 | if 'xyz' + 'abcde' != 'xyzabcde': raise TestFailed, 'string concatenation' |
| 183 | if 'xyz'*3 != 'xyzxyzxyz': raise TestFailed, 'string repetition *3' |
| 184 | if 0*'abcde' != '': raise TestFailed, 'string repetition 0*' |
| 185 | if min('abc') != 'a' or max('abc') != 'c': raise TestFailed, 'min/max string' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 186 | if 'a' in 'abc' and 'b' in 'abc' and 'c' in 'abc' and 'd' not in 'abc': pass |
| 187 | else: raise TestFailed, 'in/not in string' |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 188 | x = 'x'*103 |
| 189 | if '%s!'%x != x+'!': raise TestFailed, 'nasty string formatting bug' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 190 | |
Michael W. Hudson | 5efaf7e | 2002-06-11 10:55:12 +0000 | [diff] [blame^] | 191 | #extended slices for strings |
| 192 | a = '0123456789' |
| 193 | vereq(a[::], a) |
| 194 | vereq(a[::2], '02468') |
| 195 | vereq(a[1::2], '13579') |
| 196 | vereq(a[::-1],'9876543210') |
| 197 | vereq(a[::-2], '97531') |
| 198 | vereq(a[3::-2], '31') |
| 199 | vereq(a[-100:100:], a) |
| 200 | vereq(a[100:-100:-1], a[::-1]) |
| 201 | vereq(a[-100L:100L:2L], '02468') |
| 202 | |
| 203 | if have_unicode: |
| 204 | a = unicode('0123456789', 'ascii') |
| 205 | vereq(a[::], a) |
| 206 | vereq(a[::2], unicode('02468', 'ascii')) |
| 207 | vereq(a[1::2], unicode('13579', 'ascii')) |
| 208 | vereq(a[::-1], unicode('9876543210', 'ascii')) |
| 209 | vereq(a[::-2], unicode('97531', 'ascii')) |
| 210 | vereq(a[3::-2], unicode('31', 'ascii')) |
| 211 | vereq(a[-100:100:], a) |
| 212 | vereq(a[100:-100:-1], a[::-1]) |
| 213 | vereq(a[-100L:100L:2L], unicode('02468', 'ascii')) |
| 214 | |
| 215 | |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 216 | print '6.5.2 Tuples' |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 217 | if len(()) != 0: raise TestFailed, 'len(())' |
| 218 | if len((1,)) != 1: raise TestFailed, 'len((1,))' |
| 219 | if len((1,2,3,4,5,6)) != 6: raise TestFailed, 'len((1,2,3,4,5,6))' |
| 220 | if (1,2)+(3,4) != (1,2,3,4): raise TestFailed, 'tuple concatenation' |
| 221 | if (1,2)*3 != (1,2,1,2,1,2): raise TestFailed, 'tuple repetition *3' |
| 222 | if 0*(1,2,3) != (): raise TestFailed, 'tuple repetition 0*' |
| 223 | if min((1,2)) != 1 or max((1,2)) != 2: raise TestFailed, 'min/max tuple' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 224 | if 0 in (0,1,2) and 1 in (0,1,2) and 2 in (0,1,2) and 3 not in (0,1,2): pass |
| 225 | else: raise TestFailed, 'in/not in tuple' |
Neil Schemenauer | eff7244 | 2002-03-24 01:24:54 +0000 | [diff] [blame] | 226 | try: ()[0] |
| 227 | except IndexError: pass |
| 228 | else: raise TestFailed, "tuple index error didn't raise IndexError" |
| 229 | x = () |
| 230 | x += () |
| 231 | if x != (): raise TestFailed, 'tuple inplace add from () to () failed' |
| 232 | x += (1,) |
| 233 | if x != (1,): raise TestFailed, 'tuple resize from () failed' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 234 | |
Michael W. Hudson | 5efaf7e | 2002-06-11 10:55:12 +0000 | [diff] [blame^] | 235 | # extended slicing - subscript only for tuples |
| 236 | a = (0,1,2,3,4) |
| 237 | vereq(a[::], a) |
| 238 | vereq(a[::2], (0,2,4)) |
| 239 | vereq(a[1::2], (1,3)) |
| 240 | vereq(a[::-1], (4,3,2,1,0)) |
| 241 | vereq(a[::-2], (4,2,0)) |
| 242 | vereq(a[3::-2], (3,1)) |
| 243 | vereq(a[-100:100:], a) |
| 244 | vereq(a[100:-100:-1], a[::-1]) |
| 245 | vereq(a[-100L:100L:2L], (0,2,4)) |
| 246 | |
| 247 | |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 248 | print '6.5.3 Lists' |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 249 | if len([]) != 0: raise TestFailed, 'len([])' |
| 250 | if len([1,]) != 1: raise TestFailed, 'len([1,])' |
| 251 | if len([1,2,3,4,5,6]) != 6: raise TestFailed, 'len([1,2,3,4,5,6])' |
| 252 | if [1,2]+[3,4] != [1,2,3,4]: raise TestFailed, 'list concatenation' |
| 253 | if [1,2]*3 != [1,2,1,2,1,2]: raise TestFailed, 'list repetition *3' |
| 254 | if [1,2]*3L != [1,2,1,2,1,2]: raise TestFailed, 'list repetition *3L' |
| 255 | if 0*[1,2,3] != []: raise TestFailed, 'list repetition 0*' |
| 256 | if 0L*[1,2,3] != []: raise TestFailed, 'list repetition 0L*' |
| 257 | if min([1,2]) != 1 or max([1,2]) != 2: raise TestFailed, 'min/max list' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 258 | if 0 in [0,1,2] and 1 in [0,1,2] and 2 in [0,1,2] and 3 not in [0,1,2]: pass |
| 259 | else: raise TestFailed, 'in/not in list' |
Guido van Rossum | affd77f | 1998-07-16 15:29:06 +0000 | [diff] [blame] | 260 | a = [1, 2, 3, 4, 5] |
| 261 | a[:-1] = a |
| 262 | if a != [1, 2, 3, 4, 5, 5]: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 263 | raise TestFailed, "list self-slice-assign (head)" |
Guido van Rossum | affd77f | 1998-07-16 15:29:06 +0000 | [diff] [blame] | 264 | a = [1, 2, 3, 4, 5] |
| 265 | a[1:] = a |
| 266 | if a != [1, 1, 2, 3, 4, 5]: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 267 | raise TestFailed, "list self-slice-assign (tail)" |
Guido van Rossum | affd77f | 1998-07-16 15:29:06 +0000 | [diff] [blame] | 268 | a = [1, 2, 3, 4, 5] |
| 269 | a[1:-1] = a |
| 270 | if a != [1, 1, 2, 3, 4, 5, 5]: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 271 | raise TestFailed, "list self-slice-assign (center)" |
Neil Schemenauer | eff7244 | 2002-03-24 01:24:54 +0000 | [diff] [blame] | 272 | try: [][0] |
| 273 | except IndexError: pass |
| 274 | else: raise TestFailed, "list index error didn't raise IndexError" |
| 275 | try: [][0] = 5 |
| 276 | except IndexError: pass |
| 277 | else: raise TestFailed, "list assignment index error didn't raise IndexError" |
| 278 | try: [].pop() |
| 279 | except IndexError: pass |
| 280 | else: raise TestFailed, "empty list.pop() didn't raise IndexError" |
| 281 | try: [1].pop(5) |
| 282 | except IndexError: pass |
| 283 | else: raise TestFailed, "[1].pop(5) didn't raise IndexError" |
| 284 | try: [][0:1] = 5 |
| 285 | except TypeError: pass |
| 286 | else: raise TestFailed, "bad list slice assignment didn't raise TypeError" |
| 287 | try: [].extend(None) |
| 288 | except TypeError: pass |
| 289 | else: raise TestFailed, "list.extend(None) didn't raise TypeError" |
| 290 | a = [1, 2, 3, 4] |
| 291 | a *= 0 |
| 292 | if a != []: |
| 293 | raise TestFailed, "list inplace repeat" |
Guido van Rossum | affd77f | 1998-07-16 15:29:06 +0000 | [diff] [blame] | 294 | |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 295 | |
| 296 | print '6.5.3a Additional list operations' |
| 297 | a = [0,1,2,3,4] |
Andrew M. Kuchling | 5ebfa2a | 2000-02-23 22:23:17 +0000 | [diff] [blame] | 298 | a[0L] = 1 |
| 299 | a[1L] = 2 |
| 300 | a[2L] = 3 |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 301 | if a != [1,2,3,3,4]: raise TestFailed, 'list item assignment [0L], [1L], [2L]' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 302 | a[0] = 5 |
| 303 | a[1] = 6 |
| 304 | a[2] = 7 |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 305 | if a != [5,6,7,3,4]: raise TestFailed, 'list item assignment [0], [1], [2]' |
Andrew M. Kuchling | 5ebfa2a | 2000-02-23 22:23:17 +0000 | [diff] [blame] | 306 | a[-2L] = 88 |
| 307 | a[-1L] = 99 |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 308 | if a != [5,6,7,88,99]: raise TestFailed, 'list item assignment [-2L], [-1L]' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 309 | a[-2] = 8 |
| 310 | a[-1] = 9 |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 311 | if a != [5,6,7,8,9]: raise TestFailed, 'list item assignment [-2], [-1]' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 312 | a[:2] = [0,4] |
| 313 | a[-3:] = [] |
| 314 | a[1:1] = [1,2,3] |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 315 | if a != [0,1,2,3,4]: raise TestFailed, 'list slice assignment' |
Andrew M. Kuchling | 5ebfa2a | 2000-02-23 22:23:17 +0000 | [diff] [blame] | 316 | a[ 1L : 4L] = [7,8,9] |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 317 | if a != [0,7,8,9,4]: raise TestFailed, 'list slice assignment using long ints' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 318 | del a[1:4] |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 319 | if a != [0,4]: raise TestFailed, 'list slice deletion' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 320 | del a[0] |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 321 | if a != [4]: raise TestFailed, 'list item deletion [0]' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 322 | del a[-1] |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 323 | if a != []: raise TestFailed, 'list item deletion [-1]' |
Andrew M. Kuchling | 5ebfa2a | 2000-02-23 22:23:17 +0000 | [diff] [blame] | 324 | a=range(0,5) |
| 325 | del a[1L:4L] |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 326 | if a != [0,4]: raise TestFailed, 'list slice deletion' |
Andrew M. Kuchling | 5ebfa2a | 2000-02-23 22:23:17 +0000 | [diff] [blame] | 327 | del a[0L] |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 328 | if a != [4]: raise TestFailed, 'list item deletion [0]' |
Andrew M. Kuchling | 5ebfa2a | 2000-02-23 22:23:17 +0000 | [diff] [blame] | 329 | del a[-1L] |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 330 | if a != []: raise TestFailed, 'list item deletion [-1]' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 331 | a.append(0) |
| 332 | a.append(1) |
| 333 | a.append(2) |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 334 | if a != [0,1,2]: raise TestFailed, 'list append' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 335 | a.insert(0, -2) |
| 336 | a.insert(1, -1) |
| 337 | a.insert(2,0) |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 338 | if a != [-2,-1,0,0,1,2]: raise TestFailed, 'list insert' |
| 339 | if a.count(0) != 2: raise TestFailed, ' list count' |
| 340 | if a.index(0) != 2: raise TestFailed, 'list index' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 341 | a.remove(0) |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 342 | if a != [-2,-1,0,1,2]: raise TestFailed, 'list remove' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 343 | a.reverse() |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 344 | if a != [2,1,0,-1,-2]: raise TestFailed, 'list reverse' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 345 | a.sort() |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 346 | if a != [-2,-1,0,1,2]: raise TestFailed, 'list sort' |
Guido van Rossum | e61fa0a | 1993-10-22 13:56:35 +0000 | [diff] [blame] | 347 | def revcmp(a, b): return cmp(b, a) |
| 348 | a.sort(revcmp) |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 349 | if a != [2,1,0,-1,-2]: raise TestFailed, 'list sort with cmp func' |
Guido van Rossum | d151d34 | 1998-02-25 17:51:50 +0000 | [diff] [blame] | 350 | # The following dumps core in unpatched Python 1.5: |
| 351 | def myComparison(x,y): |
| 352 | return cmp(x%3, y%7) |
| 353 | z = range(12) |
| 354 | z.sort(myComparison) |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 355 | |
Andrew M. Kuchling | 5ebfa2a | 2000-02-23 22:23:17 +0000 | [diff] [blame] | 356 | # Test extreme cases with long ints |
| 357 | a = [0,1,2,3,4] |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 358 | if a[ -pow(2,128L): 3 ] != [0,1,2]: |
| 359 | raise TestFailed, "list slicing with too-small long integer" |
| 360 | if a[ 3: pow(2,145L) ] != [3,4]: |
| 361 | raise TestFailed, "list slicing with too-large long integer" |
Andrew M. Kuchling | 5ebfa2a | 2000-02-23 22:23:17 +0000 | [diff] [blame] | 362 | |
Michael W. Hudson | 5efaf7e | 2002-06-11 10:55:12 +0000 | [diff] [blame^] | 363 | |
| 364 | # extended slicing |
| 365 | |
| 366 | # subscript |
| 367 | a = [0,1,2,3,4] |
| 368 | vereq(a[::], a) |
| 369 | vereq(a[::2], [0,2,4]) |
| 370 | vereq(a[1::2], [1,3]) |
| 371 | vereq(a[::-1], [4,3,2,1,0]) |
| 372 | vereq(a[::-2], [4,2,0]) |
| 373 | vereq(a[3::-2], [3,1]) |
| 374 | vereq(a[-100:100:], a) |
| 375 | vereq(a[100:-100:-1], a[::-1]) |
| 376 | vereq(a[-100L:100L:2L], [0,2,4]) |
| 377 | # deletion |
| 378 | del a[::2] |
| 379 | vereq(a, [1,3]) |
| 380 | a = range(5) |
| 381 | del a[1::2] |
| 382 | vereq(a, [0,2,4]) |
| 383 | a = range(5) |
| 384 | del a[1::-2] |
| 385 | vereq(a, [0,2,3,4]) |
| 386 | # assignment |
| 387 | a = range(10) |
| 388 | a[::2] = [-1]*5 |
| 389 | vereq(a, [-1, 1, -1, 3, -1, 5, -1, 7, -1, 9]) |
| 390 | a = range(10) |
| 391 | a[::-4] = [10]*3 |
| 392 | vereq(a, [0, 10, 2, 3, 4, 10, 6, 7, 8 ,10]) |
| 393 | a = range(4) |
| 394 | a[::-1] = a |
| 395 | vereq(a, [3, 2, 1, 0]) |
| 396 | |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 397 | print '6.6 Mappings == Dictionaries' |
| 398 | d = {} |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 399 | if d.keys() != []: raise TestFailed, '{}.keys()' |
Neil Schemenauer | eff7244 | 2002-03-24 01:24:54 +0000 | [diff] [blame] | 400 | if d.values() != []: raise TestFailed, '{}.values()' |
| 401 | if d.items() != []: raise TestFailed, '{}.items()' |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 402 | if d.has_key('a') != 0: raise TestFailed, '{}.has_key(\'a\')' |
Guido van Rossum | 0dbb4fb | 2001-04-20 16:50:40 +0000 | [diff] [blame] | 403 | if ('a' in d) != 0: raise TestFailed, "'a' in {}" |
| 404 | if ('a' not in d) != 1: raise TestFailed, "'a' not in {}" |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 405 | if len(d) != 0: raise TestFailed, 'len({})' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 406 | d = {'a': 1, 'b': 2} |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 407 | if len(d) != 2: raise TestFailed, 'len(dict)' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 408 | k = d.keys() |
| 409 | k.sort() |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 410 | if k != ['a', 'b']: raise TestFailed, 'dict keys()' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 411 | if d.has_key('a') and d.has_key('b') and not d.has_key('c'): pass |
| 412 | else: raise TestFailed, 'dict keys()' |
Guido van Rossum | 0dbb4fb | 2001-04-20 16:50:40 +0000 | [diff] [blame] | 413 | if 'a' in d and 'b' in d and 'c' not in d: pass |
| 414 | else: raise TestFailed, 'dict keys() # in/not in version' |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 415 | if d['a'] != 1 or d['b'] != 2: raise TestFailed, 'dict item' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 416 | d['c'] = 3 |
| 417 | d['a'] = 4 |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 418 | if d['c'] != 3 or d['a'] != 4: raise TestFailed, 'dict item assignment' |
Guido van Rossum | 85f1820 | 1992-11-27 22:53:50 +0000 | [diff] [blame] | 419 | del d['b'] |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 420 | if d != {'a': 4, 'c': 3}: raise TestFailed, 'dict item deletion' |
Barry Warsaw | 4177538 | 2001-06-26 20:09:28 +0000 | [diff] [blame] | 421 | # dict.clear() |
Guido van Rossum | ce1fa26 | 1997-06-02 23:14:00 +0000 | [diff] [blame] | 422 | d = {1:1, 2:2, 3:3} |
| 423 | d.clear() |
| 424 | if d != {}: raise TestFailed, 'dict clear' |
Barry Warsaw | 4177538 | 2001-06-26 20:09:28 +0000 | [diff] [blame] | 425 | # dict.update() |
Guido van Rossum | ce1fa26 | 1997-06-02 23:14:00 +0000 | [diff] [blame] | 426 | d.update({1:100}) |
| 427 | d.update({2:20}) |
| 428 | d.update({1:1, 2:2, 3:3}) |
| 429 | if d != {1:1, 2:2, 3:3}: raise TestFailed, 'dict update' |
Barry Warsaw | 4177538 | 2001-06-26 20:09:28 +0000 | [diff] [blame] | 430 | d.clear() |
| 431 | try: d.update(None) |
| 432 | except AttributeError: pass |
| 433 | else: raise TestFailed, 'dict.update(None), AttributeError expected' |
| 434 | class SimpleUserDict: |
| 435 | def __init__(self): |
| 436 | self.d = {1:1, 2:2, 3:3} |
| 437 | def keys(self): |
| 438 | return self.d.keys() |
| 439 | def __getitem__(self, i): |
| 440 | return self.d[i] |
| 441 | d.update(SimpleUserDict()) |
| 442 | if d != {1:1, 2:2, 3:3}: raise TestFailed, 'dict.update(instance)' |
| 443 | d.clear() |
| 444 | class FailingUserDict: |
| 445 | def keys(self): |
| 446 | raise ValueError |
| 447 | try: d.update(FailingUserDict()) |
| 448 | except ValueError: pass |
| 449 | else: raise TestFailed, 'dict.keys() expected ValueError' |
| 450 | class FailingUserDict: |
| 451 | def keys(self): |
| 452 | class BogonIter: |
| 453 | def __iter__(self): |
| 454 | raise ValueError |
| 455 | return BogonIter() |
| 456 | try: d.update(FailingUserDict()) |
| 457 | except ValueError: pass |
| 458 | else: raise TestFailed, 'iter(dict.keys()) expected ValueError' |
| 459 | class FailingUserDict: |
| 460 | def keys(self): |
| 461 | class BogonIter: |
| 462 | def __init__(self): |
| 463 | self.i = 1 |
| 464 | def __iter__(self): |
| 465 | return self |
| 466 | def next(self): |
| 467 | if self.i: |
| 468 | self.i = 0 |
| 469 | return 'a' |
| 470 | raise ValueError |
| 471 | return BogonIter() |
| 472 | def __getitem__(self, key): |
| 473 | return key |
| 474 | try: d.update(FailingUserDict()) |
| 475 | except ValueError: pass |
| 476 | else: raise TestFailed, 'iter(dict.keys()).next() expected ValueError' |
| 477 | class FailingUserDict: |
| 478 | def keys(self): |
| 479 | class BogonIter: |
| 480 | def __init__(self): |
| 481 | self.i = ord('a') |
| 482 | def __iter__(self): |
| 483 | return self |
| 484 | def next(self): |
| 485 | if self.i <= ord('z'): |
| 486 | rtn = chr(self.i) |
| 487 | self.i += 1 |
| 488 | return rtn |
| 489 | raise StopIteration |
| 490 | return BogonIter() |
| 491 | def __getitem__(self, key): |
| 492 | raise ValueError |
| 493 | try: d.update(FailingUserDict()) |
| 494 | except ValueError: pass |
| 495 | else: raise TestFailed, 'dict.update(), __getitem__ expected ValueError' |
| 496 | # dict.copy() |
| 497 | d = {1:1, 2:2, 3:3} |
Guido van Rossum | ce1fa26 | 1997-06-02 23:14:00 +0000 | [diff] [blame] | 498 | if d.copy() != {1:1, 2:2, 3:3}: raise TestFailed, 'dict copy' |
| 499 | if {}.copy() != {}: raise TestFailed, 'empty dict copy' |
Barry Warsaw | 9b887c7 | 1997-10-20 17:34:43 +0000 | [diff] [blame] | 500 | # dict.get() |
Guido van Rossum | fb5cef1 | 1997-10-20 20:10:43 +0000 | [diff] [blame] | 501 | d = {} |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 502 | if d.get('c') is not None: raise TestFailed, 'missing {} get, no 2nd arg' |
Guido van Rossum | fb5cef1 | 1997-10-20 20:10:43 +0000 | [diff] [blame] | 503 | if d.get('c', 3) != 3: raise TestFailed, 'missing {} get, w/ 2nd arg' |
Barry Warsaw | 9b887c7 | 1997-10-20 17:34:43 +0000 | [diff] [blame] | 504 | d = {'a' : 1, 'b' : 2} |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 505 | if d.get('c') is not None: raise TestFailed, 'missing dict get, no 2nd arg' |
Barry Warsaw | 9b887c7 | 1997-10-20 17:34:43 +0000 | [diff] [blame] | 506 | if d.get('c', 3) != 3: raise TestFailed, 'missing dict get, w/ 2nd arg' |
| 507 | if d.get('a') != 1: raise TestFailed, 'present dict get, no 2nd arg' |
| 508 | if d.get('a', 3) != 1: raise TestFailed, 'present dict get, w/ 2nd arg' |
Guido van Rossum | 79c9b17 | 2000-08-08 16:13:23 +0000 | [diff] [blame] | 509 | # dict.setdefault() |
| 510 | d = {} |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 511 | if d.setdefault('key0') is not None: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 512 | raise TestFailed, 'missing {} setdefault, no 2nd arg' |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 513 | if d.setdefault('key0') is not None: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 514 | raise TestFailed, 'present {} setdefault, no 2nd arg' |
Guido van Rossum | 79c9b17 | 2000-08-08 16:13:23 +0000 | [diff] [blame] | 515 | d.setdefault('key', []).append(3) |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 516 | if d['key'][0] != 3: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 517 | raise TestFailed, 'missing {} setdefault, w/ 2nd arg' |
Guido van Rossum | 79c9b17 | 2000-08-08 16:13:23 +0000 | [diff] [blame] | 518 | d.setdefault('key', []).append(4) |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 519 | if len(d['key']) != 2: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 520 | raise TestFailed, 'present {} setdefault, w/ 2nd arg' |
Guido van Rossum | b822c61 | 2000-12-12 22:02:59 +0000 | [diff] [blame] | 521 | # dict.popitem() |
| 522 | for copymode in -1, +1: |
| 523 | # -1: b has same structure as a |
| 524 | # +1: b is a.copy() |
| 525 | for log2size in range(12): |
| 526 | size = 2**log2size |
| 527 | a = {} |
| 528 | b = {} |
| 529 | for i in range(size): |
| 530 | a[`i`] = i |
| 531 | if copymode < 0: |
| 532 | b[`i`] = i |
| 533 | if copymode > 0: |
| 534 | b = a.copy() |
| 535 | for i in range(size): |
| 536 | ka, va = ta = a.popitem() |
| 537 | if va != int(ka): raise TestFailed, "a.popitem: %s" % str(ta) |
| 538 | kb, vb = tb = b.popitem() |
| 539 | if vb != int(kb): raise TestFailed, "b.popitem: %s" % str(tb) |
| 540 | if copymode < 0 and ta != tb: |
| 541 | raise TestFailed, "a.popitem != b.popitem: %s, %s" % ( |
| 542 | str(ta), str(tb)) |
| 543 | if a: raise TestFailed, 'a not empty after popitems: %s' % str(a) |
| 544 | if b: raise TestFailed, 'b not empty after popitems: %s' % str(b) |
Guido van Rossum | 29d2606 | 2001-12-11 04:37:34 +0000 | [diff] [blame] | 545 | |
Neil Schemenauer | eff7244 | 2002-03-24 01:24:54 +0000 | [diff] [blame] | 546 | d.clear() |
| 547 | try: d.popitem() |
| 548 | except KeyError: pass |
| 549 | else: raise TestFailed, "{}.popitem doesn't raise KeyError" |
| 550 | |
Guido van Rossum | e027d98 | 2002-04-12 15:11:59 +0000 | [diff] [blame] | 551 | # Tests for pop with specified key |
| 552 | d.clear() |
| 553 | k, v = 'abc', 'def' |
| 554 | d[k] = v |
| 555 | try: d.pop('ghi') |
| 556 | except KeyError: pass |
| 557 | else: raise TestFailed, "{}.pop(k) doesn't raise KeyError when k not in dictionary" |
| 558 | |
| 559 | if d.pop(k) != v: raise TestFailed, "{}.pop(k) doesn't find known key/value pair" |
| 560 | if len(d) > 0: raise TestFailed, "{}.pop(k) failed to remove the specified pair" |
| 561 | |
| 562 | try: d.pop(k) |
| 563 | except KeyError: pass |
| 564 | else: raise TestFailed, "{}.pop(k) doesn't raise KeyError when dictionary is empty" |
| 565 | |
Neil Schemenauer | eff7244 | 2002-03-24 01:24:54 +0000 | [diff] [blame] | 566 | d[1] = 1 |
| 567 | try: |
| 568 | for i in d: |
Tim Peters | 863ac44 | 2002-04-16 01:38:40 +0000 | [diff] [blame] | 569 | d[i+1] = 1 |
Neil Schemenauer | eff7244 | 2002-03-24 01:24:54 +0000 | [diff] [blame] | 570 | except RuntimeError: |
| 571 | pass |
| 572 | else: |
| 573 | raise TestFailed, "changing dict size during iteration doesn't raise Error" |
| 574 | |
Guido van Rossum | 29d2606 | 2001-12-11 04:37:34 +0000 | [diff] [blame] | 575 | try: type(1, 2) |
| 576 | except TypeError: pass |
| 577 | else: raise TestFailed, 'type(), w/2 args expected TypeError' |
| 578 | |
| 579 | try: type(1, 2, 3, 4) |
| 580 | except TypeError: pass |
| 581 | else: raise TestFailed, 'type(), w/4 args expected TypeError' |
Neil Schemenauer | eff7244 | 2002-03-24 01:24:54 +0000 | [diff] [blame] | 582 | |
| 583 | print 'Buffers' |
| 584 | try: buffer('asdf', -1) |
| 585 | except ValueError: pass |
| 586 | else: raise TestFailed, "buffer('asdf', -1) should raise ValueError" |
| 587 | |
| 588 | try: buffer(None) |
| 589 | except TypeError: pass |
| 590 | else: raise TestFailed, "buffer(None) should raise TypeError" |
| 591 | |
| 592 | a = buffer('asdf') |
| 593 | hash(a) |
| 594 | b = a * 5 |
| 595 | if a == b: |
| 596 | raise TestFailed, 'buffers should not be equal' |
Fred Drake | 485f340 | 2002-05-02 04:27:20 +0000 | [diff] [blame] | 597 | if str(b) != ('asdf' * 5): |
| 598 | raise TestFailed, 'repeated buffer has wrong content' |
| 599 | if str(a * 0) != '': |
| 600 | raise TestFailed, 'repeated buffer zero times has wrong content' |
| 601 | if str(a + buffer('def')) != 'asdfdef': |
| 602 | raise TestFailed, 'concatenation of buffers yields wrong content' |
Neil Schemenauer | eff7244 | 2002-03-24 01:24:54 +0000 | [diff] [blame] | 603 | |
| 604 | try: a[1] = 'g' |
| 605 | except TypeError: pass |
| 606 | else: raise TestFailed, "buffer assignment should raise TypeError" |
| 607 | |
| 608 | try: a[0:1] = 'g' |
| 609 | except TypeError: pass |
| 610 | else: raise TestFailed, "buffer slice assignment should raise TypeError" |