2 Copyright (c) 2003-2006 Niels Kokholm and Peter Sestoft
3 Permission is hereby granted, free of charge, to any person obtaining a copy
4 of this software and associated documentation files (the "Software"), to deal
5 in the Software without restriction, including without limitation the rights
6 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 copies of the Software, and to permit persons to whom the Software is
8 furnished to do so, subject to the following conditions:
10 The above copyright notice and this permission notice shall be included in
11 all copies or substantial portions of the Software.
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 using NUnit
.Framework
;
25 using SCG
= System
.Collections
.Generic
;
26 using System
.Reflection
;
28 namespace C5UnitTests
.Templates
.Events
30 public abstract class CollectionValueTester
<TCollection
, TItem
> : GenericCollectionTester
<TCollection
, EventTypeEnum
>
31 where TCollection
: ICollectionValue
<TItem
>
33 protected TCollection collection
;
34 protected CollectionEventList
<TItem
> seen
;
35 protected EventTypeEnum listenTo
;
36 protected void listen() { seen.Listen(collection, listenTo); }
38 public override void SetUp(TCollection list
, EventTypeEnum testSpec
)
40 this.collection
= list
;
42 seen
= new CollectionEventList
<TItem
>(EqualityComparer
<TItem
>.Default
);
45 public SCG
.IEnumerable
<EventTypeEnum
> SpecsNone
49 CircularQueue
<EventTypeEnum
> specs
= new CircularQueue
<EventTypeEnum
>();
53 public SCG
.IEnumerable
<EventTypeEnum
> SpecsBasic
57 CircularQueue
<EventTypeEnum
> specs
= new CircularQueue
<EventTypeEnum
>();
58 //foreach (EventTypeEnum listenTo in Enum.GetValues(typeof(EventTypeEnum)))
59 // if ((listenTo & ~EventTypeEnum.Basic) == 0)
60 // specs.Enqueue(listenTo);
61 //specs.Enqueue(EventTypeEnum.Added | EventTypeEnum.Removed);
62 for (int spec
= 0; spec
<= (int)EventTypeEnum
.Basic
; spec
++)
63 specs
.Enqueue((EventTypeEnum
)spec
);
67 public SCG
.IEnumerable
<EventTypeEnum
> SpecsAll
71 CircularQueue
<EventTypeEnum
> specs
= new CircularQueue
<EventTypeEnum
>();
72 //foreach (EventTypeEnum listenTo in Enum.GetValues(typeof(EventTypeEnum)))
73 // specs.Enqueue(listenTo);
74 //specs.Enqueue(EventTypeEnum.Added | EventTypeEnum.Removed);
76 for (int spec
= 0; spec
<= (int)EventTypeEnum
.All
; spec
++)
77 specs
.Enqueue((EventTypeEnum
)spec
);
82 public abstract class CollectionValueTester
<U
> : CollectionValueTester
<U
, int> where U
: ICollectionValue
<int>
86 public class ExtensibleTester
<U
> : CollectionValueTester
<U
> where U
: IExtensible
<int>
88 public override SCG
.IEnumerable
<EventTypeEnum
> GetSpecs()
93 public virtual void Listenable()
95 Assert
.AreEqual(EventTypeEnum
.Basic
, collection
.ListenableEvents
);
96 Assert
.AreEqual(EventTypeEnum
.None
, collection
.ActiveEvents
);
98 Assert
.AreEqual(listenTo
, collection
.ActiveEvents
);
105 seen
.Check(new CollectionEvent
<int>[0]);
107 seen
.Check(new CollectionEvent
<int>[] {
108 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(23, 1), collection
),
109 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
115 for (int i
= 0; i
< 10; i
++)
117 collection
.Add(10 * i
+ 5);
120 collection
.AddAll
<int>(new int[] { 45, 200, 56, 67 }
);
121 seen
.Check(collection
.AllowsDuplicates
?
122 collection
.DuplicatesByCounting
?
123 new CollectionEvent
<int>[] {
124 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(45, 1), collection
),
125 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(200, 1), collection
),
126 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(55, 1), collection
),
127 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(65, 1), collection
),
128 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)}
130 new CollectionEvent
<int>[] {
131 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(45, 1), collection
),
132 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(200, 1), collection
),
133 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(56, 1), collection
),
134 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(67, 1), collection
),
135 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)}
137 new CollectionEvent
<int>[] {
138 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(200, 1), collection
),
139 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
140 collection
.AddAll
<int>(new int[] { }
);
141 seen
.Check(new CollectionEvent
<int>[] { }
);
146 public class CollectionTester
<U
> : ExtensibleTester
<U
> where U
: ICollection
<int>
151 collection
.Add(4); collection
.Add(54); collection
.Add(56); collection
.Add(8);
153 collection
.Update(53);
155 collection
.AllowsDuplicates
?
156 collection
.DuplicatesByCounting
?
157 new CollectionEvent
<int>[] {
158 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(54, 2), collection
),
159 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(53, 2), collection
),
160 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
162 : new CollectionEvent
<int>[] {
163 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(54, 1), collection
),
164 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(53, 1), collection
),
165 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
167 : new CollectionEvent
<int>[] {
168 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(54, 1), collection
),
169 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(53, 1), collection
),
170 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
172 collection
.Update(67);
173 seen
.Check(new CollectionEvent
<int>[] { }
);
177 public void FindOrAdd()
179 collection
.Add(4); collection
.Add(56); collection
.Add(8);
182 collection
.FindOrAdd(ref val
);
183 seen
.Check(new CollectionEvent
<int>[] { }
);
185 collection
.FindOrAdd(ref val
);
186 seen
.Check(new CollectionEvent
<int>[] {
187 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(67, 1), collection
),
188 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
193 public void UpdateOrAdd()
195 collection
.Add(4); collection
.Add(56); collection
.Add(8);
198 collection
.UpdateOrAdd(val
);
199 seen
.Check(new CollectionEvent
<int>[] {
200 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(56, 1), collection
),
201 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(53, 1), collection
),
202 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
205 collection
.UpdateOrAdd(val
);
206 seen
.Check(new CollectionEvent
<int>[] {
207 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(67, 1), collection
),
208 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
210 collection
.UpdateOrAdd(51, out val
);
211 seen
.Check(new CollectionEvent
<int>[] {
212 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(53, 1), collection
),
213 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(51, 1), collection
),
214 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
217 collection
.UpdateOrAdd(81, out val
);
218 seen
.Check(new CollectionEvent
<int>[] {
219 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(81, 1), collection
),
220 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
225 public void RemoveItem()
227 collection
.Add(4); collection
.Add(56); collection
.Add(18);
229 collection
.Remove(53);
230 seen
.Check(new CollectionEvent
<int>[] {
231 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(56, 1), collection
),
232 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
233 collection
.Remove(11);
234 seen
.Check(new CollectionEvent
<int>[] {
235 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(18, 1), collection
),
236 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
240 public void RemoveAll()
242 for (int i
= 0; i
< 10; i
++)
244 collection
.Add(10 * i
+ 5);
247 collection
.RemoveAll
<int>(new int[] { 32, 187, 45 }
);
248 //TODO: the order depends on internals of the HashSet
249 seen
.Check(new CollectionEvent
<int>[] {
250 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(35, 1), collection
),
251 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(45, 1), collection
),
252 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
253 collection
.RemoveAll
<int>(new int[] { 200, 300 }
);
254 seen
.Check(new CollectionEvent
<int>[] { }
);
258 [Ignore("Temporarily disabled. 2006-03-07. Martin")]
259 public void RetainAll()
261 for (int i
= 0; i
< 10; i
++)
263 collection
.Add(10 * i
+ 5);
266 collection
.RetainAll
<int>(new int[] { 32, 187, 45, 62, 75, 82, 95, 2 }
);
267 seen
.Check(new CollectionEvent
<int>[] {
268 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(15, 1), collection
),
269 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(25, 1), collection
),
270 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(55, 1), collection
),
271 //new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(75, 1), collection),
272 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
273 collection
.RetainAll
<int>(new int[] { 32, 187, 45, 62, 75, 82, 95, 2 }
);
274 seen
.Check(new CollectionEvent
<int>[] { }
);
278 public void RemoveAllCopies()
280 for (int i
= 0; i
< 10; i
++)
282 collection
.Add(3 * i
+ 5);
285 collection
.RemoveAllCopies(14);
287 collection
.AllowsDuplicates
?
288 collection
.DuplicatesByCounting
?
289 new CollectionEvent
<int>[] {
290 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(11, 3), collection
),
291 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)}
293 new CollectionEvent
<int>[] {
294 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(11, 1), collection
),
295 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(14, 1), collection
),
296 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(17, 1), collection
),
297 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)}
299 new CollectionEvent
<int>[] {
300 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(11, 1), collection
),
301 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
302 collection
.RemoveAllCopies(14);
303 seen
.Check(new CollectionEvent
<int>[] { }
);
307 public virtual void Clear()
309 collection
.Add(4); collection
.Add(56); collection
.Add(8);
312 seen
.Check(new CollectionEvent
<int>[] {
313 new CollectionEvent
<int>(EventTypeEnum
.Cleared
, new ClearedEventArgs(true, collection
.AllowsDuplicates
? 3 : 2), collection
),
314 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
317 seen
.Check(new CollectionEvent
<int>[] { }
);
322 public class IndexedTester
<U
> : CollectionTester
<U
> where U
: IIndexed
<int>
325 public void RemoveAt()
327 collection
.Add(4); collection
.Add(16); collection
.Add(28);
329 collection
.RemoveAt(1);
330 seen
.Check(new CollectionEvent
<int>[] {
331 new CollectionEvent
<int>(EventTypeEnum
.RemovedAt
, new ItemAtEventArgs
<int>(16,1), collection
),
332 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(16, 1), collection
),
333 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
337 public void RemoveInterval()
339 collection
.Add(4); collection
.Add(56); collection
.Add(18);
341 collection
.RemoveInterval(1, 2);
342 seen
.Check(new CollectionEvent
<int>[] {
343 collection
is IList
<int> ?
344 new CollectionEvent
<int>(EventTypeEnum
.Cleared
, new ClearedRangeEventArgs(false,2,1), collection
):
345 new CollectionEvent
<int>(EventTypeEnum
.Cleared
, new ClearedEventArgs(false,2), collection
),
346 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
348 collection
.RemoveInterval(1, 0);
349 seen
.Check(new CollectionEvent
<int>[] { }
);
353 public class SortedIndexedTester
<U
> : IndexedTester
<U
> where U
: IIndexedSorted
<int>
355 public override SCG
.IEnumerable
<EventTypeEnum
> GetSpecs()
360 public void DeleteMinMax()
367 collection
.DeleteMax();
368 seen
.Check(new CollectionEvent
<int>[] {
369 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(56, 1), collection
),
370 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
),
372 collection
.DeleteMin();
373 seen
.Check(new CollectionEvent
<int>[] {
374 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(12, 1), collection
),
375 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
),
380 public void AddSorted()
383 collection
.AddSorted(collection
.AllowsDuplicates
? new int[] { 31, 62, 63, 93 }
: new int[] { 31, 62, 93 }
);
384 seen
.Check(collection
.AllowsDuplicates
?
385 collection
.DuplicatesByCounting
?
386 new CollectionEvent
<int>[] {
387 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(31, 1), collection
),
388 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(62, 1), collection
),
389 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(62, 1), collection
),
390 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(93, 1), collection
),
391 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)}
393 new CollectionEvent
<int>[] {
394 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(31, 1), collection
),
395 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(62, 1), collection
),
396 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(63, 1), collection
),
397 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(93, 1), collection
),
398 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)}
400 new CollectionEvent
<int>[] {
401 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(31, 1), collection
),
402 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(62, 1), collection
),
403 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(93, 1), collection
),
404 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
405 collection
.AddSorted(new int[] { }
);
406 seen
.Check(new CollectionEvent
<int>[] { }
);
410 public void RemoveRange()
412 for (int i
= 0; i
< 20; i
++)
413 collection
.Add(i
* 10 + 5);
415 collection
.RemoveRangeFrom(173);
416 //TODO: fix order to remove in:
418 new CollectionEvent
<int>[] {
419 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(195, 1), collection
),
420 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(185, 1), collection
),
421 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(175, 1), collection
),
422 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
423 collection
.RemoveRangeFromTo(83, 113);
425 new CollectionEvent
<int>[] {
426 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(105, 1), collection
),
427 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(95, 1), collection
),
428 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(85, 1), collection
),
429 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
430 collection
.RemoveRangeTo(33);
432 new CollectionEvent
<int>[] {
433 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(5, 1), collection
),
434 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(15, 1), collection
),
435 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(25, 1), collection
),
436 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
437 collection
.RemoveRangeFrom(173);
438 seen
.Check(new CollectionEvent
<int>[] { }
);
439 collection
.RemoveRangeFromTo(83, 113);
440 seen
.Check(new CollectionEvent
<int>[] { }
);
441 collection
.RemoveRangeTo(33);
442 seen
.Check(new CollectionEvent
<int>[] { }
);
446 public class ListTester
<U
> : IndexedTester
<U
> where U
: IList
<int>
448 public override SCG
.IEnumerable
<EventTypeEnum
> GetSpecs()
454 public override void Listenable()
456 Assert
.AreEqual(EventTypeEnum
.All
, collection
.ListenableEvents
);
457 Assert
.AreEqual(EventTypeEnum
.None
, collection
.ActiveEvents
);
459 Assert
.AreEqual(listenTo
, collection
.ActiveEvents
);
462 public void SetThis()
464 collection
.Add(4); collection
.Add(56); collection
.Add(8);
467 seen
.Check(new CollectionEvent
<int>[] {
468 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(56, 1), collection
),
469 new CollectionEvent
<int>(EventTypeEnum
.RemovedAt
, new ItemAtEventArgs
<int>(56,1), collection
),
470 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(45, 1), collection
),
471 new CollectionEvent
<int>(EventTypeEnum
.Inserted
, new ItemAtEventArgs
<int>(45,1), collection
),
472 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
479 collection
.Add(4); collection
.Add(56); collection
.Add(8);
481 collection
.Insert(1, 45);
482 seen
.Check(new CollectionEvent
<int>[] {
483 new CollectionEvent
<int>(EventTypeEnum
.Inserted
, new ItemAtEventArgs
<int>(45,1), collection
),
484 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(45, 1), collection
),
485 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
490 public void InsertAll()
492 collection
.Add(4); collection
.Add(56); collection
.Add(8);
494 collection
.InsertAll
<int>(1, new int[] { 666, 777, 888 }
);
495 //seen.Print(Console.Error);
496 seen
.Check(new CollectionEvent
<int>[] {
497 new CollectionEvent
<int>(EventTypeEnum
.Inserted
, new ItemAtEventArgs
<int>(666,1), collection
),
498 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(666, 1), collection
),
499 new CollectionEvent
<int>(EventTypeEnum
.Inserted
, new ItemAtEventArgs
<int>(777,2), collection
),
500 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(777, 1), collection
),
501 new CollectionEvent
<int>(EventTypeEnum
.Inserted
, new ItemAtEventArgs
<int>(888,3), collection
),
502 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(888, 1), collection
),
503 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
505 collection
.InsertAll
<int>(1, new int[] { }
);
506 seen
.Check(new CollectionEvent
<int>[] { }
);
510 public void InsertFirstLast()
512 collection
.Add(4); collection
.Add(56); collection
.Add(18);
514 collection
.InsertFirst(45);
515 seen
.Check(new CollectionEvent
<int>[] {
516 new CollectionEvent
<int>(EventTypeEnum
.Inserted
, new ItemAtEventArgs
<int>(45,0), collection
),
517 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(45, 1), collection
),
518 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
520 collection
.InsertLast(88);
521 seen
.Check(new CollectionEvent
<int>[] {
522 new CollectionEvent
<int>(EventTypeEnum
.Inserted
, new ItemAtEventArgs
<int>(88,4), collection
),
523 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(88, 1), collection
),
524 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
531 collection
.FIFO
= false;
532 collection
.Add(4); collection
.Add(56); collection
.Add(18);
535 seen
.Check(new CollectionEvent
<int>[] {
536 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(18, 1), collection
),
537 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
538 collection
.FIFO
= true;
540 seen
.Check(new CollectionEvent
<int>[] {
541 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(4, 1), collection
),
542 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
546 public void RemoveFirst()
548 collection
.Add(4); collection
.Add(56); collection
.Add(18);
550 collection
.RemoveFirst();
551 seen
.Check(new CollectionEvent
<int>[] {
552 new CollectionEvent
<int>(EventTypeEnum
.RemovedAt
, new ItemAtEventArgs
<int>(4,0), collection
),
553 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(4, 1), collection
),
554 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
558 public void RemoveLast()
560 collection
.Add(4); collection
.Add(56); collection
.Add(18);
562 collection
.RemoveLast();
563 seen
.Check(new CollectionEvent
<int>[] {
564 new CollectionEvent
<int>(EventTypeEnum
.RemovedAt
, new ItemAtEventArgs
<int>(18,2), collection
),
565 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(18, 1), collection
),
566 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
570 public void Reverse()
572 collection
.Add(4); collection
.Add(56); collection
.Add(8);
574 collection
.Reverse();
575 seen
.Check(new CollectionEvent
<int>[] {
576 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
578 collection
.View(1, 0).Reverse();
579 seen
.Check(new CollectionEvent
<int>[] { }
);
586 collection
.Add(4); collection
.Add(56); collection
.Add(8);
589 seen
.Check(new CollectionEvent
<int>[] {
590 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
592 collection
.View(1, 0).Sort();
593 seen
.Check(new CollectionEvent
<int>[] { }
);
597 public void Shuffle()
599 collection
.Add(4); collection
.Add(56); collection
.Add(8);
601 collection
.Shuffle();
602 seen
.Check(new CollectionEvent
<int>[] {
603 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
605 collection
.View(1, 0).Shuffle();
606 seen
.Check(new CollectionEvent
<int>[] { }
);
610 public override void Clear()
612 collection
.Add(4); collection
.Add(56); collection
.Add(18);
614 collection
.View(1, 1).Clear();
615 seen
.Check(new CollectionEvent
<int>[] {
616 new CollectionEvent
<int>(EventTypeEnum
.Cleared
, new ClearedRangeEventArgs(false,1,1), collection
),
617 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
620 seen
.Check(new CollectionEvent
<int>[] {
621 new CollectionEvent
<int>(EventTypeEnum
.Cleared
, new ClearedRangeEventArgs(true,2,0), collection
),
622 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
625 seen
.Check(new CollectionEvent
<int>[] { }
);
629 public void ListDispose()
631 collection
.Add(4); collection
.Add(56); collection
.Add(18);
633 collection
.View(1, 1).Dispose();
634 seen
.Check(new CollectionEvent
<int>[] { }
);
635 collection
.Dispose();
636 seen
.Check(new CollectionEvent
<int>[] {
637 new CollectionEvent
<int>(EventTypeEnum
.Cleared
, new ClearedRangeEventArgs(true,3,0), collection
),
638 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
640 collection
.Dispose();
641 seen
.Check(new CollectionEvent
<int>[] { }
);
648 //public void Dispose() { list = null; seen = null; }
651 [ExpectedException(typeof(UnlistenableEventException))]
652 public void ViewChanged()
654 IList<int> w = collection.View(0, 0);
655 w.CollectionChanged += new CollectionChangedHandler<int>(w_CollectionChanged);
659 [ExpectedException(typeof(UnlistenableEventException))]
660 public void ViewCleared()
662 IList<int> w = collection.View(0, 0);
663 w.CollectionCleared += new CollectionClearedHandler<int>(w_CollectionCleared);
667 [ExpectedException(typeof(UnlistenableEventException))]
668 public void ViewAdded()
670 IList<int> w = collection.View(0, 0);
671 w.ItemsAdded += new ItemsAddedHandler<int>(w_ItemAdded);
675 [ExpectedException(typeof(UnlistenableEventException))]
676 public void ViewInserted()
678 IList<int> w = collection.View(0, 0);
679 w.ItemInserted += new ItemInsertedHandler<int>(w_ItemInserted);
683 [ExpectedException(typeof(UnlistenableEventException))]
684 public void ViewRemoved()
686 IList<int> w = collection.View(0, 0);
687 w.ItemsRemoved += new ItemsRemovedHandler<int>(w_ItemRemoved);
691 [ExpectedException(typeof(UnlistenableEventException))]
692 public void ViewRemovedAt()
694 IList<int> w = collection.View(0, 0);
695 w.ItemRemovedAt += new ItemRemovedAtHandler<int>(w_ItemRemovedAt);
698 void w_CollectionChanged(object sender)
700 throw new NotImplementedException();
703 void w_CollectionCleared(object sender, ClearedEventArgs eventArgs)
705 throw new NotImplementedException();
708 void w_ItemAdded(object sender, ItemCountEventArgs<int> eventArgs)
710 throw new NotImplementedException();
713 void w_ItemInserted(object sender, ItemAtEventArgs<int> eventArgs)
715 throw new NotImplementedException();
718 void w_ItemRemoved(object sender, ItemCountEventArgs<int> eventArgs)
720 throw new NotImplementedException();
723 void w_ItemRemovedAt(object sender, ItemAtEventArgs<int> eventArgs)
725 throw new NotImplementedException();
729 public class StackTester
<U
> : CollectionValueTester
<U
> where U
: IStack
<int>
731 public override SCG
.IEnumerable
<EventTypeEnum
> GetSpecs()
737 public void PushPop()
740 seen
.Check(new CollectionEvent
<int>[0]);
742 seen
.Check(new CollectionEvent
<int>[] {
743 new CollectionEvent
<int>(EventTypeEnum
.Inserted
, new ItemAtEventArgs
<int>(23,0), collection
),
744 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(23, 1), collection
),
745 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
746 collection
.Push(-12);
747 seen
.Check(new CollectionEvent
<int>[] {
748 new CollectionEvent
<int>(EventTypeEnum
.Inserted
, new ItemAtEventArgs
<int>(-12,1), collection
),
749 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(-12, 1), collection
),
750 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
752 seen
.Check(new CollectionEvent
<int>[] {
753 new CollectionEvent
<int>(EventTypeEnum
.RemovedAt
, new ItemAtEventArgs
<int>(-12,1), collection
),
754 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(-12, 1), collection
),
755 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
757 seen
.Check(new CollectionEvent
<int>[] {
758 new CollectionEvent
<int>(EventTypeEnum
.RemovedAt
, new ItemAtEventArgs
<int>(23,0), collection
),
759 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(23, 1), collection
),
760 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
764 public class QueueTester
<U
> : CollectionValueTester
<U
> where U
: IQueue
<int>
766 public override SCG
.IEnumerable
<EventTypeEnum
> GetSpecs()
772 public void EnqueueDequeue()
775 collection
.Enqueue(67);
776 seen
.Check(new CollectionEvent
<int>[] {
777 new CollectionEvent
<int>(EventTypeEnum
.Inserted
, new ItemAtEventArgs
<int>(67,0), collection
),
778 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(67, 1), collection
),
779 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
780 collection
.Enqueue(2);
781 seen
.Check(new CollectionEvent
<int>[] {
782 new CollectionEvent
<int>(EventTypeEnum
.Inserted
, new ItemAtEventArgs
<int>(2,1), collection
),
783 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(2, 1), collection
),
784 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
785 collection
.Dequeue();
786 seen
.Check(new CollectionEvent
<int>[] {
787 new CollectionEvent
<int>(EventTypeEnum
.RemovedAt
, new ItemAtEventArgs
<int>(67,0), collection
),
788 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(67, 1), collection
),
789 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
790 collection
.Dequeue();
791 seen
.Check(new CollectionEvent
<int>[] {
792 new CollectionEvent
<int>(EventTypeEnum
.RemovedAt
, new ItemAtEventArgs
<int>(2,0), collection
),
793 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(2, 1), collection
),
794 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
799 public class PriorityQueueTester
<U
> : ExtensibleTester
<U
> where U
: IPriorityQueue
<int>
801 public override System
.Collections
.Generic
.IEnumerable
<EventTypeEnum
> GetSpecs()
811 seen
.Check(new CollectionEvent
<int>[] {
812 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(34, 1), collection
),
813 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
),
816 seen
.Check(new CollectionEvent
<int>[] {
817 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(56, 1), collection
),
818 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
),
820 collection
.AddAll
<int>(new int[] { }
);
821 seen
.Check(new CollectionEvent
<int>[] {
824 seen
.Check(new CollectionEvent
<int>[] {
825 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(34, 1), collection
),
826 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
),
829 seen
.Check(new CollectionEvent
<int>[] {
830 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(12, 1), collection
),
831 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
),
833 collection
.DeleteMax();
834 seen
.Check(new CollectionEvent
<int>[] {
835 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(56, 1), collection
),
836 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
),
838 collection
.DeleteMin();
839 seen
.Check(new CollectionEvent
<int>[] {
840 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(12, 1), collection
),
841 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
),
843 collection
.AddAll
<int>(new int[] { 4, 5, 6, 2 }
);
844 seen
.Check(new CollectionEvent
<int>[] {
845 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(4, 1), collection
),
846 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(5, 1), collection
),
847 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(6, 1), collection
),
848 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(2, 1), collection
),
849 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
)
854 public void WithHandles()
857 IPriorityQueueHandle
<int> handle
= null, handle2
;
859 seen
.Check(new CollectionEvent
<int>[] {
860 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(34, 1), collection
),
861 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
),
864 seen
.Check(new CollectionEvent
<int>[] {
865 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(56, 1), collection
),
866 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
),
868 collection
.Add(ref handle
, 34);
869 seen
.Check(new CollectionEvent
<int>[] {
870 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(34, 1), collection
),
871 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
),
874 seen
.Check(new CollectionEvent
<int>[] {
875 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(12, 1), collection
),
876 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
),
878 collection
.DeleteMax(out handle2
);
879 seen
.Check(new CollectionEvent
<int>[] {
880 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(56, 1), collection
),
881 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
),
883 collection
.DeleteMin(out handle2
);
884 seen
.Check(new CollectionEvent
<int>[] {
885 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(12, 1), collection
),
886 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
),
889 collection
.Replace(handle
, 117);
890 seen
.Check(new CollectionEvent
<int>[] {
891 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(34, 1), collection
),
892 new CollectionEvent
<int>(EventTypeEnum
.Added
, new ItemCountEventArgs
<int>(117, 1), collection
),
893 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
),
896 collection
.Delete(handle
);
897 seen
.Check(new CollectionEvent
<int>[] {
898 new CollectionEvent
<int>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<int>(117, 1), collection
),
899 new CollectionEvent
<int>(EventTypeEnum
.Changed
, new EventArgs(), collection
),
904 public class DictionaryTester
<U
> : CollectionValueTester
<U
, KeyValuePair
<int, int>> where U
: IDictionary
<int, int>
906 public override SCG
.IEnumerable
<EventTypeEnum
> GetSpecs()
912 public virtual void Listenable()
914 Assert
.AreEqual(EventTypeEnum
.Basic
, collection
.ListenableEvents
);
915 Assert
.AreEqual(EventTypeEnum
.None
, collection
.ActiveEvents
);
917 Assert
.AreEqual(listenTo
, collection
.ActiveEvents
);
921 public void AddAndREmove()
924 seen
.Check(new CollectionEvent
<KeyValuePair
<int, int>>[0]);
925 collection
.Add(23, 45);
926 seen
.Check(new CollectionEvent
<KeyValuePair
<int,int>>[] {
927 new CollectionEvent
<KeyValuePair
<int,int>>(EventTypeEnum
.Added
, new ItemCountEventArgs
<KeyValuePair
<int,int>>(new KeyValuePair
<int,int>(23,45), 1), collection
),
928 new CollectionEvent
<KeyValuePair
<int,int>>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});
929 collection
.Remove(25);
930 seen
.Check(new CollectionEvent
<KeyValuePair
<int, int>>[] {
931 new CollectionEvent
<KeyValuePair
<int,int>>(EventTypeEnum
.Removed
, new ItemCountEventArgs
<KeyValuePair
<int,int>>(new KeyValuePair
<int,int>(23,45), 1), collection
),
932 new CollectionEvent
<KeyValuePair
<int,int>>(EventTypeEnum
.Changed
, new EventArgs(), collection
)});