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

Side by Side Diff: test/typed_buffers_test.dart

Issue 1385333007: Use the new test runner. (Closed) Base URL: git@github.com:dart-lang/typed_data@master
Patch Set: Code review changes Created 5 years, 2 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
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // Tests typed-data buffer classes. 5 // Tests typed-data buffer classes.
6 6
7 import "dart:typed_data";
8
9 import "package:test/test.dart";
7 import "package:typed_data/typed_buffers.dart"; 10 import "package:typed_data/typed_buffers.dart";
8 import "package:unittest/unittest.dart";
9 import "dart:typed_data";
10 11
11 main() { 12 main() {
12 testUint(8, (l) => new Uint8Buffer(l)); 13 testUint(8, (l) => new Uint8Buffer(l));
13 testInt(8, (l) => new Int8Buffer(l)); 14 testInt(8, (l) => new Int8Buffer(l));
14 test("Uint8ClampedBuffer", () { 15 test("Uint8ClampedBuffer", () {
15 testIntBuffer(8, 0, 255, (l) => new Uint8ClampedBuffer(l), clampUint8); 16 testIntBuffer(8, 0, 255, (l) => new Uint8ClampedBuffer(l), clampUint8);
16 }); 17 });
17 testUint(16, (l) => new Uint16Buffer(l)); 18 testUint(16, (l) => new Uint16Buffer(l));
18 testInt(16, (l) => new Int16Buffer(l)); 19 testInt(16, (l) => new Int16Buffer(l));
19 testUint(32, (l) => new Uint32Buffer(l)); /// 01: ok 20 testUint(32, (l) => new Uint32Buffer(l)); /// 01: ok
20 testInt(32, (l) => new Int32Buffer(l)); 21 testInt(32, (l) => new Int32Buffer(l));
21 testUint(64, (l) => new Uint64Buffer(l)); /// 01: continued 22 testUint(64, (l) => new Uint64Buffer(l), /// 01: continued
22 testInt(64, (l) => new Int64Buffer(l)); /// 01: continued 23 // JS doesn't support 64-bit ints, so only test this on the VM.
24 testOn: "dart-vm");
25 testInt(64, (l) => new Int64Buffer(l), /// 01: continued
26 // JS doesn't support 64-bit ints, so only test this on the VM.
27 testOn: "dart-vm");
23 28
24 testInt32x4Buffer(intSamples); 29 testInt32x4Buffer(intSamples);
25 30
26 List roundedFloatSamples = floatSamples.map(roundToFloat).toList(); 31 List roundedFloatSamples = floatSamples.map(roundToFloat).toList();
27 testFloatBuffer(32, roundedFloatSamples, 32 testFloatBuffer(32, roundedFloatSamples,
28 () => new Float32Buffer(), 33 () => new Float32Buffer(),
29 roundToFloat); 34 roundToFloat);
30 testFloatBuffer(64, doubleSamples, () => new Float64Buffer(), (x) => x); 35 testFloatBuffer(64, doubleSamples, () => new Float64Buffer(), (x) => x);
31 36
32 testFloat32x4Buffer(roundedFloatSamples); 37 testFloat32x4Buffer(roundedFloatSamples);
(...skipping 12 matching lines...) Expand all
45 } 50 }
46 51
47 Rounder roundInt(bits) { 52 Rounder roundInt(bits) {
48 int highBit = 1 << (bits - 1); 53 int highBit = 1 << (bits - 1);
49 int mask = highBit - 1; 54 int mask = highBit - 1;
50 return (int x) => (x & mask) - (x & highBit); 55 return (int x) => (x & mask) - (x & highBit);
51 } 56 }
52 57
53 int clampUint8(x) => x < 0 ? 0 : x > 255 ? 255 : x; 58 int clampUint8(x) => x < 0 ? 0 : x > 255 ? 255 : x;
54 59
55 void testUint(int bits, var buffer) { 60 void testUint(int bits, var buffer, {String testOn}) {
56 int min = 0; 61 int min = 0;
57 Function round = roundUint(bits); 62 Function round = roundUint(bits);
58 int max = round(-1); 63 int max = round(-1);
59 test("Uint${bits}Buffer", () { 64 test("Uint${bits}Buffer", () {
60 testIntBuffer(bits, min, max, buffer, round); 65 testIntBuffer(bits, min, max, buffer, round);
61 }); 66 }, testOn: testOn);
62 } 67 }
63 68
64 void testInt(int bits, var buffer) { 69 void testInt(int bits, var buffer, {String testOn}) {
65 int min = -(1 << (bits - 1)); 70 int min = -(1 << (bits - 1));
66 int max = -(min + 1); 71 int max = -(min + 1);
67 test("Int${bits}Buffer", () { 72 test("Int${bits}Buffer", () {
68 testIntBuffer(bits, min, max, buffer, roundInt(bits)); 73 testIntBuffer(bits, min, max, buffer, roundInt(bits));
69 }); 74 }, testOn: testOn);
70 } 75 }
71 76
72 const List<int> intSamples = const [ 77 const List<int> intSamples = const [
73 0x10000000000000001, 78 0x10000000000000001,
74 0x10000000000000000, // 2^64 79 0x10000000000000000, // 2^64
75 0x0ffffffffffffffff, 80 0x0ffffffffffffffff,
76 0xaaaaaaaaaaaaaaaa, 81 0xaaaaaaaaaaaaaaaa,
77 0x8000000000000001, 82 0x8000000000000001,
78 0x8000000000000000, // 2^63 83 0x8000000000000000, // 2^63
79 0x7fffffffffffffff, 84 0x7fffffffffffffff,
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 bool matches(item, Map matchState) { 417 bool matches(item, Map matchState) {
413 if (item is! Int32x4) return false; 418 if (item is! Int32x4) return false;
414 Int32x4 value = item; 419 Int32x4 value = item;
415 return result.x == value.x && result.y == value.y && 420 return result.x == value.x && result.y == value.y &&
416 result.z == value.z && result.w == value.w; 421 result.z == value.z && result.w == value.w;
417 } 422 }
418 423
419 Description describe(Description description) => 424 Description describe(Description description) =>
420 description.add('Int32x4.=='); 425 description.add('Int32x4.==');
421 } 426 }
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698