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

Side by Side Diff: tests/html/typed_arrays_2_test.dart

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library TypedArrays2Test; 5 library TypedArrays2Test;
6
6 import 'package:unittest/unittest.dart'; 7 import 'package:unittest/unittest.dart';
7 import 'package:unittest/html_config.dart'; 8 import 'package:unittest/html_config.dart';
8 import 'dart:html'; 9 import 'dart:html';
9 import 'dart:typed_data'; 10 import 'dart:typed_data';
10 11
11 main() { 12 main() {
12 useHtmlConfiguration(); 13 useHtmlConfiguration();
13 14
14 // Only perform tests if ArrayBuffer is supported. 15 // Only perform tests if ArrayBuffer is supported.
15 if (!Platform.supportsTypedData) { 16 if (!Platform.supportsTypedData) {
16 return; 17 return;
17 } 18 }
18 19
19 test('viewTest_dynamic', () { 20 test('viewTest_dynamic', () {
20 var a1 = new Uint8List(1024); 21 var a1 = new Uint8List(1024);
21 for (int i = 0; i < a1.length; i++) { 22 for (int i = 0; i < a1.length; i++) {
22 a1[i] = i; // 0,1,2,...,254,255,0,1,2,... 23 a1[i] = i; // 0,1,2,...,254,255,0,1,2,...
23 } 24 }
24 25
25 var a2 = new Uint32List.view(a1.buffer); 26 var a2 = new Uint32List.view(a1.buffer);
26 expect(1024 ~/ 4, a2.length); 27 expect(1024 ~/ 4, a2.length);
27 expect(a2[0], 0x03020100); 28 expect(a2[0], 0x03020100);
28 expect(a2[1], 0x07060504); 29 expect(a2[1], 0x07060504);
29 expect(a2[2], 0x0B0A0908); 30 expect(a2[2], 0x0B0A0908);
30 expect(a2[50], 0xCBCAC9C8); 31 expect(a2[50], 0xCBCAC9C8);
31 expect(a2[51], 0xCFCECDCC); 32 expect(a2[51], 0xCFCECDCC);
32 expect(a2[64], 0x03020100); 33 expect(a2[64], 0x03020100);
33 34
34 a2 = new Uint32List.view(a1.buffer, 200); 35 a2 = new Uint32List.view(a1.buffer, 200);
35 expect(a2.length, (1024 - 200) ~/ 4); 36 expect(a2.length, (1024 - 200) ~/ 4);
36 expect(a2[0], 0xCBCAC9C8); 37 expect(a2[0], 0xCBCAC9C8);
37 expect(a2[1], 0xCFCECDCC); 38 expect(a2[1], 0xCFCECDCC);
38 expect(a2[14], 0x03020100); 39 expect(a2[14], 0x03020100);
39 40
40 a2 = new Uint32List.view(a1.buffer, 456, 20); 41 a2 = new Uint32List.view(a1.buffer, 456, 20);
41 expect(a2.length, 20); 42 expect(a2.length, 20);
42 expect(a2[0], 0xCBCAC9C8); 43 expect(a2[0], 0xCBCAC9C8);
43 expect(a2[1], 0xCFCECDCC); 44 expect(a2[1], 0xCFCECDCC);
44 expect(a2[14], 0x03020100); 45 expect(a2[14], 0x03020100);
45 46
46 // OPTIONALS a2 = new Uint32List.view(a1.buffer, length: 30, byteOffset: 4 56); 47 // OPTIONALS a2 = new Uint32List.view(a1.buffer, length: 30, byteOffset: 456 );
47 a2 = new Uint32List.view(a1.buffer, 456, 30); 48 a2 = new Uint32List.view(a1.buffer, 456, 30);
48 expect(a2.length, 30); 49 expect(a2.length, 30);
49 expect(a2[0], 0xCBCAC9C8); 50 expect(a2[0], 0xCBCAC9C8);
50 expect(a2[1], 0xCFCECDCC); 51 expect(a2[1], 0xCFCECDCC);
51 expect(a2[14], 0x03020100); 52 expect(a2[14], 0x03020100);
52 }); 53 });
53 54
54 test('viewTest_typed', () { 55 test('viewTest_typed', () {
55 Uint8List a1 = new Uint8List(1024); 56 Uint8List a1 = new Uint8List(1024);
56 for (int i = 0; i < a1.length; i++) { 57 for (int i = 0; i < a1.length; i++) {
57 a1[i] = i; 58 a1[i] = i;
58 } 59 }
59 60
60 Uint32List a2 = new Uint32List.view(a1.buffer); 61 Uint32List a2 = new Uint32List.view(a1.buffer);
61 expect(a2.length, 1024 ~/ 4); 62 expect(a2.length, 1024 ~/ 4);
62 expect(a2[0], 0x03020100); 63 expect(a2[0], 0x03020100);
63 expect(a2[50], 0xCBCAC9C8); 64 expect(a2[50], 0xCBCAC9C8);
64 expect(a2[51], 0xCFCECDCC); 65 expect(a2[51], 0xCFCECDCC);
65 expect(a2[64], 0x03020100); 66 expect(a2[64], 0x03020100);
66 67
67 a2 = new Uint32List.view(a1.buffer, 200); 68 a2 = new Uint32List.view(a1.buffer, 200);
68 expect(a2.length, (1024 - 200) ~/ 4); 69 expect(a2.length, (1024 - 200) ~/ 4);
69 expect(a2[0], 0xCBCAC9C8); 70 expect(a2[0], 0xCBCAC9C8);
70 expect(a2[1], 0xCFCECDCC); 71 expect(a2[1], 0xCFCECDCC);
71 expect(a2[14], 0x03020100); 72 expect(a2[14], 0x03020100);
72 73
73 a2 = new Uint32List.view(a1.buffer, 456, 20); 74 a2 = new Uint32List.view(a1.buffer, 456, 20);
74 expect(20, a2.length); 75 expect(20, a2.length);
75 expect(a2[0], 0xCBCAC9C8); 76 expect(a2[0], 0xCBCAC9C8);
76 expect(a2[1], 0xCFCECDCC); 77 expect(a2[1], 0xCFCECDCC);
77 expect(a2[14], 0x03020100); 78 expect(a2[14], 0x03020100);
78 79
79 // OPTIONALS a2 = new Uint32List.view(a1.buffer, length: 30, byteOffset: 4 56); 80 // OPTIONALS a2 = new Uint32List.view(a1.buffer, length: 30, byteOffset: 456 );
80 a2 = new Uint32List.view(a1.buffer, 456, 30); 81 a2 = new Uint32List.view(a1.buffer, 456, 30);
81 expect(a2.length, 30); 82 expect(a2.length, 30);
82 expect(a2[0], 0xCBCAC9C8); 83 expect(a2[0], 0xCBCAC9C8);
83 expect(a2[1], 0xCFCECDCC); 84 expect(a2[1], 0xCFCECDCC);
84 expect(a2[14], 0x03020100); 85 expect(a2[14], 0x03020100);
85 }); 86 });
86 } 87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698