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
28 namespace C5UnitTests.wrappers
\r
35 private ArrayList<int> list;
\r
36 ICollectionValue<int> guarded;
\r
37 CollectionEventList<int> seen;
\r
42 list = new ArrayList<int>(TenEqualityComparer.Default);
\r
43 guarded = new GuardedList<int>(list);
\r
44 seen = new CollectionEventList<int>(IntEqualityComparer.Default);
\r
47 private void listen() { seen.Listen(guarded, EventTypeEnum.All); }
\r
50 public void Listenable()
\r
52 Assert.AreEqual(EventTypeEnum.All, guarded.ListenableEvents);
\r
53 Assert.AreEqual(EventTypeEnum.None, guarded.ActiveEvents);
\r
55 Assert.AreEqual(EventTypeEnum.All, guarded.ActiveEvents);
\r
59 public void SetThis()
\r
61 list.Add(4); list.Add(56); list.Add(8);
\r
64 seen.Check(new CollectionEvent<int>[] {
\r
65 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), guarded),
\r
66 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(56,1), guarded),
\r
67 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), guarded),
\r
68 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(45,1), guarded),
\r
69 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)
\r
74 public void Insert()
\r
76 list.Add(4); list.Add(56); list.Add(8);
\r
79 seen.Check(new CollectionEvent<int>[] {
\r
80 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(45,1), guarded),
\r
81 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), guarded),
\r
82 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)
\r
87 public void InsertAll()
\r
89 list.Add(4); list.Add(56); list.Add(8);
\r
91 list.InsertAll<int>(1, new int[] { 666, 777, 888 });
\r
92 //seen.Print(Console.Error);
\r
93 seen.Check(new CollectionEvent<int>[] {
\r
94 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(666,1), guarded),
\r
95 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(666, 1), guarded),
\r
96 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(777,2), guarded),
\r
97 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(777, 1), guarded),
\r
98 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(888,3), guarded),
\r
99 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(888, 1), guarded),
\r
100 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)
\r
102 list.InsertAll<int>(1, new int[] {});
\r
103 seen.Check(new CollectionEvent<int>[] {});
\r
107 public void InsertFirstLast()
\r
109 list.Add(4); list.Add(56); list.Add(8);
\r
111 list.InsertFirst(45);
\r
112 seen.Check(new CollectionEvent<int>[] {
\r
113 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(45,0), guarded),
\r
114 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), guarded),
\r
115 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)
\r
117 list.InsertLast(88);
\r
118 seen.Check(new CollectionEvent<int>[] {
\r
119 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(88,4), guarded),
\r
120 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(88, 1), guarded),
\r
121 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)
\r
126 public void Remove()
\r
128 list.Add(4); list.Add(56); list.Add(8);
\r
131 seen.Check(new CollectionEvent<int>[] {
\r
132 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(8, 1), guarded),
\r
133 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)});
\r
137 public void RemoveFirst()
\r
139 list.Add(4); list.Add(56); list.Add(8);
\r
141 list.RemoveFirst();
\r
142 seen.Check(new CollectionEvent<int>[] {
\r
143 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(4,0), guarded),
\r
144 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(4, 1), guarded),
\r
145 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)});
\r
149 public void RemoveLast()
\r
151 list.Add(4); list.Add(56); list.Add(8);
\r
154 seen.Check(new CollectionEvent<int>[] {
\r
155 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(8,2), guarded),
\r
156 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(8, 1), guarded),
\r
157 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)});
\r
161 public void Reverse()
\r
163 list.Add(4); list.Add(56); list.Add(8);
\r
166 seen.Check(new CollectionEvent<int>[] {
\r
167 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)
\r
169 list.View(1, 0).Reverse();
\r
170 seen.Check(new CollectionEvent<int>[] {});
\r
177 list.Add(4); list.Add(56); list.Add(8);
\r
180 seen.Check(new CollectionEvent<int>[] {
\r
181 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)
\r
183 list.View(1, 0).Sort();
\r
184 seen.Check(new CollectionEvent<int>[] {});
\r
188 public void Shuffle()
\r
190 list.Add(4); list.Add(56); list.Add(8);
\r
193 seen.Check(new CollectionEvent<int>[] {
\r
194 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)
\r
196 list.View(1, 0).Shuffle();
\r
197 seen.Check(new CollectionEvent<int>[] {});
\r
201 public void RemoveAt()
\r
203 list.Add(4); list.Add(56); list.Add(8);
\r
206 seen.Check(new CollectionEvent<int>[] {
\r
207 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(56,1), guarded),
\r
208 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), guarded),
\r
209 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)});
\r
213 public void RemoveInterval()
\r
215 list.Add(4); list.Add(56); list.Add(8);
\r
217 list.RemoveInterval(1, 2);
\r
218 seen.Check(new CollectionEvent<int>[] {
\r
219 new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(false,2,1), guarded),
\r
220 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)
\r
222 list.RemoveInterval(1, 0);
\r
223 seen.Check(new CollectionEvent<int>[] {});
\r
227 public void Update()
\r
229 list.Add(4); list.Add(56); list.Add(8);
\r
232 seen.Check(new CollectionEvent<int>[] {
\r
233 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), guarded),
\r
234 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(53, 1), guarded),
\r
235 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)
\r
238 seen.Check(new CollectionEvent<int>[] {});
\r
242 public void FindOrAdd()
\r
244 list.Add(4); list.Add(56); list.Add(8);
\r
247 list.FindOrAdd(ref val);
\r
248 seen.Check(new CollectionEvent<int>[] {});
\r
250 list.FindOrAdd(ref val);
\r
251 seen.Check(new CollectionEvent<int>[] {
\r
252 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), guarded),
\r
253 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)
\r
258 public void UpdateOrAdd()
\r
260 list.Add(4); list.Add(56); list.Add(8);
\r
263 list.UpdateOrAdd(val);
\r
264 seen.Check(new CollectionEvent<int>[] {
\r
265 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), guarded),
\r
266 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(53, 1), guarded),
\r
267 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)
\r
270 list.UpdateOrAdd(val);
\r
271 seen.Check(new CollectionEvent<int>[] {
\r
272 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), guarded),
\r
273 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)
\r
275 list.UpdateOrAdd(51, out val);
\r
276 seen.Check(new CollectionEvent<int>[] {
\r
277 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(53, 1), guarded),
\r
278 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(51, 1), guarded),
\r
279 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)
\r
282 list.UpdateOrAdd(81, out val);
\r
283 seen.Check(new CollectionEvent<int>[] {
\r
284 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(81, 1), guarded),
\r
285 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)
\r
290 public void RemoveItem()
\r
292 list.Add(4); list.Add(56); list.Add(18);
\r
295 seen.Check(new CollectionEvent<int>[] {
\r
296 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), guarded),
\r
297 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)});
\r
299 seen.Check(new CollectionEvent<int>[] {
\r
300 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(18, 1), guarded),
\r
301 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)});
\r
305 public void RemoveAll()
\r
307 for (int i = 0; i < 10; i++)
\r
309 list.Add(10 * i + 5);
\r
312 list.RemoveAll<int>(new int[] { 32, 187, 45 });
\r
313 //TODO: the order depends on internals of the HashSet
\r
314 seen.Check(new CollectionEvent<int>[] {
\r
315 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(35, 1), guarded),
\r
316 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(45, 1), guarded),
\r
317 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)});
\r
318 list.RemoveAll<int>(new int[] { 200, 300 });
\r
319 seen.Check(new CollectionEvent<int>[] {});
\r
323 public void Clear()
\r
325 list.Add(4); list.Add(56); list.Add(8);
\r
327 list.View(1, 1).Clear();
\r
328 seen.Check(new CollectionEvent<int>[] {
\r
329 new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(false,1,1), guarded),
\r
330 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)
\r
333 seen.Check(new CollectionEvent<int>[] {
\r
334 new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(true,2,0), guarded),
\r
335 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)
\r
338 seen.Check(new CollectionEvent<int>[] {});
\r
342 public void ListDispose()
\r
344 list.Add(4); list.Add(56); list.Add(8);
\r
346 list.View(1, 1).Dispose();
\r
347 seen.Check(new CollectionEvent<int>[] {});
\r
349 seen.Check(new CollectionEvent<int>[] {
\r
350 new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(true,3,0), guarded),
\r
351 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)
\r
354 seen.Check(new CollectionEvent<int>[] {});
\r
359 public void RetainAll()
\r
361 for (int i = 0; i < 10; i++)
\r
363 list.Add(10 * i + 5);
\r
366 list.RetainAll<int>(new int[] { 32, 187, 45, 62, 82, 95, 2 });
\r
367 seen.Check(new CollectionEvent<int>[] {
\r
368 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(15, 1), guarded),
\r
369 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(25, 1), guarded),
\r
370 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(55, 1), guarded),
\r
371 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(75, 1), guarded),
\r
372 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)});
\r
373 list.RetainAll<int>(new int[] { 32, 187, 45, 62, 82, 95, 2 });
\r
374 seen.Check(new CollectionEvent<int>[] {});
\r
378 public void RemoveAllCopies()
\r
380 for (int i = 0; i < 10; i++)
\r
382 list.Add(3 * i + 5);
\r
385 list.RemoveAllCopies(14);
\r
386 seen.Check(new CollectionEvent<int>[] {
\r
387 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(11, 1), guarded),
\r
388 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(14, 1), guarded),
\r
389 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(17, 1), guarded),
\r
390 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)});
\r
391 list.RemoveAllCopies(14);
\r
392 seen.Check(new CollectionEvent<int>[] {});
\r
399 seen.Check(new CollectionEvent<int>[0]);
\r
401 seen.Check(new CollectionEvent<int>[] {
\r
402 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(23, 1), guarded),
\r
403 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)});
\r
407 public void AddAll()
\r
409 for (int i = 0; i < 10; i++)
\r
411 list.Add(10 * i + 5);
\r
414 list.AddAll<int>(new int[] { 45, 56, 67 });
\r
415 seen.Check(new CollectionEvent<int>[] {
\r
416 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), guarded),
\r
417 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(56, 1), guarded),
\r
418 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), guarded),
\r
419 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)});
\r
420 list.AddAll<int>(new int[] { });
\r
421 seen.Check(new CollectionEvent<int>[] {});
\r
425 public void Dispose() { list = null; seen = null; }
\r
428 [ExpectedException(typeof(UnlistenableEventException))]
\r
429 public void ViewChanged()
\r
431 IList<int> w = list.View(0, 0);
\r
432 w.CollectionChanged += new CollectionChangedHandler<int>(w_CollectionChanged);
\r
436 [ExpectedException(typeof(UnlistenableEventException))]
\r
437 public void ViewCleared()
\r
439 IList<int> w = list.View(0, 0);
\r
440 w.CollectionCleared += new CollectionClearedHandler<int>(w_CollectionCleared);
\r
444 [ExpectedException(typeof(UnlistenableEventException))]
\r
445 public void ViewAdded()
\r
447 IList<int> w = list.View(0, 0);
\r
448 w.ItemsAdded += new ItemsAddedHandler<int>(w_ItemAdded);
\r
452 [ExpectedException(typeof(UnlistenableEventException))]
\r
453 public void ViewInserted()
\r
455 IList<int> w = list.View(0, 0);
\r
456 w.ItemInserted += new ItemInsertedHandler<int>(w_ItemInserted);
\r
460 [ExpectedException(typeof(UnlistenableEventException))]
\r
461 public void ViewRemoved()
\r
463 IList<int> w = list.View(0, 0);
\r
464 w.ItemsRemoved += new ItemsRemovedHandler<int>(w_ItemRemoved);
\r
468 [ExpectedException(typeof(UnlistenableEventException))]
\r
469 public void ViewRemovedAt()
\r
471 IList<int> w = list.View(0, 0);
\r
472 w.ItemRemovedAt += new ItemRemovedAtHandler<int>(w_ItemRemovedAt);
\r
475 void w_CollectionChanged(object sender)
\r
477 throw new NotImplementedException();
\r
480 void w_CollectionCleared(object sender, ClearedEventArgs eventArgs)
\r
482 throw new NotImplementedException();
\r
485 void w_ItemAdded(object sender, ItemCountEventArgs<int> eventArgs)
\r
487 throw new NotImplementedException();
\r
490 void w_ItemInserted(object sender, ItemAtEventArgs<int> eventArgs)
\r
492 throw new NotImplementedException();
\r
495 void w_ItemRemoved(object sender, ItemCountEventArgs<int> eventArgs)
\r
497 throw new NotImplementedException();
\r
500 void w_ItemRemovedAt(object sender, ItemAtEventArgs<int> eventArgs)
\r
502 throw new NotImplementedException();
\r
507 public class StackQueue
\r
509 private ArrayList<int> list;
\r
510 ICollectionValue<int> guarded;
\r
511 CollectionEventList<int> seen;
\r
516 list = new ArrayList<int>(TenEqualityComparer.Default);
\r
517 guarded = new GuardedList<int>(list);
\r
518 seen = new CollectionEventList<int>(IntEqualityComparer.Default);
\r
521 private void listen() { seen.Listen(guarded, EventTypeEnum.All); }
\r
525 public void EnqueueDequeue()
\r
529 seen.Check(new CollectionEvent<int>[] {
\r
530 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(67,0), guarded),
\r
531 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), guarded),
\r
532 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)});
\r
534 seen.Check(new CollectionEvent<int>[] {
\r
535 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(2,1), guarded),
\r
536 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(2, 1), guarded),
\r
537 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)});
\r
539 seen.Check(new CollectionEvent<int>[] {
\r
540 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(67,0), guarded),
\r
541 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(67, 1), guarded),
\r
542 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)});
\r
544 seen.Check(new CollectionEvent<int>[] {
\r
545 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(2,0), guarded),
\r
546 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(2, 1), guarded),
\r
547 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)});
\r
551 public void PushPop()
\r
554 seen.Check(new CollectionEvent<int>[0]);
\r
556 seen.Check(new CollectionEvent<int>[] {
\r
557 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(23,0), guarded),
\r
558 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(23, 1), guarded),
\r
559 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)});
\r
561 seen.Check(new CollectionEvent<int>[] {
\r
562 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(-12,1), guarded),
\r
563 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(-12, 1), guarded),
\r
564 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)});
\r
566 seen.Check(new CollectionEvent<int>[] {
\r
567 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(-12,1), guarded),
\r
568 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(-12, 1), guarded),
\r
569 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)});
\r
571 seen.Check(new CollectionEvent<int>[] {
\r
572 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(23,0), guarded),
\r
573 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(23, 1), guarded),
\r
574 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), guarded)});
\r
578 public void Dispose() { list = null; seen = null; }
\r
584 namespace wrappedarray
\r
596 public void Dispose()
\r
601 public void NoExc()
\r
603 WrappedArray<int> wrapped = new WrappedArray<int>(new int[] { 4, 6, 5 });
\r
604 Assert.AreEqual(6, wrapped[1]);
\r
605 Assert.IsTrue(IC.eq(wrapped[1, 2], 6, 5));
\r
607 Fun<int, bool> is4 = delegate(int i) { return i == 4; };
\r
608 Assert.AreEqual(EventTypeEnum.None, wrapped.ActiveEvents);
\r
609 Assert.AreEqual(false, wrapped.All(is4));
\r
610 Assert.AreEqual(true, wrapped.AllowsDuplicates);
\r
611 wrapped.Apply(delegate(int i) { });
\r
612 Assert.AreEqual("{ 5, 6, 4 }", wrapped.Backwards().ToString());
\r
613 Assert.AreEqual(true, wrapped.Check());
\r
615 Assert.AreEqual(true, wrapped.Contains(4));
\r
616 Assert.AreEqual(true, wrapped.ContainsAll(new ArrayList<int>()));
\r
617 Assert.AreEqual(1, wrapped.ContainsCount(4));
\r
618 Assert.AreEqual(Speed.Linear, wrapped.ContainsSpeed);
\r
619 int[] extarray = new int[5];
\r
620 wrapped.CopyTo(extarray, 1);
\r
621 Assert.IsTrue(IC.eq(extarray, 0, 4, 6, 5, 0));
\r
622 Assert.AreEqual(3, wrapped.Count);
\r
623 Assert.AreEqual(Speed.Constant, wrapped.CountSpeed);
\r
624 Assert.AreEqual(EnumerationDirection.Forwards, wrapped.Direction);
\r
625 Assert.AreEqual(false, wrapped.DuplicatesByCounting);
\r
626 Assert.AreEqual(IntEqualityComparer.Default, wrapped.EqualityComparer);
\r
627 Assert.AreEqual(true, wrapped.Exists(is4));
\r
628 Assert.IsTrue(IC.eq(wrapped.Filter(is4), 4));
\r
630 Assert.AreEqual(true, wrapped.Find(ref j));
\r
631 Assert.AreEqual(true, wrapped.Find(is4, out j));
\r
632 Assert.AreEqual("[ 0:4 ]", wrapped.FindAll(is4).ToString());
\r
633 Assert.AreEqual(0, wrapped.FindIndex(is4));
\r
634 Assert.AreEqual(true, wrapped.FindLast(is4, out j));
\r
635 Assert.AreEqual(0, wrapped.FindLastIndex(is4));
\r
636 Assert.AreEqual(4, wrapped.First);
\r
637 wrapped.GetEnumerator();
\r
638 Assert.AreEqual(CHC.sequencedhashcode(4, 6, 5), wrapped.GetSequencedHashCode());
\r
639 Assert.AreEqual(CHC.unsequencedhashcode(4, 6, 5), wrapped.GetUnsequencedHashCode());
\r
640 Assert.AreEqual(Speed.Constant, wrapped.IndexingSpeed);
\r
641 Assert.AreEqual(2, wrapped.IndexOf(5));
\r
642 Assert.AreEqual(false, wrapped.IsEmpty);
\r
643 Assert.AreEqual(true, wrapped.IsReadOnly);
\r
644 Assert.AreEqual(false, wrapped.IsSorted());
\r
645 Assert.AreEqual(true, wrapped.IsValid);
\r
646 Assert.AreEqual(5, wrapped.Last);
\r
647 Assert.AreEqual(2, wrapped.LastIndexOf(5));
\r
648 Assert.AreEqual(EventTypeEnum.None, wrapped.ListenableEvents);
\r
649 Fun<int, string> i2s = delegate(int i) { return string.Format("T{0}", i); };
\r
650 Assert.AreEqual("[ 0:T4, 1:T6, 2:T5 ]", wrapped.Map<string>(i2s).ToString());
\r
651 Assert.AreEqual(0, wrapped.Offset);
\r
653 Assert.AreEqual("[ 0:5, 1:6, 2:4 ]", wrapped.ToString());
\r
654 IList<int> other = new ArrayList<int>(); other.AddAll<int>(new int[] { 4, 5, 6 });
\r
655 Assert.IsFalse(wrapped.SequencedEquals(other));
\r
657 Assert.AreEqual(true, wrapped.Show(new System.Text.StringBuilder(), ref j, null));
\r
659 Assert.AreEqual("[ 0:4, 1:5, 2:6 ]", wrapped.ToString());
\r
660 Assert.IsNotNull(wrapped.SyncRoot);
\r
661 Assert.IsTrue(IC.eq(wrapped.ToArray(), 4, 5, 6));
\r
662 Assert.AreEqual("[ ... ]", wrapped.ToString("L4", null));
\r
663 Assert.AreEqual(null, wrapped.Underlying);
\r
664 Assert.IsTrue(IC.seteq(wrapped.UniqueItems(), 4, 5, 6));
\r
665 Assert.IsTrue(wrapped.UnsequencedEquals(other));
\r
667 Assert.IsTrue(IC.seteq(wrapped.UniqueItems(), 4, 5, 6));
\r
671 public void WithExc()
\r
673 WrappedArray<int> wrapped = new WrappedArray<int>(new int[] { 3, 4, 6, 5, 7 });
\r
675 try { wrapped.Add(1); Assert.Fail("No throw"); }
\r
676 catch (FixedSizeCollectionException) { }
\r
677 try { wrapped.AddAll<int>(null); Assert.Fail("No throw"); }
\r
678 catch (FixedSizeCollectionException) { }
\r
679 try { wrapped.Clear(); Assert.Fail("No throw"); }
\r
680 catch (FixedSizeCollectionException) { }
\r
681 try { wrapped.Dispose(); Assert.Fail("No throw"); }
\r
682 catch (FixedSizeCollectionException) { }
\r
684 try { wrapped.FindOrAdd(ref j); Assert.Fail("No throw"); }
\r
685 catch (FixedSizeCollectionException) { }
\r
686 try { wrapped.Insert(1, 1); Assert.Fail("No throw"); }
\r
687 catch (FixedSizeCollectionException) { }
\r
688 try { wrapped.Insert(wrapped.View(0, 0), 1); Assert.Fail("No throw"); }
\r
689 catch (FixedSizeCollectionException) { }
\r
690 try { wrapped.InsertAll<int>(1, null); Assert.Fail("No throw"); }
\r
691 catch (FixedSizeCollectionException) { }
\r
692 try { wrapped.InsertFirst(1); Assert.Fail("No throw"); }
\r
693 catch (FixedSizeCollectionException) { }
\r
694 try { wrapped.InsertLast(1); Assert.Fail("No throw"); }
\r
695 catch (FixedSizeCollectionException) { }
\r
696 try { wrapped.Remove(); Assert.Fail("No throw"); }
\r
697 catch (FixedSizeCollectionException) { }
\r
698 try { wrapped.Remove(1); Assert.Fail("No throw"); }
\r
699 catch (FixedSizeCollectionException) { }
\r
700 try { wrapped.RemoveAll<int>(null); Assert.Fail("No throw"); }
\r
701 catch (FixedSizeCollectionException) { }
\r
702 try { wrapped.RemoveAllCopies(1); Assert.Fail("No throw"); }
\r
703 catch (FixedSizeCollectionException) { }
\r
704 try { wrapped.RemoveAt(1); Assert.Fail("No throw"); }
\r
705 catch (FixedSizeCollectionException) { }
\r
706 try { wrapped.RemoveFirst(); Assert.Fail("No throw"); }
\r
707 catch (FixedSizeCollectionException) { }
\r
708 try { wrapped.RemoveInterval(0, 0); Assert.Fail("No throw"); }
\r
709 catch (FixedSizeCollectionException) { }
\r
710 try { wrapped.RemoveLast(); Assert.Fail("No throw"); }
\r
711 catch (FixedSizeCollectionException) { }
\r
712 try { wrapped.RetainAll<int>(null); Assert.Fail("No throw"); }
\r
713 catch (FixedSizeCollectionException) { }
\r
714 try { wrapped.Update(1, out j); Assert.Fail("No throw"); }
\r
715 catch (FixedSizeCollectionException) { }
\r
716 try { wrapped.UpdateOrAdd(1); Assert.Fail("No throw"); }
\r
717 catch (FixedSizeCollectionException) { }
\r
723 WrappedArray<int> outerwrapped = new WrappedArray<int>(new int[] { 3, 4, 6, 5, 7 });
\r
724 WrappedArray<int> wrapped = (WrappedArray<int>)outerwrapped.View(1, 3);
\r
726 Assert.AreEqual(6, wrapped[1]);
\r
727 Assert.IsTrue(IC.eq(wrapped[1, 2], 6, 5));
\r
729 Fun<int, bool> is4 = delegate(int i) { return i == 4; };
\r
730 Assert.AreEqual(EventTypeEnum.None, wrapped.ActiveEvents);
\r
731 Assert.AreEqual(false, wrapped.All(is4));
\r
732 Assert.AreEqual(true, wrapped.AllowsDuplicates);
\r
733 wrapped.Apply(delegate(int i) { });
\r
734 Assert.AreEqual("{ 5, 6, 4 }", wrapped.Backwards().ToString());
\r
735 Assert.AreEqual(true, wrapped.Check());
\r
737 Assert.AreEqual(true, wrapped.Contains(4));
\r
738 Assert.AreEqual(true, wrapped.ContainsAll(new ArrayList<int>()));
\r
739 Assert.AreEqual(1, wrapped.ContainsCount(4));
\r
740 Assert.AreEqual(Speed.Linear, wrapped.ContainsSpeed);
\r
741 int[] extarray = new int[5];
\r
742 wrapped.CopyTo(extarray, 1);
\r
743 Assert.IsTrue(IC.eq(extarray, 0, 4, 6, 5, 0));
\r
744 Assert.AreEqual(3, wrapped.Count);
\r
745 Assert.AreEqual(Speed.Constant, wrapped.CountSpeed);
\r
746 Assert.AreEqual(EnumerationDirection.Forwards, wrapped.Direction);
\r
747 Assert.AreEqual(false, wrapped.DuplicatesByCounting);
\r
748 Assert.AreEqual(IntEqualityComparer.Default, wrapped.EqualityComparer);
\r
749 Assert.AreEqual(true, wrapped.Exists(is4));
\r
750 Assert.IsTrue(IC.eq(wrapped.Filter(is4), 4));
\r
752 Assert.AreEqual(true, wrapped.Find(ref j));
\r
753 Assert.AreEqual(true, wrapped.Find(is4, out j));
\r
754 Assert.AreEqual("[ 0:4 ]", wrapped.FindAll(is4).ToString());
\r
755 Assert.AreEqual(0, wrapped.FindIndex(is4));
\r
756 Assert.AreEqual(true, wrapped.FindLast(is4, out j));
\r
757 Assert.AreEqual(0, wrapped.FindLastIndex(is4));
\r
758 Assert.AreEqual(4, wrapped.First);
\r
759 wrapped.GetEnumerator();
\r
760 Assert.AreEqual(CHC.sequencedhashcode(4, 6, 5), wrapped.GetSequencedHashCode());
\r
761 Assert.AreEqual(CHC.unsequencedhashcode(4, 6, 5), wrapped.GetUnsequencedHashCode());
\r
762 Assert.AreEqual(Speed.Constant, wrapped.IndexingSpeed);
\r
763 Assert.AreEqual(2, wrapped.IndexOf(5));
\r
764 Assert.AreEqual(false, wrapped.IsEmpty);
\r
765 Assert.AreEqual(true, wrapped.IsReadOnly);
\r
766 Assert.AreEqual(false, wrapped.IsSorted());
\r
767 Assert.AreEqual(true, wrapped.IsValid);
\r
768 Assert.AreEqual(5, wrapped.Last);
\r
769 Assert.AreEqual(2, wrapped.LastIndexOf(5));
\r
770 Assert.AreEqual(EventTypeEnum.None, wrapped.ListenableEvents);
\r
771 Fun<int, string> i2s = delegate(int i) { return string.Format("T{0}", i); };
\r
772 Assert.AreEqual("[ 0:T4, 1:T6, 2:T5 ]", wrapped.Map<string>(i2s).ToString());
\r
773 Assert.AreEqual(1, wrapped.Offset);
\r
775 Assert.AreEqual("[ 0:5, 1:6, 2:4 ]", wrapped.ToString());
\r
776 IList<int> other = new ArrayList<int>(); other.AddAll<int>(new int[] { 4, 5, 6 });
\r
777 Assert.IsFalse(wrapped.SequencedEquals(other));
\r
779 Assert.AreEqual(true, wrapped.Show(new System.Text.StringBuilder(), ref j, null));
\r
781 Assert.AreEqual("[ 0:4, 1:5, 2:6 ]", wrapped.ToString());
\r
782 Assert.IsNotNull(wrapped.SyncRoot);
\r
783 Assert.IsTrue(IC.eq(wrapped.ToArray(), 4, 5, 6));
\r
784 Assert.AreEqual("[ ... ]", wrapped.ToString("L4", null));
\r
785 Assert.AreEqual(outerwrapped, wrapped.Underlying);
\r
786 Assert.IsTrue(IC.seteq(wrapped.UniqueItems(), 4, 5, 6));
\r
787 Assert.IsTrue(wrapped.UnsequencedEquals(other));
\r
789 Assert.IsTrue(wrapped.TrySlide(1));
\r
790 Assert.IsTrue(IC.eq(wrapped, 5, 6, 7));
\r
791 Assert.IsTrue(wrapped.TrySlide(-1, 2));
\r
792 Assert.IsTrue(IC.eq(wrapped, 4, 5));
\r
793 Assert.IsFalse(wrapped.TrySlide(-2));
\r
794 Assert.IsTrue(IC.eq(wrapped.Span(outerwrapped.ViewOf(7)), 4, 5, 6, 7));
\r
797 Assert.IsTrue(IC.seteq(wrapped.UniqueItems(), 4, 5));
\r
798 Assert.IsTrue(wrapped.IsValid);
\r
800 Assert.IsFalse(wrapped.IsValid);
\r
804 public void ViewWithExc()
\r
806 WrappedArray<int> outerwrapped = new WrappedArray<int>(new int[] { 3, 4, 6, 5, 7 });
\r
807 WrappedArray<int> wrapped = (WrappedArray<int>)outerwrapped.View(1, 3);
\r
809 try { wrapped.Add(1); Assert.Fail("No throw"); }
\r
810 catch (FixedSizeCollectionException) { }
\r
811 try { wrapped.AddAll<int>(null); Assert.Fail("No throw"); }
\r
812 catch (FixedSizeCollectionException) { }
\r
813 try { wrapped.Clear(); Assert.Fail("No throw"); }
\r
814 catch (FixedSizeCollectionException) { }
\r
816 //try { wrapped.Dispose(); Assert.Fail("No throw"); }
\r
817 //catch (FixedSizeCollectionException) { }
\r
819 try { wrapped.FindOrAdd(ref j); Assert.Fail("No throw"); }
\r
820 catch (FixedSizeCollectionException) { }
\r
821 try { wrapped.Insert(1, 1); Assert.Fail("No throw"); }
\r
822 catch (FixedSizeCollectionException) { }
\r
823 try { wrapped.Insert(wrapped.View(0, 0), 1); Assert.Fail("No throw"); }
\r
824 catch (FixedSizeCollectionException) { }
\r
825 try { wrapped.InsertAll<int>(1, null); Assert.Fail("No throw"); }
\r
826 catch (FixedSizeCollectionException) { }
\r
827 try { wrapped.InsertFirst(1); Assert.Fail("No throw"); }
\r
828 catch (FixedSizeCollectionException) { }
\r
829 try { wrapped.InsertLast(1); Assert.Fail("No throw"); }
\r
830 catch (FixedSizeCollectionException) { }
\r
831 try { wrapped.Remove(); Assert.Fail("No throw"); }
\r
832 catch (FixedSizeCollectionException) { }
\r
833 try { wrapped.Remove(1); Assert.Fail("No throw"); }
\r
834 catch (FixedSizeCollectionException) { }
\r
835 try { wrapped.RemoveAll<int>(null); Assert.Fail("No throw"); }
\r
836 catch (FixedSizeCollectionException) { }
\r
837 try { wrapped.RemoveAllCopies(1); Assert.Fail("No throw"); }
\r
838 catch (FixedSizeCollectionException) { }
\r
839 try { wrapped.RemoveAt(1); Assert.Fail("No throw"); }
\r
840 catch (FixedSizeCollectionException) { }
\r
841 try { wrapped.RemoveFirst(); Assert.Fail("No throw"); }
\r
842 catch (FixedSizeCollectionException) { }
\r
843 try { wrapped.RemoveInterval(0, 0); Assert.Fail("No throw"); }
\r
844 catch (FixedSizeCollectionException) { }
\r
845 try { wrapped.RemoveLast(); Assert.Fail("No throw"); }
\r
846 catch (FixedSizeCollectionException) { }
\r
847 try { wrapped.RetainAll<int>(null); Assert.Fail("No throw"); }
\r
848 catch (FixedSizeCollectionException) { }
\r
849 try { wrapped.Update(1, out j); Assert.Fail("No throw"); }
\r
850 catch (FixedSizeCollectionException) { }
\r
851 try { wrapped.UpdateOrAdd(1); Assert.Fail("No throw"); }
\r
852 catch (FixedSizeCollectionException) { }
\r