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:collection/collection.dart"; | 5 import "package:collection/collection.dart"; |
6 import "package:test/test.dart"; | 6 import "package:test/test.dart"; |
7 | 7 |
8 void main() { | 8 void main() { |
9 group("new QueueList()", () { | 9 group("new QueueList()", () { |
10 test("creates an empty QueueList", () { | 10 test("creates an empty QueueList", () { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 }); | 62 }); |
63 }); | 63 }); |
64 | 64 |
65 group("removeFirst()", () { | 65 group("removeFirst()", () { |
66 test("removes an element from the beginning of the queue", () { | 66 test("removes an element from the beginning of the queue", () { |
67 var queue = new QueueList.from([1, 2, 3]); | 67 var queue = new QueueList.from([1, 2, 3]); |
68 expect(queue.removeFirst(), equals(1)); | 68 expect(queue.removeFirst(), equals(1)); |
69 expect(queue, equals([2, 3])); | 69 expect(queue, equals([2, 3])); |
70 }); | 70 }); |
71 | 71 |
72 test("removes an element from the beginning of a queue with an internal " | 72 test( |
| 73 "removes an element from the beginning of a queue with an internal " |
73 "gap", () { | 74 "gap", () { |
74 var queue = withInternalGap(); | 75 var queue = withInternalGap(); |
75 expect(queue.removeFirst(), equals(1)); | 76 expect(queue.removeFirst(), equals(1)); |
76 expect(queue, equals([2, 3, 4, 5, 6, 7])); | 77 expect(queue, equals([2, 3, 4, 5, 6, 7])); |
77 }); | 78 }); |
78 | 79 |
79 test("removes an element from the beginning of a queue at capacity", () { | 80 test("removes an element from the beginning of a queue at capacity", () { |
80 var queue = atCapacity(); | 81 var queue = atCapacity(); |
81 expect(queue.removeFirst(), equals(1)); | 82 expect(queue.removeFirst(), equals(1)); |
82 expect(queue, equals([2, 3, 4, 5, 6, 7])); | 83 expect(queue, equals([2, 3, 4, 5, 6, 7])); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 expect(queue[4], equals(5)); | 161 expect(queue[4], equals(5)); |
161 expect(queue[5], equals(6)); | 162 expect(queue[5], equals(6)); |
162 expect(queue[6], equals(7)); | 163 expect(queue[6], equals(7)); |
163 }); | 164 }); |
164 | 165 |
165 test("throws a RangeError if the index is less than 0", () { | 166 test("throws a RangeError if the index is less than 0", () { |
166 var queue = new QueueList.from([1, 2, 3]); | 167 var queue = new QueueList.from([1, 2, 3]); |
167 expect(() => queue[-1], throwsRangeError); | 168 expect(() => queue[-1], throwsRangeError); |
168 }); | 169 }); |
169 | 170 |
170 test("throws a RangeError if the index is greater than or equal to the " | 171 test( |
| 172 "throws a RangeError if the index is greater than or equal to the " |
171 "length", () { | 173 "length", () { |
172 var queue = new QueueList.from([1, 2, 3]); | 174 var queue = new QueueList.from([1, 2, 3]); |
173 expect(() => queue[3], throwsRangeError); | 175 expect(() => queue[3], throwsRangeError); |
174 }); | 176 }); |
175 }); | 177 }); |
176 | 178 |
177 group("[]=", () { | 179 group("[]=", () { |
178 test("sets individual entries in the queue", () { | 180 test("sets individual entries in the queue", () { |
179 var queue = new QueueList.from([1, 2, 3]); | 181 var queue = new QueueList<dynamic>.from([1, 2, 3]); |
180 queue[0] = "a"; | 182 queue[0] = "a"; |
181 queue[1] = "b"; | 183 queue[1] = "b"; |
182 queue[2] = "c"; | 184 queue[2] = "c"; |
183 expect(queue, equals(["a", "b", "c"])); | 185 expect(queue, equals(["a", "b", "c"])); |
184 }); | 186 }); |
185 | 187 |
186 test("sets individual entries in a queue with an internal gap", () { | 188 test("sets individual entries in a queue with an internal gap", () { |
187 var queue = withInternalGap(); | 189 var queue = withInternalGap(); |
188 queue[0] = "a"; | 190 queue[0] = "a"; |
189 queue[1] = "b"; | 191 queue[1] = "b"; |
190 queue[2] = "c"; | 192 queue[2] = "c"; |
191 queue[3] = "d"; | 193 queue[3] = "d"; |
192 queue[4] = "e"; | 194 queue[4] = "e"; |
193 queue[5] = "f"; | 195 queue[5] = "f"; |
194 queue[6] = "g"; | 196 queue[6] = "g"; |
195 expect(queue, equals(["a", "b", "c", "d", "e", "f", "g"])); | 197 expect(queue, equals(["a", "b", "c", "d", "e", "f", "g"])); |
196 }); | 198 }); |
197 | 199 |
198 test("throws a RangeError if the index is less than 0", () { | 200 test("throws a RangeError if the index is less than 0", () { |
199 var queue = new QueueList.from([1, 2, 3]); | 201 var queue = new QueueList.from([1, 2, 3]); |
200 expect(() { | 202 expect(() { |
201 queue[-1] = 0; | 203 queue[-1] = 0; |
202 }, throwsRangeError); | 204 }, throwsRangeError); |
203 }); | 205 }); |
204 | 206 |
205 test("throws a RangeError if the index is greater than or equal to the " | 207 test( |
| 208 "throws a RangeError if the index is greater than or equal to the " |
206 "length", () { | 209 "length", () { |
207 var queue = new QueueList.from([1, 2, 3]); | 210 var queue = new QueueList.from([1, 2, 3]); |
208 expect(() { | 211 expect(() { |
209 queue[3] = 4; | 212 queue[3] = 4; |
210 }, throwsRangeError); | 213 }, throwsRangeError); |
211 }); | 214 }); |
212 }); | 215 }); |
213 | 216 |
214 group("throws a modification error for", () { | 217 group("throws a modification error for", () { |
215 var queue; | 218 var queue; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 queue.removeFirst(); | 267 queue.removeFirst(); |
265 } | 268 } |
266 for (var i = 5; i < 8; i++) { | 269 for (var i = 5; i < 8; i++) { |
267 queue.addLast(i); | 270 queue.addLast(i); |
268 } | 271 } |
269 return queue; | 272 return queue; |
270 } | 273 } |
271 | 274 |
272 /// Returns a matcher that expects that a closure throws a | 275 /// Returns a matcher that expects that a closure throws a |
273 /// [ConcurrentModificationError]. | 276 /// [ConcurrentModificationError]. |
274 final throwsConcurrentModificationError = throwsA( | 277 final throwsConcurrentModificationError = |
275 new isInstanceOf<ConcurrentModificationError>()); | 278 throwsA(new isInstanceOf<ConcurrentModificationError>()); |
OLD | NEW |