annotate Lib/test/test_types.py @ 4566:6403c94de50d legacy-trunk

Added safeguard against failure in __del__.
author Guido van Rossum <guido@python.org>
date Wed, 27 Nov 1996 19:39:58 +0000
parents 1ce3dbeeb890
children c66236b7cc6c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1097
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 # Python test set -- part 6, built-in types
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 from test_support import *
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 print '6. Built-in types'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 print '6.1 Truth value testing'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 if None: raise TestFailed, 'None is true instead of false'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 if 0: raise TestFailed, '0 is true instead of false'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 if 0L: raise TestFailed, '0L is true instead of false'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 if 0.0: raise TestFailed, '0.0 is true instead of false'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 if '': raise TestFailed, '\'\' is true instead of false'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 if (): raise TestFailed, '() is true instead of false'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 if []: raise TestFailed, '[] is true instead of false'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 if {}: raise TestFailed, '{} is true instead of false'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 if not 1: raise TestFailed, '1 is false instead of true'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 if not 1L: raise TestFailed, '1L is false instead of true'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 if not 1.0: raise TestFailed, '1.0 is false instead of true'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 if not 'x': raise TestFailed, '\'x\' is false instead of true'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 if not (1, 1): raise TestFailed, '(1, 1) is false instead of true'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 if not [1]: raise TestFailed, '[1] is false instead of true'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 if not {'x': 1}: raise TestFailed, '{\'x\': 1} is false instead of true'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 def f(): pass
1291
517d29ebc840 * ftplib.py: added abort() command (sends oob data).
Guido van Rossum <guido@python.org>
parents: 1190
diff changeset
24 class C: pass
1097
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 import sys
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 x = C()
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 if not f: raise TestFailed, 'f is false instead of true'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 if not C: raise TestFailed, 'C is false instead of true'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 if not sys: raise TestFailed, 'sys is false instead of true'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 if not x: raise TestFailed, 'x is false instead of true'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 print '6.2 Boolean operations'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 if 0 or 0: raise TestFailed, '0 or 0 is true instead of false'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 if 1 and 1: pass
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 else: raise TestFailed, '1 and 1 is false instead of false'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 if not 1: raise TestFailed, 'not 1 is true instead of false'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
37
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 print '6.3 Comparisons'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 if 0 < 1 <= 1 == 1 >= 1 > 0 <> 1: pass
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 else: raise TestFailed, 'int comparisons failed'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 if 0L < 1L <= 1L == 1L >= 1L > 0L <> 1L: pass
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 else: raise TestFailed, 'long int comparisons failed'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 if 0.0 < 1.0 <= 1.0 == 1.0 >= 1.0 > 0.0 <> 1.0: pass
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 else: raise TestFailed, 'float comparisons failed'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 if '' < 'a' <= 'a' == 'a' < 'abc' < 'abd' < 'b': pass
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 else: raise TestFailed, 'string comparisons failed'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 if 0 in [0] and 0 not in [1]: pass
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 else: raise TestFailed, 'membership test failed'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 if None is None and [] is not []: pass
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 else: raise TestFailed, 'identity test failed'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
51
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 print '6.4 Numeric types (mostly conversions)'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 if 0 <> 0L or 0 <> 0.0 or 0L <> 0.0: raise TestFailed, 'mixed comparisons'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 if 1 <> 1L or 1 <> 1.0 or 1L <> 1.0: raise TestFailed, 'mixed comparisons'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 if -1 <> -1L or -1 <> -1.0 or -1L <> -1.0:
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 raise TestFailed, 'int/long/float value not equal'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 if int(1.9) == 1 == int(1.1) and int(-1.1) == -1 == int(-1.9): pass
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 else: raise TestFailed, 'int() does not round properly'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 if long(1.9) == 1L == long(1.1) and long(-1.1) == -1L == long(-1.9): pass
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 else: raise TestFailed, 'long() does not round properly'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 if float(1) == 1.0 and float(-1) == -1.0 and float(0) == 0.0: pass
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 else: raise TestFailed, 'float() does not work properly'
1190
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
63 print '6.4.1 32-bit integers'
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
64 if 12 + 24 <> 36: raise TestFailed, 'int op'
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
65 if 12 + (-24) <> -12: raise TestFailed, 'int op'
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
66 if (-12) + 24 <> 12: raise TestFailed, 'int op'
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
67 if (-12) + (-24) <> -36: raise TestFailed, 'int op'
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
68 if not 12 < 24: raise TestFailed, 'int op'
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
69 if not -24 < -12: raise TestFailed, 'int op'
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1357
diff changeset
70 # Test for a particular bug in integer multiply
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1357
diff changeset
71 xsize, ysize, zsize = 238, 356, 4
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1357
diff changeset
72 if not (xsize*ysize*zsize == zsize*xsize*ysize == 338912):
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1357
diff changeset
73 raise TestFailed, 'int mul commutativity'
1190
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
74 print '6.4.2 Long integers'
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
75 if 12L + 24L <> 36L: raise TestFailed, 'long op'
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
76 if 12L + (-24L) <> -12L: raise TestFailed, 'long op'
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
77 if (-12L) + 24L <> 12L: raise TestFailed, 'long op'
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
78 if (-12L) + (-24L) <> -36L: raise TestFailed, 'long op'
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
79 if not 12L < 24L: raise TestFailed, 'long op'
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
80 if not -24L < -12L: raise TestFailed, 'long op'
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
81 print '6.4.3 Floating point numbers'
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
82 if 12.0 + 24.0 <> 36.0: raise TestFailed, 'float op'
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
83 if 12.0 + (-24.0) <> -12.0: raise TestFailed, 'float op'
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
84 if (-12.0) + 24.0 <> 12.0: raise TestFailed, 'float op'
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
85 if (-12.0) + (-24.0) <> -36.0: raise TestFailed, 'float op'
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
86 if not 12.0 < 24.0: raise TestFailed, 'float op'
ea8d4cce782b * Add some more tests for numbers
Guido van Rossum <guido@python.org>
parents: 1097
diff changeset
87 if not -24.0 < -12.0: raise TestFailed, 'float op'
1097
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
88
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 print '6.5 Sequence types'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
90
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 print '6.5.1 Strings'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 if len('') <> 0: raise TestFailed, 'len(\'\')'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 if len('a') <> 1: raise TestFailed, 'len(\'a\')'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 if len('abcdef') <> 6: raise TestFailed, 'len(\'abcdef\')'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 if 'xyz' + 'abcde' <> 'xyzabcde': raise TestFailed, 'string concatenation'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 if 'xyz'*3 <> 'xyzxyzxyz': raise TestFailed, 'string repetition *3'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 if 0*'abcde' <> '': raise TestFailed, 'string repetition 0*'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 if min('abc') <> 'a' or max('abc') <> 'c': raise TestFailed, 'min/max string'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 if 'a' in 'abc' and 'b' in 'abc' and 'c' in 'abc' and 'd' not in 'abc': pass
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 else: raise TestFailed, 'in/not in string'
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1357
diff changeset
101 x = 'x'*103
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1357
diff changeset
102 if '%s!'%x != x+'!': raise TestFailed, 'nasty string formatting bug'
1097
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
103
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 print '6.5.2 Tuples'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 if len(()) <> 0: raise TestFailed, 'len(())'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 if len((1,)) <> 1: raise TestFailed, 'len((1,))'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 if len((1,2,3,4,5,6)) <> 6: raise TestFailed, 'len((1,2,3,4,5,6))'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 if (1,2)+(3,4) <> (1,2,3,4): raise TestFailed, 'tuple concatenation'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 if (1,2)*3 <> (1,2,1,2,1,2): raise TestFailed, 'tuple repetition *3'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 if 0*(1,2,3) <> (): raise TestFailed, 'tuple repetition 0*'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 if min((1,2)) <> 1 or max((1,2)) <> 2: raise TestFailed, 'min/max tuple'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 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
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 else: raise TestFailed, 'in/not in tuple'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
114
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 print '6.5.3 Lists'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 if len([]) <> 0: raise TestFailed, 'len([])'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 if len([1,]) <> 1: raise TestFailed, 'len([1,])'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 if len([1,2,3,4,5,6]) <> 6: raise TestFailed, 'len([1,2,3,4,5,6])'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 if [1,2]+[3,4] <> [1,2,3,4]: raise TestFailed, 'list concatenation'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 if [1,2]*3 <> [1,2,1,2,1,2]: raise TestFailed, 'list repetition *3'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 if 0*[1,2,3] <> []: raise TestFailed, 'list repetition 0*'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 if min([1,2]) <> 1 or max([1,2]) <> 2: raise TestFailed, 'min/max list'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 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
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 else: raise TestFailed, 'in/not in list'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
125
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 print '6.5.3a Additional list operations'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 a = [0,1,2,3,4]
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 a[0] = 5
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 a[1] = 6
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 a[2] = 7
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 if a <> [5,6,7,3,4]: raise TestFailed, 'list item assignment [0], [1], [2]'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 a[-2] = 8
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 a[-1] = 9
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 if a <> [5,6,7,8,9]: raise TestFailed, 'list item assignment [-2], [-1]'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 a[:2] = [0,4]
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 a[-3:] = []
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 a[1:1] = [1,2,3]
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 if a <> [0,1,2,3,4]: raise TestFailed, 'list slice assignment'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 del a[1:4]
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 if a <> [0,4]: raise TestFailed, 'list slice deletion'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 del a[0]
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 if a <> [4]: raise TestFailed, 'list item deletion [0]'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 del a[-1]
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 if a <> []: raise TestFailed, 'list item deletion [-1]'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 a.append(0)
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 a.append(1)
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 a.append(2)
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 if a <> [0,1,2]: raise TestFailed, 'list append'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 a.insert(0, -2)
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 a.insert(1, -1)
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 a.insert(2,0)
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 if a <> [-2,-1,0,0,1,2]: raise TestFailed, 'list insert'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 if a.count(0) <> 2: raise TestFailed, ' list count'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 if a.index(0) <> 2: raise TestFailed, 'list index'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 a.remove(0)
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 if a <> [-2,-1,0,1,2]: raise TestFailed, 'list remove'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 a.reverse()
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 if a <> [2,1,0,-1,-2]: raise TestFailed, 'list reverse'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 a.sort()
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 if a <> [-2,-1,0,1,2]: raise TestFailed, 'list sort'
1357
2fac209e1c3f * profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents: 1291
diff changeset
161 def revcmp(a, b): return cmp(b, a)
2fac209e1c3f * profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents: 1291
diff changeset
162 a.sort(revcmp)
2fac209e1c3f * profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents: 1291
diff changeset
163 if a <> [2,1,0,-1,-2]: raise TestFailed, 'list sort with cmp func'
1097
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
164
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 print '6.6 Mappings == Dictionaries'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 d = {}
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 if d.keys() <> []: raise TestFailed, '{}.keys()'
2046
1ce3dbeeb890 Test new __import__ module, test reload of built-in module, test
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
168 if d.has_key('a') <> 0: raise TestFailed, '{}.has_key(\'a\')'
1097
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 if len(d) <> 0: raise TestFailed, 'len({})'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 d = {'a': 1, 'b': 2}
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 if len(d) <> 2: raise TestFailed, 'len(dict)'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 k = d.keys()
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 k.sort()
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 if k <> ['a', 'b']: raise TestFailed, 'dict keys()'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 if d.has_key('a') and d.has_key('b') and not d.has_key('c'): pass
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 else: raise TestFailed, 'dict keys()'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 if d['a'] <> 1 or d['b'] <> 2: raise TestFailed, 'dict item'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 d['c'] = 3
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 d['a'] = 4
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 if d['c'] <> 3 or d['a'] <> 4: raise TestFailed, 'dict item assignment'
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 del d['b']
c644bc626098 Added some new tests and two new files for testing: test_types.py
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 if d <> {'a': 4, 'c': 3}: raise TestFailed, 'dict item deletion'