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

Unified Diff: test/typed_buffers_test.dart

Issue 1404443005: Add _TypedDataBuffer.addRange. (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 side-by-side diff with in-line comments
Download patch
« lib/typed_buffers.dart ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/typed_buffers_test.dart
diff --git a/test/typed_buffers_test.dart b/test/typed_buffers_test.dart
index b5f907cd8e21caa4b049888541180f129efa2ae3..fab80a1ef341e596dc05293631b7e3eed1e5eb2c 100644
--- a/test/typed_buffers_test.dart
+++ b/test/typed_buffers_test.dart
@@ -35,6 +35,52 @@ main() {
testFloatBuffer(64, doubleSamples, () => new Float64Buffer(), (x) => x);
testFloat32x4Buffer(roundedFloatSamples);
+
+ group("addAll", () {
+ for (var type in ['list', 'iterable']) {
+ 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.
+ var source;
+ var buffer;
+ setUp(() {
+ source = [1, 2, 3, 4, 5];
+ if (type == 'iterable') source = source.reversed.toList().reversed;
+ buffer = new Uint8Buffer();
+ });
+
+ test("adds values to the buffer", () {
+ buffer.addAll(source, 1, 4);
+ expect(buffer, equals([2, 3, 4]));
+
+ buffer.addAll(source, 4);
+ expect(buffer, equals([2, 3, 4, 5]));
+
+ buffer.addAll(source, 0, 1);
+ expect(buffer, equals([2, 3, 4, 5, 1]));
+ });
+
+ test("does nothing for empty slices", () {
+ buffer.addAll([6, 7, 8, 9, 10]);
+
+ buffer.addAll(source, 0, 0);
+ expect(buffer, equals([6, 7, 8, 9, 10]));
+
+ buffer.addAll(source, 3, 3);
+ expect(buffer, equals([6, 7, 8, 9, 10]));
+
+ buffer.addAll(source, 5);
+ expect(buffer, equals([6, 7, 8, 9, 10]));
+ });
+
+ test("throws errors for invalid start and end", () {
+ expect(() => buffer.addAll(source, -1), throwsRangeError);
+ expect(() => buffer.addAll(source, 10), throwsRangeError);
+ expect(() => buffer.addAll(source, 3, 2), throwsRangeError);
+ expect(() => buffer.addAll(source, 3, 10), throwsRangeError);
+ 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
+ });
+ });
+ }
+ });
}
double roundToFloat(double value) {
« lib/typed_buffers.dart ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698