OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 // Dart test program for testing assign operators. | |
5 // VMOptions=--optimization-counter-threshold=10 | |
6 | |
7 import "package:expect/expect.dart"; | |
8 | |
9 class AssignOpTest { | |
10 AssignOpTest() {} | |
11 | |
12 static testMain() { | |
13 var b = 0; | |
14 b += 1; | |
15 Expect.equals(1, b); | |
16 b *= 5; | |
17 Expect.equals(5, b); | |
18 b -= 1; | |
19 Expect.equals(4, b); | |
20 b ~/= 2; | |
21 Expect.equals(2, b); | |
22 | |
23 f = 0; | |
24 f += 1; | |
25 Expect.equals(1, f); | |
26 f *= 5; | |
27 Expect.equals(5, f); | |
28 f -= 1; | |
29 Expect.equals(4, f); | |
30 f ~/= 2; | |
31 Expect.equals(2, f); | |
32 f /= 4; | |
33 Expect.equals(.5, f); | |
34 | |
35 AssignOpTest.f = 0; | |
36 AssignOpTest.f += 1; | |
37 Expect.equals(1, AssignOpTest.f); | |
38 AssignOpTest.f *= 5; | |
39 Expect.equals(5, AssignOpTest.f); | |
40 AssignOpTest.f -= 1; | |
41 Expect.equals(4, AssignOpTest.f); | |
42 AssignOpTest.f ~/= 2; | |
43 Expect.equals(2, AssignOpTest.f); | |
44 AssignOpTest.f /= 4; | |
45 Expect.equals(.5, f); | |
46 | |
47 var o = new AssignOpTest(); | |
48 o.instf = 0; | |
49 o.instf += 1; | |
50 Expect.equals(1, o.instf); | |
51 o.instf *= 5; | |
52 Expect.equals(5, o.instf); | |
53 o.instf -= 1; | |
54 Expect.equals(4, o.instf); | |
55 o.instf ~/= 2; | |
56 Expect.equals(2, o.instf); | |
57 o.instf /= 4; | |
58 Expect.equals(.5, o.instf); | |
59 | |
60 var x = 0xFF; | |
61 x >>= 3; | |
62 Expect.equals(0x1F, x); | |
63 x <<= 3; | |
64 Expect.equals(0xF8, x); | |
65 x |= 0xF00; | |
66 Expect.equals(0xFF8, x); | |
67 x &= 0xF0; | |
68 Expect.equals(0xF0, x); | |
69 x ^= 0x11; | |
70 Expect.equals(0xE1, x); | |
71 | |
72 var y = 100; | |
73 y += 1 << 3; | |
74 Expect.equals(108, y); | |
75 y *= 2 + 1; | |
76 Expect.equals(324, y); | |
77 y -= 3 - 2; | |
78 Expect.equals(323, y); | |
79 y += 3 * 4; | |
80 Expect.equals(335, y); | |
81 | |
82 var a = [1, 2, 3]; | |
83 var ix = 0; | |
84 a[ix] |= 12; | |
85 Expect.equals(13, a[ix]); | |
86 } | |
87 | |
88 static var f; | |
89 var instf; | |
90 } | |
91 | |
92 main() { | |
93 for (int i = 0; i < 20; i++) { | |
94 AssignOpTest.testMain(); | |
95 } | |
96 } | |
OLD | NEW |