Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: tests/lib/fixnum/int_32_test.dart

Issue 10854162: Move fixnum to from lib/ to pkg/ . Once pub.dartlang.org (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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
5 #library("int32test");
6 #import('../../../lib/fixnum/fixnum.dart');
7
8 void main() {
9 Expect.equals("0", new int32.fromInt(0).toString());
10 Expect.equals("1", new int32.fromInt(1).toString());
11 Expect.equals("-1", new int32.fromInt(-1).toString());
12 Expect.equals("1000", new int32.fromInt(1000).toString());
13 Expect.equals("-1000", new int32.fromInt(-1000).toString());
14 Expect.equals("2147483647", new int32.fromInt(2147483647).toString());
15 Expect.equals("-2147483648", new int32.fromInt(2147483648).toString());
16 Expect.equals("-2147483647", new int32.fromInt(2147483649).toString());
17 Expect.equals("-2147483646", new int32.fromInt(2147483650).toString());
18 Expect.equals("-2147483648", new int32.fromInt(-2147483648).toString());
19 Expect.equals("2147483647", new int32.fromInt(-2147483649).toString());
20 Expect.equals("2147483646", new int32.fromInt(-2147483650).toString());
21
22 Expect.equals("-1", new int32.fromInt(-1).toHexString());
23 Expect.equals("-1", (new int32.fromInt(-1) >> 8).toHexString());
24 Expect.equals("-100", (new int32.fromInt(-1) << 8).toHexString());
25 Expect.equals("ffffff",
26 new int32.fromInt(-1).shiftRightUnsigned(8).toHexString());
27
28 Expect.equals("123456789", new int32.fromInt(123456789).toString());
29 Expect.equals("75bcd15", new int32.fromInt(123456789).toHexString());
30 Expect.equals("223101104124", new int32.fromInt(123456789).toRadixString(5));
31
32 try {
33 new int32.fromInt(17) >> -1;
34 Expect.fail("x >> -1 should throw IllegalArgumentException");
35 } catch (IllegalArgumentException e) {
36 }
37
38 try {
39 new int32.fromInt(17) << -1;
40 Expect.fail("x >> -1 should throw IllegalArgumentException");
41 } catch (IllegalArgumentException e) {
42 }
43
44 try {
45 new int32.fromInt(17).shiftRightUnsigned(-1);
46 Expect.fail("x >> -1 should throw IllegalArgumentException");
47 } catch (IllegalArgumentException e) {
48 }
49
50 // wraparound
51 Expect.equals("-67153019", (new int32.fromInt(123456789) *
52 new int32.fromInt(987654321)).toString());
53 Expect.equals("121932631112635269", (new int64.fromInt(123456789) *
54 new int32.fromInt(987654321)).toString());
55 Expect.equals("121932631112635269", (new int32.fromInt(123456789) *
56 new int64.fromInt(987654321)).toString());
57 Expect.equals("121932631112635269", (new int64.fromInt(123456789) *
58 new int64.fromInt(987654321)).toString());
59
60 Expect.equals("432461",
61 (new int32.fromInt(829893893) ~/ new int32.fromInt(1919)).toString());
62 Expect.equals("432461",
63 (new int32.fromInt(829893893) ~/ new int64.fromInt(1919)).toString());
64 Expect.equals("432461",
65 (new int64.fromInt(829893893) ~/ new int32.fromInt(1919)).toString());
66 Expect.equals("432461",
67 (new int64.fromInt(829893893) ~/ new int64.fromInt(1919)).toString());
68 Expect.equals("432461",
69 (new int32.fromInt(829893893) ~/ 1919).toString());
70 Expect.equals("432461",
71 (new int64.fromInt(829893893) ~/ 1919).toString());
72
73 Expect.isTrue(new int32.fromInt(12345) == 12345);
74 Expect.isTrue(new int32.fromInt(12345) == new int32.fromInt(12345));
75 Expect.isTrue(new int64.fromInt(12345) == new int32.fromInt(12345));
76
77 Expect.equals(new int32.fromInt(~0x12345678),
78 ~(new int32.fromInt(0x12345678)));
79 Expect.equals(new int64.fromInt(-0x12345678),
80 -(new int32.fromInt(0x12345678)));
81
82 Expect.equals(new int32.fromInt(0x12345678 & 0x22222222),
83 new int32.fromInt(0x12345678) & new int32.fromInt(0x22222222));
84 Expect.equals(new int64.fromInt(0x12345678 & 0x22222222),
85 new int32.fromInt(0x12345678) & new int64.fromInt(0x22222222));
86 Expect.equals(new int32.fromInt(0x12345678 | 0x22222222),
87 new int32.fromInt(0x12345678) | new int32.fromInt(0x22222222));
88 Expect.equals(new int64.fromInt(0x12345678 | 0x22222222),
89 new int32.fromInt(0x12345678) | new int64.fromInt(0x22222222));
90 Expect.equals(new int32.fromInt(0x12345678 ^ 0x22222222),
91 new int32.fromInt(0x12345678) ^ new int32.fromInt(0x22222222));
92 Expect.equals(new int64.fromInt(0x12345678 ^ 0x22222222),
93 new int32.fromInt(0x12345678) ^ new int64.fromInt(0x22222222));
94
95 Expect.equals(new int32.fromInt(0x12345678 + 0x22222222),
96 new int32.fromInt(0x12345678) + new int32.fromInt(0x22222222));
97 Expect.equals(new int64.fromInt(0x12345678 + 0x22222222),
98 new int32.fromInt(0x12345678) + new int64.fromInt(0x22222222));
99 Expect.equals(new int32.fromInt(0x12345678 - 0x22222222),
100 new int32.fromInt(0x12345678) - new int32.fromInt(0x22222222));
101 Expect.equals(new int64.fromInt(0x12345678 - 0x22222222),
102 new int32.fromInt(0x12345678) - new int64.fromInt(0x22222222));
103 Expect.equals(new int32.fromInt(-899716112),
104 new int32.fromInt(0x12345678) * new int32.fromInt(0x22222222));
105 Expect.equals(new int64.fromInts(0x026D60DC, 0xCA5F6BF0),
106 new int32.fromInt(0x12345678) * new int64.fromInt(0x22222222));
107 Expect.equals(new int32.fromInt(0x12345678 % 0x22),
108 new int32.fromInt(0x12345678) % new int32.fromInt(0x22));
109 Expect.equals(new int32.fromInt(0x12345678 % 0x22),
110 new int32.fromInt(0x12345678) % new int64.fromInt(0x22));
111 Expect.equals(new int32.fromInt(0x12345678.remainder(0x22)),
112 new int32.fromInt(0x12345678).remainder(new int32.fromInt(0x22)));
113 Expect.equals(new int32.fromInt(0x12345678.remainder(-0x22)),
114 new int32.fromInt(0x12345678).remainder(new int32.fromInt(-0x22)));
115 Expect.equals(new int32.fromInt(-0x12345678.remainder(-0x22)),
116 new int32.fromInt(-0x12345678).remainder(new int32.fromInt(-0x22)));
117 Expect.equals(new int32.fromInt(-0x12345678.remainder(0x22)),
118 new int32.fromInt(-0x12345678).remainder(new int32.fromInt(0x22)));
119 Expect.equals(new int32.fromInt(0x12345678.remainder(0x22)),
120 new int32.fromInt(0x12345678).remainder(new int64.fromInt(0x22)));
121 Expect.equals(new int32.fromInt(0x12345678 ~/ 0x22),
122 new int32.fromInt(0x12345678) ~/ new int32.fromInt(0x22));
123 Expect.equals(new int32.fromInt(0x12345678 ~/ 0x22),
124 new int32.fromInt(0x12345678) ~/ new int64.fromInt(0x22));
125
126 Expect.equals(new int32.fromInt(0x12345678 >> 7),
127 new int32.fromInt(0x12345678) >> 7);
128 Expect.equals(new int32.fromInt(0x12345678 << 7),
129 new int32.fromInt(0x12345678) << 7);
130 Expect.equals(new int32.fromInt(0x12345678 >> 7),
131 new int32.fromInt(0x12345678).shiftRightUnsigned(7));
132
133 try {
134 new int32.fromInt(17) < null;
135 Expect.fail("x < null should throw NullPointerException");
136 } catch (NullPointerException e) {
137 }
138
139 try {
140 new int32.fromInt(17) <= null;
141 Expect.fail("x <= null should throw NullPointerException");
142 } catch (NullPointerException e) {
143 }
144
145 try {
146 new int32.fromInt(17) > null;
147 Expect.fail("x > null should throw NullPointerException");
148 } catch (NullPointerException e) {
149 }
150
151 try {
152 new int32.fromInt(17) < null;
153 Expect.fail("x >= null should throw NullPointerException");
154 } catch (NullPointerException e) {
155 }
156
157 Expect.isFalse(new int32.fromInt(17) == null);
158 }
OLDNEW
« pkg/fixnum/pubspec.yaml ('K') | « pkg/pkg.status ('k') | tests/lib/fixnum/int_64_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698