OLD | NEW |
---|---|
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"; | 7 import "dart:typed_data"; |
8 | 8 |
9 import "package:test/test.dart"; | 9 import "package:test/test.dart"; |
10 import "package:typed_data/typed_buffers.dart"; | 10 import "package:typed_data/typed_buffers.dart"; |
(...skipping 17 matching lines...) Expand all Loading... | |
28 | 28 |
29 testInt32x4Buffer(intSamples); | 29 testInt32x4Buffer(intSamples); |
30 | 30 |
31 List roundedFloatSamples = floatSamples.map(roundToFloat).toList(); | 31 List roundedFloatSamples = floatSamples.map(roundToFloat).toList(); |
32 testFloatBuffer(32, roundedFloatSamples, | 32 testFloatBuffer(32, roundedFloatSamples, |
33 () => new Float32Buffer(), | 33 () => new Float32Buffer(), |
34 roundToFloat); | 34 roundToFloat); |
35 testFloatBuffer(64, doubleSamples, () => new Float64Buffer(), (x) => x); | 35 testFloatBuffer(64, doubleSamples, () => new Float64Buffer(), (x) => x); |
36 | 36 |
37 testFloat32x4Buffer(roundedFloatSamples); | 37 testFloat32x4Buffer(roundedFloatSamples); |
38 | |
39 group("addAll", () { | |
40 for (var type in ['list', 'iterable']) { | |
41 group("with a${type == 'list' ? '' : 'n'} $type", () { | |
Lasse Reichstein Nielsen
2015/10/15 10:58:25
You could just make the string "a list" and "an it
nweiz
2015/10/15 20:14:10
Done.
| |
42 var source; | |
43 var buffer; | |
44 setUp(() { | |
45 source = [1, 2, 3, 4, 5]; | |
46 if (type == 'iterable') source = source.reversed.toList().reversed; | |
47 buffer = new Uint8Buffer(); | |
48 }); | |
49 | |
50 test("adds values to the buffer", () { | |
51 buffer.addAll(source, 1, 4); | |
52 expect(buffer, equals([2, 3, 4])); | |
53 | |
54 buffer.addAll(source, 4); | |
55 expect(buffer, equals([2, 3, 4, 5])); | |
56 | |
57 buffer.addAll(source, 0, 1); | |
58 expect(buffer, equals([2, 3, 4, 5, 1])); | |
59 }); | |
60 | |
61 test("does nothing for empty slices", () { | |
62 buffer.addAll([6, 7, 8, 9, 10]); | |
63 | |
64 buffer.addAll(source, 0, 0); | |
65 expect(buffer, equals([6, 7, 8, 9, 10])); | |
66 | |
67 buffer.addAll(source, 3, 3); | |
68 expect(buffer, equals([6, 7, 8, 9, 10])); | |
69 | |
70 buffer.addAll(source, 5); | |
71 expect(buffer, equals([6, 7, 8, 9, 10])); | |
72 }); | |
73 | |
74 test("throws errors for invalid start and end", () { | |
75 expect(() => buffer.addAll(source, -1), throwsRangeError); | |
76 expect(() => buffer.addAll(source, 10), throwsRangeError); | |
77 expect(() => buffer.addAll(source, 3, 2), throwsRangeError); | |
78 expect(() => buffer.addAll(source, 3, 10), throwsRangeError); | |
79 expect(() => buffer.addAll(source, 3, -1), throwsRangeError); | |
Lasse Reichstein Nielsen
2015/10/15 10:58:25
This is where I think #2 and #4 should not be erro
nweiz
2015/10/15 20:14:10
AFAICT this would be inconsistent with existing me
Lasse Reichstein Nielsen
2015/10/20 08:09:49
Only accidentally. Ranges on iterables should gene
| |
80 }); | |
81 }); | |
82 } | |
83 }); | |
38 } | 84 } |
39 | 85 |
40 double roundToFloat(double value) { | 86 double roundToFloat(double value) { |
41 return (new Float32List(1)..[0] = value)[0]; | 87 return (new Float32List(1)..[0] = value)[0]; |
42 } | 88 } |
43 | 89 |
44 typedef int Rounder(int value); | 90 typedef int Rounder(int value); |
45 | 91 |
46 Rounder roundUint(bits) { | 92 Rounder roundUint(bits) { |
47 int halfbits = (1 << (bits ~/ 2)) - 1; | 93 int halfbits = (1 << (bits ~/ 2)) - 1; |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 bool matches(item, Map matchState) { | 463 bool matches(item, Map matchState) { |
418 if (item is! Int32x4) return false; | 464 if (item is! Int32x4) return false; |
419 Int32x4 value = item; | 465 Int32x4 value = item; |
420 return result.x == value.x && result.y == value.y && | 466 return result.x == value.x && result.y == value.y && |
421 result.z == value.z && result.w == value.w; | 467 result.z == value.z && result.w == value.w; |
422 } | 468 } |
423 | 469 |
424 Description describe(Description description) => | 470 Description describe(Description description) => |
425 description.add('Int32x4.=='); | 471 description.add('Int32x4.=='); |
426 } | 472 } |
OLD | NEW |