Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / lib / python2.4 / test / test_augassign.py
CommitLineData
920dae64
AT
1# Augmented assignment test.
2
3x = 2
4x += 1
5x *= 2
6x **= 2
7x -= 8
8x //= 2
9x //= 1
10x %= 12
11x &= 2
12x |= 5
13x ^= 1
14
15print x
16
17x = [2]
18x[0] += 1
19x[0] *= 2
20x[0] **= 2
21x[0] -= 8
22x[0] //= 2
23x[0] //= 2
24x[0] %= 12
25x[0] &= 2
26x[0] |= 5
27x[0] ^= 1
28
29print x
30
31x = {0: 2}
32x[0] += 1
33x[0] *= 2
34x[0] **= 2
35x[0] -= 8
36x[0] //= 2
37x[0] //= 1
38x[0] %= 12
39x[0] &= 2
40x[0] |= 5
41x[0] ^= 1
42
43print x[0]
44
45x = [1,2]
46x += [3,4]
47x *= 2
48
49print x
50
51x = [1, 2, 3]
52y = x
53x[1:2] *= 2
54y[1:2] += [1]
55
56print x
57print x is y
58
59class aug_test:
60 def __init__(self, value):
61 self.val = value
62 def __radd__(self, val):
63 return self.val + val
64 def __add__(self, val):
65 return aug_test(self.val + val)
66
67
68class aug_test2(aug_test):
69 def __iadd__(self, val):
70 self.val = self.val + val
71 return self
72
73class aug_test3(aug_test):
74 def __iadd__(self, val):
75 return aug_test3(self.val + val)
76
77x = aug_test(1)
78y = x
79x += 10
80
81print isinstance(x, aug_test)
82print y is not x
83print x.val
84
85x = aug_test2(2)
86y = x
87x += 10
88
89print y is x
90print x.val
91
92x = aug_test3(3)
93y = x
94x += 10
95
96print isinstance(x, aug_test3)
97print y is not x
98print x.val
99
100class testall:
101
102 def __add__(self, val):
103 print "__add__ called"
104 def __radd__(self, val):
105 print "__radd__ called"
106 def __iadd__(self, val):
107 print "__iadd__ called"
108 return self
109
110 def __sub__(self, val):
111 print "__sub__ called"
112 def __rsub__(self, val):
113 print "__rsub__ called"
114 def __isub__(self, val):
115 print "__isub__ called"
116 return self
117
118 def __mul__(self, val):
119 print "__mul__ called"
120 def __rmul__(self, val):
121 print "__rmul__ called"
122 def __imul__(self, val):
123 print "__imul__ called"
124 return self
125
126 def __div__(self, val):
127 print "__div__ called"
128 def __rdiv__(self, val):
129 print "__rdiv__ called"
130 def __idiv__(self, val):
131 print "__idiv__ called"
132 return self
133
134 def __floordiv__(self, val):
135 print "__floordiv__ called"
136 return self
137 def __ifloordiv__(self, val):
138 print "__ifloordiv__ called"
139 return self
140 def __rfloordiv__(self, val):
141 print "__rfloordiv__ called"
142 return self
143
144 def __truediv__(self, val):
145 print "__truediv__ called"
146 return self
147 def __itruediv__(self, val):
148 print "__itruediv__ called"
149 return self
150
151 def __mod__(self, val):
152 print "__mod__ called"
153 def __rmod__(self, val):
154 print "__rmod__ called"
155 def __imod__(self, val):
156 print "__imod__ called"
157 return self
158
159 def __pow__(self, val):
160 print "__pow__ called"
161 def __rpow__(self, val):
162 print "__rpow__ called"
163 def __ipow__(self, val):
164 print "__ipow__ called"
165 return self
166
167 def __or__(self, val):
168 print "__or__ called"
169 def __ror__(self, val):
170 print "__ror__ called"
171 def __ior__(self, val):
172 print "__ior__ called"
173 return self
174
175 def __and__(self, val):
176 print "__and__ called"
177 def __rand__(self, val):
178 print "__rand__ called"
179 def __iand__(self, val):
180 print "__iand__ called"
181 return self
182
183 def __xor__(self, val):
184 print "__xor__ called"
185 def __rxor__(self, val):
186 print "__rxor__ called"
187 def __ixor__(self, val):
188 print "__ixor__ called"
189 return self
190
191 def __rshift__(self, val):
192 print "__rshift__ called"
193 def __rrshift__(self, val):
194 print "__rrshift__ called"
195 def __irshift__(self, val):
196 print "__irshift__ called"
197 return self
198
199 def __lshift__(self, val):
200 print "__lshift__ called"
201 def __rlshift__(self, val):
202 print "__rlshift__ called"
203 def __ilshift__(self, val):
204 print "__ilshift__ called"
205 return self
206
207x = testall()
208x + 1
2091 + x
210x += 1
211
212x - 1
2131 - x
214x -= 1
215
216x * 1
2171 * x
218x *= 1
219
220if 1/2 == 0:
221 x / 1
222 1 / x
223 x /= 1
224else:
225 # True division is in effect, so "/" doesn't map to __div__ etc;
226 # but the canned expected-output file requires that those get called.
227 x.__div__(1)
228 x.__rdiv__(1)
229 x.__idiv__(1)
230
231x // 1
2321 // x
233x //= 1
234
235x % 1
2361 % x
237x %= 1
238
239x ** 1
2401 ** x
241x **= 1
242
243x | 1
2441 | x
245x |= 1
246
247x & 1
2481 & x
249x &= 1
250
251x ^ 1
2521 ^ x
253x ^= 1
254
255x >> 1
2561 >> x
257x >>= 1
258
259x << 1
2601 << x
261x <<= 1