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 // Add elements, but not infinitely often. | 128 void add4(collection) { collection.add(4); } |
129 void add4(collection) { if (collection.length < 10) collection.add(4); } | |
130 void addList4(collection) { if (collection.length < 10) collection.add([4]); } | |
131 void put4(map) { map[4] = 4; } | 129 void put4(map) { map[4] = 4; } |
132 | 130 |
133 testModification([1, 2, 3], add4, id); | 131 testModification([1, 2, 3], add4, id); |
134 testModification(new HashSet()..add(1)..add(2)..add(3), add4, id); | 132 testModification(new HashSet()..add(1)..add(2)..add(3), add4, id); |
135 testModification(new LinkedHashSet()..add(1)..add(2)..add(3), add4, id); | 133 testModification(new LinkedHashSet()..add(1)..add(2)..add(3), add4, id); |
136 testModification(new SplayTreeSet()..add(1)..add(2)..add(3), add4, id); | 134 testModification(new SplayTreeSet()..add(1)..add(2)..add(3), add4, id); |
137 testModification(new MyList([1, 2, 3]), add4, id); | 135 testModification(new MyList([1, 2, 3]), add4, id); |
138 | 136 |
139 testModification([0, 1, 2, 3], add4, (x) => x.where((x) => x > 0)); | 137 testModification([0, 1, 2, 3], add4, (x) => x.where((x) => x > 0)); |
140 testModification([0, 1, 2], add4, (x) => x.map((x) => x + 1)); | 138 testModification([0, 1, 2], add4, (x) => x.map((x) => x + 1)); |
141 testModification([[1, 2], [3]], addList4, (x) => x.expand((x) => x)); | 139 testModification([[1, 2], [3]], add4, (x) => x.expand((x) => x)); |
142 testModification([3, 2, 1], add4, (x) => x.reversed); | 140 testModification([3, 2, 1], add4, (x) => x.reversed); |
143 testModification({1: 1, 2: 2, 3: 3}, put4, (x) => x.keys); | 141 testModification({1: 1, 2: 2, 3: 3}, put4, (x) => x.keys); |
144 testModification({1: 1, 2: 2, 3: 3}, put4, (x) => x.values); | 142 testModification({1: 1, 2: 2, 3: 3}, put4, (x) => x.values); |
145 var hashMap = new HashMap()..[1] = 1..[2] = 2..[3] = 3; | 143 var hashMap = new HashMap()..[1] = 1..[2] = 2..[3] = 3; |
146 testModification(hashMap, put4, (x) => x.keys); | 144 testModification(hashMap, put4, (x) => x.keys); |
147 hashMap = new HashMap()..[1] = 1..[2] = 2..[3] = 3; | 145 hashMap = new HashMap()..[1] = 1..[2] = 2..[3] = 3; |
148 testModification(hashMap, put4, (x) => x.values); | 146 testModification(hashMap, put4, (x) => x.values); |
149 var splayMap = new SplayTreeMap()..[1] = 1..[2] = 2..[3] = 3; | 147 var splayMap = new SplayTreeMap()..[1] = 1..[2] = 2..[3] = 3; |
150 testModification(splayMap, put4, (x) => x.keys); | 148 testModification(splayMap, put4, (x) => x.keys); |
151 splayMap = new SplayTreeMap()..[1] = 1..[2] = 2..[3] = 3; | 149 splayMap = new SplayTreeMap()..[1] = 1..[2] = 2..[3] = 3; |
152 testModification(splayMap, put4, (x) => x.values); | 150 testModification(splayMap, put4, (x) => x.values); |
153 } | 151 } |
OLD | NEW |