OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 import 'dart:collection'; | 6 import 'dart:collection'; |
7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
8 | 8 |
9 class MyList extends ListBase { | 9 class MyList extends ListBase { |
10 List list; | 10 List list; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 testModification(base, modify, transform) { | 118 testModification(base, modify, transform) { |
119 var iterable = transform(base); | 119 var iterable = transform(base); |
120 Expect.throws(() { | 120 Expect.throws(() { |
121 iterable.reduce((x, y) { | 121 iterable.reduce((x, y) { |
122 modify(base); | 122 modify(base); |
123 return x + y; | 123 return x + y; |
124 }); | 124 }); |
125 }, (e) => e is ConcurrentModificationError); | 125 }, (e) => e is ConcurrentModificationError); |
126 } | 126 } |
127 | 127 |
128 void add4(collection) { collection.add(4); } | 128 // Add elements, but not infinitely often. |
| 129 void add4(collection) { if (collection.length < 10) collection.add(4); } |
| 130 void addList4(collection) { if (collection.length < 10) collection.add([4]); } |
129 void put4(map) { map[4] = 4; } | 131 void put4(map) { map[4] = 4; } |
130 | 132 |
131 testModification([1, 2, 3], add4, id); | 133 testModification([1, 2, 3], add4, id); |
132 testModification(new HashSet()..add(1)..add(2)..add(3), add4, id); | 134 testModification(new HashSet()..add(1)..add(2)..add(3), add4, id); |
133 testModification(new LinkedHashSet()..add(1)..add(2)..add(3), add4, id); | 135 testModification(new LinkedHashSet()..add(1)..add(2)..add(3), add4, id); |
134 testModification(new SplayTreeSet()..add(1)..add(2)..add(3), add4, id); | 136 testModification(new SplayTreeSet()..add(1)..add(2)..add(3), add4, id); |
135 testModification(new MyList([1, 2, 3]), add4, id); | 137 testModification(new MyList([1, 2, 3]), add4, id); |
136 | 138 |
137 testModification([0, 1, 2, 3], add4, (x) => x.where((x) => x > 0)); | 139 testModification([0, 1, 2, 3], add4, (x) => x.where((x) => x > 0)); |
138 testModification([0, 1, 2], add4, (x) => x.map((x) => x + 1)); | 140 testModification([0, 1, 2], add4, (x) => x.map((x) => x + 1)); |
139 testModification([[1, 2], [3]], add4, (x) => x.expand((x) => x)); | 141 testModification([[1, 2], [3]], addList4, (x) => x.expand((x) => x)); |
140 testModification([3, 2, 1], add4, (x) => x.reversed); | 142 testModification([3, 2, 1], add4, (x) => x.reversed); |
141 testModification({1: 1, 2: 2, 3: 3}, put4, (x) => x.keys); | 143 testModification({1: 1, 2: 2, 3: 3}, put4, (x) => x.keys); |
142 testModification({1: 1, 2: 2, 3: 3}, put4, (x) => x.values); | 144 testModification({1: 1, 2: 2, 3: 3}, put4, (x) => x.values); |
143 var hashMap = new HashMap()..[1] = 1..[2] = 2..[3] = 3; | 145 var hashMap = new HashMap()..[1] = 1..[2] = 2..[3] = 3; |
144 testModification(hashMap, put4, (x) => x.keys); | 146 testModification(hashMap, put4, (x) => x.keys); |
145 hashMap = new HashMap()..[1] = 1..[2] = 2..[3] = 3; | 147 hashMap = new HashMap()..[1] = 1..[2] = 2..[3] = 3; |
146 testModification(hashMap, put4, (x) => x.values); | 148 testModification(hashMap, put4, (x) => x.values); |
147 var splayMap = new SplayTreeMap()..[1] = 1..[2] = 2..[3] = 3; | 149 var splayMap = new SplayTreeMap()..[1] = 1..[2] = 2..[3] = 3; |
148 testModification(splayMap, put4, (x) => x.keys); | 150 testModification(splayMap, put4, (x) => x.keys); |
149 splayMap = new SplayTreeMap()..[1] = 1..[2] = 2..[3] = 3; | 151 splayMap = new SplayTreeMap()..[1] = 1..[2] = 2..[3] = 3; |
150 testModification(splayMap, put4, (x) => x.values); | 152 testModification(splayMap, put4, (x) => x.values); |
151 } | 153 } |
OLD | NEW |