OLD | NEW |
| (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 // Dart test program for testing native int arrays. | |
6 | |
7 // Library tag to be able to run in html test framework. | |
8 library IntArrayTest; | |
9 | |
10 import "package:expect/expect.dart"; | |
11 import 'dart:typed_data'; | |
12 | |
13 void testInt16() { | |
14 Int16List intArray = new Int16List(4); | |
15 intArray[0] = 0; | |
16 intArray[1] = -1; | |
17 intArray[2] = -2; | |
18 intArray[3] = -3; | |
19 for (int i = 0; i < intArray.length; i++) { | |
20 intArray[i]++; | |
21 } | |
22 var x = intArray[0]; | |
23 var y = intArray[1]; | |
24 var z = intArray[2]; | |
25 var w = intArray[3]; | |
26 Expect.equals(1, x); | |
27 Expect.equals(0, y); | |
28 Expect.equals(-1, z); | |
29 Expect.equals(-2, w); | |
30 var t = y + 1; | |
31 intArray[0] = t; | |
32 Expect.equals(t, intArray[0]); | |
33 } | |
34 | |
35 void testUint16() { | |
36 Uint16List intArray = new Uint16List(4); | |
37 intArray[0] = 0; | |
38 intArray[1] = 1; | |
39 intArray[2] = 2; | |
40 intArray[3] = 3; | |
41 for (int i = 0; i < intArray.length; i++) { | |
42 intArray[i]--; | |
43 } | |
44 var x = intArray[0]; | |
45 var y = intArray[1]; | |
46 var z = intArray[2]; | |
47 var w = intArray[3]; | |
48 Expect.equals(65535, x); | |
49 Expect.equals(0, y); | |
50 Expect.equals(1, z); | |
51 Expect.equals(2, w); | |
52 var t = y + 1; | |
53 intArray[0] = t; | |
54 Expect.equals(t, intArray[0]); | |
55 } | |
56 | |
57 void testInt32ToSmi() { | |
58 Int32List intArray; | |
59 | |
60 intArray = new Int32List(4); | |
61 intArray[0] = 1073741823; // SmiMax | |
62 intArray[1] = -1073741824; // SmiMin | |
63 intArray[2] = 1073741824; // SmiMax+1 | |
64 intArray[3] = -1073741825; // SmiMin-1 | |
65 var x = intArray[0]; | |
66 var y = intArray[1]; | |
67 var z = intArray[2]; | |
68 var w = intArray[3]; | |
69 Expect.equals(1073741823, x); | |
70 Expect.equals(-1073741824, y); | |
71 Expect.equals(1073741824, z); | |
72 Expect.equals(-1073741825, w); | |
73 } | |
74 | |
75 void testUint32ToSmi() { | |
76 Uint32List intArray; | |
77 | |
78 intArray = new Uint32List(4); | |
79 intArray[0] = 1073741823; // SmiMax | |
80 intArray[1] = -1; // 0xFFFFFFFF : 4294967295 | |
81 intArray[2] = 1073741830; // SmiMax+7 | |
82 intArray[3] = -1073741825; // 0xbfffffff : 3221225471 | |
83 var x = intArray[0]; | |
84 var y = intArray[1]; | |
85 var z = intArray[2]; | |
86 var w = intArray[3]; | |
87 Expect.equals(1073741823, x); | |
88 Expect.equals(4294967295, y); | |
89 Expect.equals(1073741830, z); | |
90 Expect.equals(3221225471, w); | |
91 } | |
92 | |
93 void testInt64ToSmi() { | |
94 Int64List intArray; | |
95 | |
96 intArray = new Int64List(4); | |
97 intArray[0] = 4611686018427387903; // SmiMax | |
98 intArray[1] = -4611686018427387904; // SmiMin | |
99 intArray[2] = 4611686018427387904; // SmiMax+1 | |
100 intArray[3] = -4611686018427387905; // SmiMin-1 | |
101 var x = intArray[0]; | |
102 var y = intArray[1]; | |
103 var z = intArray[2]; | |
104 var w = intArray[3]; | |
105 Expect.equals(4611686018427387903, x); | |
106 Expect.equals(-4611686018427387904, y); | |
107 Expect.equals(4611686018427387904, z); | |
108 Expect.equals(-4611686018427387905, w); | |
109 } | |
110 | |
111 void testUint64ToSmi() { | |
112 Uint64List intArray; | |
113 | |
114 intArray = new Uint64List(4); | |
115 intArray[0] = 4611686018427387903; // SmiMax | |
116 intArray[1] = -1; // 0xFFFFFFFFFFFFFFFF : 18446744073709551615 | |
117 intArray[2] = 4611686018427387904; // SmiMax+1 | |
118 intArray[3] = 9223372036854775808; | |
119 var x = intArray[0]; | |
120 var y = intArray[1]; | |
121 var z = intArray[2]; | |
122 var w = intArray[3]; | |
123 Expect.equals(4611686018427387903, x); | |
124 Expect.equals(18446744073709551615, y); | |
125 Expect.equals(4611686018427387904, z); | |
126 Expect.equals(9223372036854775808, w); | |
127 } | |
128 | |
129 main() { | |
130 testUint64ToSmi(); | |
131 for (int i = 0; i < 2000; i++) { | |
132 testInt16(); | |
133 testUint16(); | |
134 testInt32ToSmi(); | |
135 testUint32ToSmi(); | |
136 testInt64ToSmi(); | |
137 testUint64ToSmi(); | |
138 } | |
139 } | |
OLD | NEW |