2 Copyright (c) 2003-2006 Niels Kokholm and Peter Sestoft
\r
3 Permission is hereby granted, free of charge, to any person obtaining a copy
\r
4 of this software and associated documentation files (the "Software"), to deal
\r
5 in the Software without restriction, including without limitation the rights
\r
6 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
7 copies of the Software, and to permit persons to whom the Software is
\r
8 furnished to do so, subject to the following conditions:
\r
10 The above copyright notice and this permission notice shall be included in
\r
11 all copies or substantial portions of the Software.
\r
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
16 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
17 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
18 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
\r
24 using NUnit.Framework;
\r
25 using SCG = System.Collections.Generic;
\r
26 using System.Reflection;
\r
28 namespace C5UnitTests.Templates.Events
\r
30 public abstract class CollectionValueTester<TCollection, TItem> : GenericCollectionTester<TCollection, EventTypeEnum>
\r
31 where TCollection : ICollectionValue<TItem>
\r
33 protected TCollection collection;
\r
34 protected CollectionEventList<TItem> seen;
\r
35 protected EventTypeEnum listenTo;
\r
36 protected void listen() { seen.Listen(collection, listenTo); }
\r
38 public override void SetUp(TCollection list, EventTypeEnum testSpec)
\r
40 this.collection = list;
\r
41 listenTo = testSpec;
\r
42 seen = new CollectionEventList<TItem>(EqualityComparer<TItem>.Default);
\r
45 public SCG.IEnumerable<EventTypeEnum> SpecsBasic
\r
49 CircularQueue<EventTypeEnum> specs = new CircularQueue<EventTypeEnum>();
\r
50 //foreach (EventTypeEnum listenTo in Enum.GetValues(typeof(EventTypeEnum)))
\r
51 // if ((listenTo & ~EventTypeEnum.Basic) == 0)
\r
52 // specs.Enqueue(listenTo);
\r
53 //specs.Enqueue(EventTypeEnum.Added | EventTypeEnum.Removed);
\r
54 for (int spec = 0; spec <= (int)EventTypeEnum.Basic; spec++)
\r
55 specs.Enqueue((EventTypeEnum)spec);
\r
59 public SCG.IEnumerable<EventTypeEnum> SpecsAll
\r
63 CircularQueue<EventTypeEnum> specs = new CircularQueue<EventTypeEnum>();
\r
64 //foreach (EventTypeEnum listenTo in Enum.GetValues(typeof(EventTypeEnum)))
\r
65 // specs.Enqueue(listenTo);
\r
66 //specs.Enqueue(EventTypeEnum.Added | EventTypeEnum.Removed);
\r
68 for (int spec = 0; spec <= (int)EventTypeEnum.All; spec++)
\r
69 specs.Enqueue((EventTypeEnum)spec);
\r
74 public abstract class CollectionValueTester<U> : CollectionValueTester<U, int> where U : ICollectionValue<int>
\r
78 public class ExtensibleTester<U> : CollectionValueTester<U> where U : IExtensible<int>
\r
80 public override SCG.IEnumerable<EventTypeEnum> GetSpecs()
\r
85 public virtual void Listenable()
\r
87 Assert.AreEqual(EventTypeEnum.Basic, collection.ListenableEvents);
\r
88 Assert.AreEqual(EventTypeEnum.None, collection.ActiveEvents);
\r
90 Assert.AreEqual(listenTo, collection.ActiveEvents);
\r
97 seen.Check(new CollectionEvent<int>[0]);
\r
99 seen.Check(new CollectionEvent<int>[] {
\r
100 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(23, 1), collection),
\r
101 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
105 public void AddAll()
\r
107 for (int i = 0; i < 10; i++)
\r
109 collection.Add(10 * i + 5);
\r
112 collection.AddAll<int>(new int[] { 45, 200, 56, 67 });
\r
113 seen.Check(collection.AllowsDuplicates ?
\r
114 collection.DuplicatesByCounting ?
\r
115 new CollectionEvent<int>[] {
\r
116 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), collection),
\r
117 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(200, 1), collection),
\r
118 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(55, 1), collection),
\r
119 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(65, 1), collection),
\r
120 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)}
\r
122 new CollectionEvent<int>[] {
\r
123 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), collection),
\r
124 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(200, 1), collection),
\r
125 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(56, 1), collection),
\r
126 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), collection),
\r
127 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)}
\r
129 new CollectionEvent<int>[] {
\r
130 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(200, 1), collection),
\r
131 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
132 collection.AddAll<int>(new int[] { });
\r
133 seen.Check(new CollectionEvent<int>[] { });
\r
138 public class CollectionTester<U> : ExtensibleTester<U> where U : ICollection<int>
\r
141 public void Update()
\r
143 collection.Add(4); collection.Add(54); collection.Add(56); collection.Add(8);
\r
145 collection.Update(53);
\r
147 collection.AllowsDuplicates ?
\r
148 collection.DuplicatesByCounting ?
\r
149 new CollectionEvent<int>[] {
\r
150 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(54, 2), collection),
\r
151 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(53, 2), collection),
\r
152 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
154 : new CollectionEvent<int>[] {
\r
155 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(54, 1), collection),
\r
156 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(53, 1), collection),
\r
157 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
159 : new CollectionEvent<int>[] {
\r
160 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(54, 1), collection),
\r
161 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(53, 1), collection),
\r
162 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
164 collection.Update(67);
\r
165 seen.Check(new CollectionEvent<int>[] { });
\r
169 public void FindOrAdd()
\r
171 collection.Add(4); collection.Add(56); collection.Add(8);
\r
174 collection.FindOrAdd(ref val);
\r
175 seen.Check(new CollectionEvent<int>[] { });
\r
177 collection.FindOrAdd(ref val);
\r
178 seen.Check(new CollectionEvent<int>[] {
\r
179 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), collection),
\r
180 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
185 public void UpdateOrAdd()
\r
187 collection.Add(4); collection.Add(56); collection.Add(8);
\r
190 collection.UpdateOrAdd(val);
\r
191 seen.Check(new CollectionEvent<int>[] {
\r
192 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), collection),
\r
193 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(53, 1), collection),
\r
194 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
197 collection.UpdateOrAdd(val);
\r
198 seen.Check(new CollectionEvent<int>[] {
\r
199 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), collection),
\r
200 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
202 collection.UpdateOrAdd(51, out val);
\r
203 seen.Check(new CollectionEvent<int>[] {
\r
204 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(53, 1), collection),
\r
205 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(51, 1), collection),
\r
206 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
209 collection.UpdateOrAdd(81, out val);
\r
210 seen.Check(new CollectionEvent<int>[] {
\r
211 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(81, 1), collection),
\r
212 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
217 public void RemoveItem()
\r
219 collection.Add(4); collection.Add(56); collection.Add(18);
\r
221 collection.Remove(53);
\r
222 seen.Check(new CollectionEvent<int>[] {
\r
223 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), collection),
\r
224 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
225 collection.Remove(11);
\r
226 seen.Check(new CollectionEvent<int>[] {
\r
227 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(18, 1), collection),
\r
228 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
232 public void RemoveAll()
\r
234 for (int i = 0; i < 10; i++)
\r
236 collection.Add(10 * i + 5);
\r
239 collection.RemoveAll<int>(new int[] { 32, 187, 45 });
\r
240 //TODO: the order depends on internals of the HashSet
\r
241 seen.Check(new CollectionEvent<int>[] {
\r
242 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(35, 1), collection),
\r
243 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(45, 1), collection),
\r
244 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
245 collection.RemoveAll<int>(new int[] { 200, 300 });
\r
246 seen.Check(new CollectionEvent<int>[] { });
\r
250 public void RetainAll()
\r
252 for (int i = 0; i < 10; i++)
\r
254 collection.Add(10 * i + 5);
\r
257 collection.RetainAll<int>(new int[] { 32, 187, 45, 62, 75, 82, 95, 2 });
\r
258 seen.Check(new CollectionEvent<int>[] {
\r
259 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(15, 1), collection),
\r
260 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(25, 1), collection),
\r
261 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(55, 1), collection),
\r
262 //new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(75, 1), collection),
\r
263 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
264 collection.RetainAll<int>(new int[] { 32, 187, 45, 62, 75, 82, 95, 2 });
\r
265 seen.Check(new CollectionEvent<int>[] { });
\r
269 public void RemoveAllCopies()
\r
271 for (int i = 0; i < 10; i++)
\r
273 collection.Add(3 * i + 5);
\r
276 collection.RemoveAllCopies(14);
\r
278 collection.AllowsDuplicates ?
\r
279 collection.DuplicatesByCounting ?
\r
280 new CollectionEvent<int>[] {
\r
281 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(11, 3), collection),
\r
282 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)}
\r
284 new CollectionEvent<int>[] {
\r
285 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(11, 1), collection),
\r
286 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(14, 1), collection),
\r
287 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(17, 1), collection),
\r
288 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)}
\r
290 new CollectionEvent<int>[] {
\r
291 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(11, 1), collection),
\r
292 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
293 collection.RemoveAllCopies(14);
\r
294 seen.Check(new CollectionEvent<int>[] { });
\r
298 public virtual void Clear()
\r
300 collection.Add(4); collection.Add(56); collection.Add(8);
\r
302 collection.Clear();
\r
303 seen.Check(new CollectionEvent<int>[] {
\r
304 new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedEventArgs(true, collection.AllowsDuplicates ? 3 : 2), collection),
\r
305 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
307 collection.Clear();
\r
308 seen.Check(new CollectionEvent<int>[] { });
\r
313 public class IndexedTester<U> : CollectionTester<U> where U : IIndexed<int>
\r
316 public void RemoveAt()
\r
318 collection.Add(4); collection.Add(16); collection.Add(28);
\r
320 collection.RemoveAt(1);
\r
321 seen.Check(new CollectionEvent<int>[] {
\r
322 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(16,1), collection),
\r
323 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(16, 1), collection),
\r
324 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
328 public void RemoveInterval()
\r
330 collection.Add(4); collection.Add(56); collection.Add(18);
\r
332 collection.RemoveInterval(1, 2);
\r
333 seen.Check(new CollectionEvent<int>[] {
\r
334 collection is IList<int> ?
\r
335 new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(false,2,1), collection):
\r
336 new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedEventArgs(false,2), collection),
\r
337 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
339 collection.RemoveInterval(1, 0);
\r
340 seen.Check(new CollectionEvent<int>[] { });
\r
344 public class SortedIndexedTester<U> : IndexedTester<U> where U : IIndexedSorted<int>
\r
347 public void DeleteMinMax()
\r
349 collection.Add(34);
\r
350 collection.Add(56);
\r
351 collection.Add(34);
\r
352 collection.Add(12);
\r
354 collection.DeleteMax();
\r
355 seen.Check(new CollectionEvent<int>[] {
\r
356 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), collection),
\r
357 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection),
\r
359 collection.DeleteMin();
\r
360 seen.Check(new CollectionEvent<int>[] {
\r
361 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(12, 1), collection),
\r
362 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection),
\r
367 public void AddSorted()
\r
370 collection.AddSorted(collection.AllowsDuplicates ? new int[] { 31, 62, 63, 93 } : new int[] { 31, 62, 93 });
\r
371 seen.Check(collection.AllowsDuplicates ?
\r
372 collection.DuplicatesByCounting ?
\r
373 new CollectionEvent<int>[] {
\r
374 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(31, 1), collection),
\r
375 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(62, 1), collection),
\r
376 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(62, 1), collection),
\r
377 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(93, 1), collection),
\r
378 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)}
\r
380 new CollectionEvent<int>[] {
\r
381 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(31, 1), collection),
\r
382 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(62, 1), collection),
\r
383 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(63, 1), collection),
\r
384 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(93, 1), collection),
\r
385 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)}
\r
387 new CollectionEvent<int>[] {
\r
388 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(31, 1), collection),
\r
389 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(62, 1), collection),
\r
390 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(93, 1), collection),
\r
391 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
392 collection.AddSorted(new int[] { });
\r
393 seen.Check(new CollectionEvent<int>[] { });
\r
397 public void RemoveRange()
\r
399 for (int i = 0; i < 20; i++)
\r
400 collection.Add(i * 10 + 5);
\r
402 collection.RemoveRangeFrom(173);
\r
403 //TODO: fix order to remove in:
\r
405 new CollectionEvent<int>[] {
\r
406 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(195, 1), collection),
\r
407 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(185, 1), collection),
\r
408 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(175, 1), collection),
\r
409 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
410 collection.RemoveRangeFromTo(83, 113);
\r
412 new CollectionEvent<int>[] {
\r
413 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(105, 1), collection),
\r
414 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(95, 1), collection),
\r
415 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(85, 1), collection),
\r
416 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
417 collection.RemoveRangeTo(33);
\r
419 new CollectionEvent<int>[] {
\r
420 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(5, 1), collection),
\r
421 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(15, 1), collection),
\r
422 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(25, 1), collection),
\r
423 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
424 collection.RemoveRangeFrom(173);
\r
425 seen.Check(new CollectionEvent<int>[] { });
\r
426 collection.RemoveRangeFromTo(83, 113);
\r
427 seen.Check(new CollectionEvent<int>[] { });
\r
428 collection.RemoveRangeTo(33);
\r
429 seen.Check(new CollectionEvent<int>[] { });
\r
433 public class ListTester<U> : IndexedTester<U> where U : IList<int>
\r
435 public override SCG.IEnumerable<EventTypeEnum> GetSpecs()
\r
441 public override void Listenable()
\r
443 Assert.AreEqual(EventTypeEnum.All, collection.ListenableEvents);
\r
444 Assert.AreEqual(EventTypeEnum.None, collection.ActiveEvents);
\r
446 Assert.AreEqual(listenTo, collection.ActiveEvents);
\r
449 public void SetThis()
\r
451 collection.Add(4); collection.Add(56); collection.Add(8);
\r
453 collection[1] = 45;
\r
454 seen.Check(new CollectionEvent<int>[] {
\r
455 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), collection),
\r
456 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(56,1), collection),
\r
457 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), collection),
\r
458 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(45,1), collection),
\r
459 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
464 public void Insert()
\r
466 collection.Add(4); collection.Add(56); collection.Add(8);
\r
468 collection.Insert(1, 45);
\r
469 seen.Check(new CollectionEvent<int>[] {
\r
470 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(45,1), collection),
\r
471 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), collection),
\r
472 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
477 public void InsertAll()
\r
479 collection.Add(4); collection.Add(56); collection.Add(8);
\r
481 collection.InsertAll<int>(1, new int[] { 666, 777, 888 });
\r
482 //seen.Print(Console.Error);
\r
483 seen.Check(new CollectionEvent<int>[] {
\r
484 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(666,1), collection),
\r
485 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(666, 1), collection),
\r
486 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(777,2), collection),
\r
487 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(777, 1), collection),
\r
488 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(888,3), collection),
\r
489 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(888, 1), collection),
\r
490 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
492 collection.InsertAll<int>(1, new int[] { });
\r
493 seen.Check(new CollectionEvent<int>[] { });
\r
497 public void InsertFirstLast()
\r
499 collection.Add(4); collection.Add(56); collection.Add(18);
\r
501 collection.InsertFirst(45);
\r
502 seen.Check(new CollectionEvent<int>[] {
\r
503 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(45,0), collection),
\r
504 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), collection),
\r
505 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
507 collection.InsertLast(88);
\r
508 seen.Check(new CollectionEvent<int>[] {
\r
509 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(88,4), collection),
\r
510 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(88, 1), collection),
\r
511 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
516 public void Remove()
\r
518 collection.FIFO = false;
\r
519 collection.Add(4); collection.Add(56); collection.Add(18);
\r
521 collection.Remove();
\r
522 seen.Check(new CollectionEvent<int>[] {
\r
523 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(18, 1), collection),
\r
524 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
525 collection.FIFO = true;
\r
526 collection.Remove();
\r
527 seen.Check(new CollectionEvent<int>[] {
\r
528 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(4, 1), collection),
\r
529 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
533 public void RemoveFirst()
\r
535 collection.Add(4); collection.Add(56); collection.Add(18);
\r
537 collection.RemoveFirst();
\r
538 seen.Check(new CollectionEvent<int>[] {
\r
539 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(4,0), collection),
\r
540 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(4, 1), collection),
\r
541 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
545 public void RemoveLast()
\r
547 collection.Add(4); collection.Add(56); collection.Add(18);
\r
549 collection.RemoveLast();
\r
550 seen.Check(new CollectionEvent<int>[] {
\r
551 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(18,2), collection),
\r
552 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(18, 1), collection),
\r
553 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
557 public void Reverse()
\r
559 collection.Add(4); collection.Add(56); collection.Add(8);
\r
561 collection.Reverse();
\r
562 seen.Check(new CollectionEvent<int>[] {
\r
563 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
565 collection.View(1, 0).Reverse();
\r
566 seen.Check(new CollectionEvent<int>[] { });
\r
573 collection.Add(4); collection.Add(56); collection.Add(8);
\r
576 seen.Check(new CollectionEvent<int>[] {
\r
577 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
579 collection.View(1, 0).Sort();
\r
580 seen.Check(new CollectionEvent<int>[] { });
\r
584 public void Shuffle()
\r
586 collection.Add(4); collection.Add(56); collection.Add(8);
\r
588 collection.Shuffle();
\r
589 seen.Check(new CollectionEvent<int>[] {
\r
590 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
592 collection.View(1, 0).Shuffle();
\r
593 seen.Check(new CollectionEvent<int>[] { });
\r
597 public override void Clear()
\r
599 collection.Add(4); collection.Add(56); collection.Add(18);
\r
601 collection.View(1, 1).Clear();
\r
602 seen.Check(new CollectionEvent<int>[] {
\r
603 new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(false,1,1), collection),
\r
604 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
606 collection.Clear();
\r
607 seen.Check(new CollectionEvent<int>[] {
\r
608 new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(true,2,0), collection),
\r
609 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
611 collection.Clear();
\r
612 seen.Check(new CollectionEvent<int>[] { });
\r
616 public void ListDispose()
\r
618 collection.Add(4); collection.Add(56); collection.Add(18);
\r
620 collection.View(1, 1).Dispose();
\r
621 seen.Check(new CollectionEvent<int>[] { });
\r
622 collection.Dispose();
\r
623 seen.Check(new CollectionEvent<int>[] {
\r
624 new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(true,3,0), collection),
\r
625 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
627 collection.Dispose();
\r
628 seen.Check(new CollectionEvent<int>[] { });
\r
635 //public void Dispose() { list = null; seen = null; }
\r
638 [ExpectedException(typeof(UnlistenableEventException))]
\r
639 public void ViewChanged()
\r
641 IList<int> w = collection.View(0, 0);
\r
642 w.CollectionChanged += new CollectionChangedHandler<int>(w_CollectionChanged);
\r
646 [ExpectedException(typeof(UnlistenableEventException))]
\r
647 public void ViewCleared()
\r
649 IList<int> w = collection.View(0, 0);
\r
650 w.CollectionCleared += new CollectionClearedHandler<int>(w_CollectionCleared);
\r
654 [ExpectedException(typeof(UnlistenableEventException))]
\r
655 public void ViewAdded()
\r
657 IList<int> w = collection.View(0, 0);
\r
658 w.ItemsAdded += new ItemsAddedHandler<int>(w_ItemAdded);
\r
662 [ExpectedException(typeof(UnlistenableEventException))]
\r
663 public void ViewInserted()
\r
665 IList<int> w = collection.View(0, 0);
\r
666 w.ItemInserted += new ItemInsertedHandler<int>(w_ItemInserted);
\r
670 [ExpectedException(typeof(UnlistenableEventException))]
\r
671 public void ViewRemoved()
\r
673 IList<int> w = collection.View(0, 0);
\r
674 w.ItemsRemoved += new ItemsRemovedHandler<int>(w_ItemRemoved);
\r
678 [ExpectedException(typeof(UnlistenableEventException))]
\r
679 public void ViewRemovedAt()
\r
681 IList<int> w = collection.View(0, 0);
\r
682 w.ItemRemovedAt += new ItemRemovedAtHandler<int>(w_ItemRemovedAt);
\r
685 void w_CollectionChanged(object sender)
\r
687 throw new NotImplementedException();
\r
690 void w_CollectionCleared(object sender, ClearedEventArgs eventArgs)
\r
692 throw new NotImplementedException();
\r
695 void w_ItemAdded(object sender, ItemCountEventArgs<int> eventArgs)
\r
697 throw new NotImplementedException();
\r
700 void w_ItemInserted(object sender, ItemAtEventArgs<int> eventArgs)
\r
702 throw new NotImplementedException();
\r
705 void w_ItemRemoved(object sender, ItemCountEventArgs<int> eventArgs)
\r
707 throw new NotImplementedException();
\r
710 void w_ItemRemovedAt(object sender, ItemAtEventArgs<int> eventArgs)
\r
712 throw new NotImplementedException();
\r
716 public class StackTester<U> : CollectionValueTester<U> where U : IStack<int>
\r
718 public override SCG.IEnumerable<EventTypeEnum> GetSpecs()
\r
724 public void PushPop()
\r
727 seen.Check(new CollectionEvent<int>[0]);
\r
728 collection.Push(23);
\r
729 seen.Check(new CollectionEvent<int>[] {
\r
730 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(23,0), collection),
\r
731 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(23, 1), collection),
\r
732 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
733 collection.Push(-12);
\r
734 seen.Check(new CollectionEvent<int>[] {
\r
735 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(-12,1), collection),
\r
736 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(-12, 1), collection),
\r
737 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
739 seen.Check(new CollectionEvent<int>[] {
\r
740 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(-12,1), collection),
\r
741 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(-12, 1), collection),
\r
742 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
744 seen.Check(new CollectionEvent<int>[] {
\r
745 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(23,0), collection),
\r
746 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(23, 1), collection),
\r
747 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
751 public class QueueTester<U> : CollectionValueTester<U> where U : IQueue<int>
\r
753 public override SCG.IEnumerable<EventTypeEnum> GetSpecs()
\r
759 public void EnqueueDequeue()
\r
762 collection.Enqueue(67);
\r
763 seen.Check(new CollectionEvent<int>[] {
\r
764 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(67,0), collection),
\r
765 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), collection),
\r
766 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
767 collection.Enqueue(2);
\r
768 seen.Check(new CollectionEvent<int>[] {
\r
769 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(2,1), collection),
\r
770 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(2, 1), collection),
\r
771 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
772 collection.Dequeue();
\r
773 seen.Check(new CollectionEvent<int>[] {
\r
774 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(67,0), collection),
\r
775 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(67, 1), collection),
\r
776 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
777 collection.Dequeue();
\r
778 seen.Check(new CollectionEvent<int>[] {
\r
779 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(2,0), collection),
\r
780 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(2, 1), collection),
\r
781 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
786 public class PriorityQueueTester<U> : ExtensibleTester<U> where U : IPriorityQueue<int>
\r
788 public override System.Collections.Generic.IEnumerable<EventTypeEnum> GetSpecs()
\r
794 public void Direct()
\r
797 collection.Add(34);
\r
798 seen.Check(new CollectionEvent<int>[] {
\r
799 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(34, 1), collection),
\r
800 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection),
\r
802 collection.Add(56);
\r
803 seen.Check(new CollectionEvent<int>[] {
\r
804 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(56, 1), collection),
\r
805 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection),
\r
807 collection.AddAll<int>(new int[] { });
\r
808 seen.Check(new CollectionEvent<int>[] {
\r
810 collection.Add(34);
\r
811 seen.Check(new CollectionEvent<int>[] {
\r
812 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(34, 1), collection),
\r
813 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection),
\r
815 collection.Add(12);
\r
816 seen.Check(new CollectionEvent<int>[] {
\r
817 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(12, 1), collection),
\r
818 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection),
\r
820 collection.DeleteMax();
\r
821 seen.Check(new CollectionEvent<int>[] {
\r
822 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), collection),
\r
823 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection),
\r
825 collection.DeleteMin();
\r
826 seen.Check(new CollectionEvent<int>[] {
\r
827 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(12, 1), collection),
\r
828 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection),
\r
830 collection.AddAll<int>(new int[] { 4, 5, 6, 2 });
\r
831 seen.Check(new CollectionEvent<int>[] {
\r
832 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(4, 1), collection),
\r
833 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(5, 1), collection),
\r
834 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(6, 1), collection),
\r
835 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(2, 1), collection),
\r
836 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection)
\r
841 public void WithHandles()
\r
844 IPriorityQueueHandle<int> handle = null, handle2;
\r
845 collection.Add(34);
\r
846 seen.Check(new CollectionEvent<int>[] {
\r
847 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(34, 1), collection),
\r
848 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection),
\r
850 collection.Add(56);
\r
851 seen.Check(new CollectionEvent<int>[] {
\r
852 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(56, 1), collection),
\r
853 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection),
\r
855 collection.Add(ref handle, 34);
\r
856 seen.Check(new CollectionEvent<int>[] {
\r
857 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(34, 1), collection),
\r
858 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection),
\r
860 collection.Add(12);
\r
861 seen.Check(new CollectionEvent<int>[] {
\r
862 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(12, 1), collection),
\r
863 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection),
\r
865 collection.DeleteMax(out handle2);
\r
866 seen.Check(new CollectionEvent<int>[] {
\r
867 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), collection),
\r
868 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection),
\r
870 collection.DeleteMin(out handle2);
\r
871 seen.Check(new CollectionEvent<int>[] {
\r
872 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(12, 1), collection),
\r
873 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection),
\r
876 collection.Replace(handle, 117);
\r
877 seen.Check(new CollectionEvent<int>[] {
\r
878 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(34, 1), collection),
\r
879 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(117, 1), collection),
\r
880 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection),
\r
883 collection.Delete(handle);
\r
884 seen.Check(new CollectionEvent<int>[] {
\r
885 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(117, 1), collection),
\r
886 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), collection),
\r
891 public class DictionaryTester<U> : CollectionValueTester<U, KeyValuePair<int, int>> where U : IDictionary<int, int>
\r
893 public override SCG.IEnumerable<EventTypeEnum> GetSpecs()
\r
899 public virtual void Listenable()
\r
901 Assert.AreEqual(EventTypeEnum.Basic, collection.ListenableEvents);
\r
902 Assert.AreEqual(EventTypeEnum.None, collection.ActiveEvents);
\r
904 Assert.AreEqual(listenTo, collection.ActiveEvents);
\r
908 public void AddAndREmove()
\r
911 seen.Check(new CollectionEvent<KeyValuePair<int, int>>[0]);
\r
912 collection.Add(23, 45);
\r
913 seen.Check(new CollectionEvent<KeyValuePair<int,int>>[] {
\r
914 new CollectionEvent<KeyValuePair<int,int>>(EventTypeEnum.Added, new ItemCountEventArgs<KeyValuePair<int,int>>(new KeyValuePair<int,int>(23,45), 1), collection),
\r
915 new CollectionEvent<KeyValuePair<int,int>>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r
916 collection.Remove(25);
\r
917 seen.Check(new CollectionEvent<KeyValuePair<int, int>>[] {
\r
918 new CollectionEvent<KeyValuePair<int,int>>(EventTypeEnum.Removed, new ItemCountEventArgs<KeyValuePair<int,int>>(new KeyValuePair<int,int>(23,45), 1), collection),
\r
919 new CollectionEvent<KeyValuePair<int,int>>(EventTypeEnum.Changed, new EventArgs(), collection)});
\r