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

Unified Diff: tests/corelib/iterable_reduce_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 side-by-side diff with in-line comments
Download patch
Index: tests/corelib/iterable_reduce_test.dart
diff --git a/tests/corelib/iterable_reduce_test.dart b/tests/corelib/iterable_reduce_test.dart
index 492ce9c6871937754d715094d977b0a5ebce43f2..755a749eb92fca4f4fe9978cab00f6cc6adf44ca 100644
--- a/tests/corelib/iterable_reduce_test.dart
+++ b/tests/corelib/iterable_reduce_test.dart
@@ -11,7 +11,9 @@ class MyList extends ListBase {
MyList(this.list);
get length => list.length;
- set length(val) { list.length = val; }
+ set length(val) {
+ list.length = val;
+ }
operator [](index) => list[index];
operator []=(index, val) => list[index] = val;
@@ -22,95 +24,127 @@ id(x) => x;
main() {
// Test functionality.
for (var iterable in [
- const [1, 2, 3],
- [1, 2, 3],
- new List(3)..[0] = 1..[1] = 2..[2] = 3,
- {1: 1, 2: 2, 3: 3}.keys,
- {1: 1, 2: 2, 3: 3}.values,
- new Iterable.generate(3, (x) => x + 1),
- new List.generate(3, (x) => x + 1),
- [0, 1, 2, 3].where((x) => x > 0),
- [0, 1, 2].map((x) => x + 1),
- [[1, 2], [3]].expand(id),
- [3, 2, 1].reversed,
- [0, 1, 2, 3].skip(1),
- [1, 2, 3, 4].take(3),
- new Uint8List(3)..[0] = 1..[1] = 2..[2] = 3,
- (new HashMap()..[1] = 1..[2] = 2..[3] = 3).keys,
- (new HashMap()..[1] = 1..[2] = 2..[3] = 3).values,
- (new SplayTreeMap()..[1] = 0..[2] = 0..[3] = 0).keys,
- (new SplayTreeMap()..[0] = 1..[1] = 2..[2] = 3).values,
- new HashSet()..add(1)..add(2)..add(3),
- new LinkedHashSet()..add(1)..add(2)..add(3),
- new SplayTreeSet()..add(1)..add(2)..add(3),
- "\x01\x02\x03".codeUnits,
- "\x01\x02\x03".runes,
- new MyList([1, 2, 3]),
- ]) {
+ const [1, 2, 3],
+ [1, 2, 3],
+ new List(3)
+ ..[0] = 1
+ ..[1] = 2
+ ..[2] = 3,
+ {1: 1, 2: 2, 3: 3}.keys,
+ {1: 1, 2: 2, 3: 3}.values,
+ new Iterable.generate(3, (x) => x + 1),
+ new List.generate(3, (x) => x + 1),
+ [0, 1, 2, 3].where((x) => x > 0),
+ [0, 1, 2].map((x) => x + 1),
+ [
+ [1, 2],
+ [3]
+ ].expand(id),
+ [3, 2, 1].reversed,
+ [0, 1, 2, 3].skip(1),
+ [1, 2, 3, 4].take(3),
+ new Uint8List(3)
+ ..[0] = 1
+ ..[1] = 2
+ ..[2] = 3,
+ (new HashMap()
+ ..[1] = 1
+ ..[2] = 2
+ ..[3] = 3)
+ .keys,
+ (new HashMap()
+ ..[1] = 1
+ ..[2] = 2
+ ..[3] = 3)
+ .values,
+ (new SplayTreeMap()
+ ..[1] = 0
+ ..[2] = 0
+ ..[3] = 0)
+ .keys,
+ (new SplayTreeMap()
+ ..[0] = 1
+ ..[1] = 2
+ ..[2] = 3)
+ .values,
+ new HashSet()..add(1)..add(2)..add(3),
+ new LinkedHashSet()..add(1)..add(2)..add(3),
+ new SplayTreeSet()..add(1)..add(2)..add(3),
+ "\x01\x02\x03".codeUnits,
+ "\x01\x02\x03".runes,
+ new MyList([1, 2, 3]),
+ ]) {
int callCount = 0;
- var result = iterable.reduce((x, y) { callCount++; return x + y; });
+ var result = iterable.reduce((x, y) {
+ callCount++;
+ return x + y;
+ });
Expect.equals(6, result, "${iterable.runtimeType}");
Expect.equals(2, callCount);
}
// Empty iterables not allowed.
for (var iterable in [
- const [],
- [],
- new List(0),
- {}.keys,
- {}.values,
- new Iterable.generate(0, (x) => x + 1),
- new List.generate(0, (x) => x + 1),
- [0, 1, 2, 3].where((x) => false),
- [].map((x) => x + 1),
- [[], []].expand(id),
- [].reversed,
- [0, 1, 2, 3].skip(4),
- [1, 2, 3, 4].take(0),
- new Uint8List(0),
- (new HashMap()).keys,
- (new HashMap()).values,
- (new SplayTreeMap()).keys,
- (new SplayTreeMap()).values,
- new HashSet(),
- new LinkedHashSet(),
- new SplayTreeSet(),
- "".codeUnits,
- "".runes,
- new MyList([]),
- ]) {
- Expect.throws(() { iterable.reduce((x, y) => throw "Unreachable"); },
- (e) => e is StateError);
+ const [],
+ [],
+ new List(0),
+ {}.keys,
+ {}.values,
+ new Iterable.generate(0, (x) => x + 1),
+ new List.generate(0, (x) => x + 1),
+ [0, 1, 2, 3].where((x) => false),
+ [].map((x) => x + 1),
+ [[], []].expand(id),
+ [].reversed,
+ [0, 1, 2, 3].skip(4),
+ [1, 2, 3, 4].take(0),
+ new Uint8List(0),
+ (new HashMap()).keys,
+ (new HashMap()).values,
+ (new SplayTreeMap()).keys,
+ (new SplayTreeMap()).values,
+ new HashSet(),
+ new LinkedHashSet(),
+ new SplayTreeSet(),
+ "".codeUnits,
+ "".runes,
+ new MyList([]),
+ ]) {
+ Expect.throws(() {
+ iterable.reduce((x, y) => throw "Unreachable");
+ }, (e) => e is StateError);
}
// Singleton iterables not calling reduce function.
for (var iterable in [
- const [1],
- [1],
- new List(1)..[0] = 1,
- {1: 1}.keys,
- {1: 1}.values,
- new Iterable.generate(1, (x) => x + 1),
- new List.generate(1, (x) => x + 1),
- [0, 1, 2, 3].where((x) => x == 1),
- [0].map((x) => x + 1),
- [[], [1]].expand(id),
- [1].reversed,
- [0, 1].skip(1),
- [1, 2, 3, 4].take(1),
- new Uint8List(1)..[0] = 1,
- (new HashMap()..[1] = 0).keys,
- (new HashMap()..[0] = 1).values,
- (new SplayTreeMap()..[1] = 0).keys,
- (new SplayTreeMap()..[0] = 1).values,
- new HashSet()..add(1),
- new LinkedHashSet()..add(1),
- new SplayTreeSet()..add(1),
- "\x01".codeUnits,
- "\x01".runes,
- new MyList([1]),
- ]) {
+ const [1],
+ [1],
+ new List(1)..[0] = 1,
+ {1: 1}.keys,
+ {1: 1}.values,
+ new Iterable.generate(1, (x) => x + 1),
+ new List.generate(1, (x) => x + 1),
+ [0, 1, 2, 3].where((x) => x == 1),
+ [0].map((x) => x + 1),
+ [
+ [],
+ [1]
+ ].expand(id),
+ [1].reversed,
+ [0, 1].skip(1),
+ [1, 2, 3, 4].take(1),
+ new Uint8List(1)..[0] = 1,
+ (new HashMap()..[1] = 0).keys,
+ (new HashMap()..[0] = 1).values,
+ (new SplayTreeMap()..[1] = 0).keys,
+ (new SplayTreeMap()..[0] = 1).values,
+ new HashSet()..add(1),
+ new LinkedHashSet()..add(1),
+ new SplayTreeSet()..add(1),
+ "\x01".codeUnits,
+ "\x01".runes,
+ new MyList([1]),
+ ]) {
Expect.equals(1, iterable.reduce((x, y) => throw "Unreachable"));
}
@@ -125,8 +159,13 @@ main() {
}, (e) => e is ConcurrentModificationError);
}
- void add4(collection) { collection.add(4); }
- void put4(map) { map[4] = 4; }
+ void add4(collection) {
+ collection.add(4);
+ }
+
+ void put4(map) {
+ map[4] = 4;
+ }
testModification([1, 2, 3], add4, id);
testModification(new HashSet()..add(1)..add(2)..add(3), add4, id);
@@ -136,16 +175,31 @@ main() {
testModification([0, 1, 2, 3], add4, (x) => x.where((x) => x > 0));
testModification([0, 1, 2], add4, (x) => x.map((x) => x + 1));
- testModification([[1, 2], [3]], add4, (x) => x.expand((x) => x));
+ testModification([
+ [1, 2],
+ [3]
+ ], add4, (x) => x.expand((x) => x));
testModification([3, 2, 1], add4, (x) => x.reversed);
testModification({1: 1, 2: 2, 3: 3}, put4, (x) => x.keys);
testModification({1: 1, 2: 2, 3: 3}, put4, (x) => x.values);
- var hashMap = new HashMap()..[1] = 1..[2] = 2..[3] = 3;
+ var hashMap = new HashMap()
+ ..[1] = 1
+ ..[2] = 2
+ ..[3] = 3;
testModification(hashMap, put4, (x) => x.keys);
- hashMap = new HashMap()..[1] = 1..[2] = 2..[3] = 3;
+ hashMap = new HashMap()
+ ..[1] = 1
+ ..[2] = 2
+ ..[3] = 3;
testModification(hashMap, put4, (x) => x.values);
- var splayMap = new SplayTreeMap()..[1] = 1..[2] = 2..[3] = 3;
+ var splayMap = new SplayTreeMap()
+ ..[1] = 1
+ ..[2] = 2
+ ..[3] = 3;
testModification(splayMap, put4, (x) => x.keys);
- splayMap = new SplayTreeMap()..[1] = 1..[2] = 2..[3] = 3;
+ splayMap = new SplayTreeMap()
+ ..[1] = 1
+ ..[2] = 2
+ ..[3] = 3;
testModification(splayMap, put4, (x) => x.values);
}

Powered by Google App Engine
This is Rietveld 408576698