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
27 namespace C5UnitTests.arrays.list
\r
29 using CollectionOfInt = ArrayList<int>;
\r
32 public class GenericTesters
\r
35 public void TestEvents()
\r
37 Fun<CollectionOfInt> factory = delegate() { return new CollectionOfInt(TenEqualityComparer.Default); };
\r
38 new C5UnitTests.Templates.Events.ListTester<CollectionOfInt>().Test(factory);
\r
39 new C5UnitTests.Templates.Events.QueueTester<CollectionOfInt>().Test(factory);
\r
40 new C5UnitTests.Templates.Events.StackTester<CollectionOfInt>().Test(factory);
\r
44 public void Extensible()
\r
46 C5UnitTests.Templates.Extensible.Clone.Tester<CollectionOfInt>();
\r
47 C5UnitTests.Templates.Extensible.Clone.ViewTester<CollectionOfInt>();
\r
48 C5UnitTests.Templates.Extensible.Serialization.Tester<CollectionOfInt>();
\r
49 C5UnitTests.Templates.Extensible.Serialization.ViewTester<CollectionOfInt>();
\r
53 static class Factory
\r
55 public static ICollection<T> New<T>() { return new ArrayList<T>(); }
\r
63 private ArrayList<int> list;
\r
64 CollectionEventList<int> seen;
\r
69 list = new ArrayList<int>(TenEqualityComparer.Default);
\r
70 seen = new CollectionEventList<int>(IntEqualityComparer.Default);
\r
73 private void listen() { seen.Listen(list, EventTypeEnum.Added); }
\r
76 public void Listenable()
\r
78 Assert.AreEqual(EventTypeEnum.All, list.ListenableEvents);
\r
79 Assert.AreEqual(EventTypeEnum.None, list.ActiveEvents);
\r
81 Assert.AreEqual(EventTypeEnum.Added, list.ActiveEvents);
\r
85 public void SetThis()
\r
87 list.Add(4); list.Add(56); list.Add(8);
\r
90 seen.Check(new CollectionEvent<int>[] {
\r
91 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), list),
\r
92 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(56,1), list),
\r
93 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), list),
\r
94 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(45,1), list),
\r
95 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
\r
100 public void Insert()
\r
102 list.Add(4); list.Add(56); list.Add(8);
\r
104 list.Insert(1, 45);
\r
105 seen.Check(new CollectionEvent<int>[] {
\r
106 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(45,1), list),
\r
107 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), list),
\r
108 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
\r
113 public void InsertAll()
\r
115 list.Add(4); list.Add(56); list.Add(8);
\r
117 list.InsertAll<int>(1, new int[] { 666, 777, 888 });
\r
118 //seen.Print(Console.Error);
\r
119 seen.Check(new CollectionEvent<int>[] {
\r
120 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(666,1), list),
\r
121 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(666, 1), list),
\r
122 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(777,2), list),
\r
123 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(777, 1), list),
\r
124 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(888,3), list),
\r
125 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(888, 1), list),
\r
126 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
\r
128 list.InsertAll<int>(1, new int[] {});
\r
129 seen.Check(new CollectionEvent<int>[] {});
\r
133 public void InsertFirstLast()
\r
135 list.Add(4); list.Add(56); list.Add(8);
\r
137 list.InsertFirst(45);
\r
138 seen.Check(new CollectionEvent<int>[] {
\r
139 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(45,0), list),
\r
140 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), list),
\r
141 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
\r
143 list.InsertLast(88);
\r
144 seen.Check(new CollectionEvent<int>[] {
\r
145 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(88,4), list),
\r
146 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(88, 1), list),
\r
147 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
\r
152 public void Remove()
\r
154 list.Add(4); list.Add(56); list.Add(8);
\r
157 seen.Check(new CollectionEvent<int>[] {
\r
158 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(8, 1), list),
\r
159 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
\r
163 public void RemoveFirst()
\r
165 list.Add(4); list.Add(56); list.Add(8);
\r
167 list.RemoveFirst();
\r
168 seen.Check(new CollectionEvent<int>[] {
\r
169 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(4,0), list),
\r
170 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(4, 1), list),
\r
171 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
\r
175 public void RemoveLast()
\r
177 list.Add(4); list.Add(56); list.Add(8);
\r
180 seen.Check(new CollectionEvent<int>[] {
\r
181 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(8,2), list),
\r
182 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(8, 1), list),
\r
183 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
\r
187 public void Reverse()
\r
189 list.Add(4); list.Add(56); list.Add(8);
\r
192 seen.Check(new CollectionEvent<int>[] {
\r
193 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
\r
195 list.View(1, 0).Reverse();
\r
196 seen.Check(new CollectionEvent<int>[] {});
\r
203 list.Add(4); list.Add(56); list.Add(8);
\r
206 seen.Check(new CollectionEvent<int>[] {
\r
207 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
\r
209 list.View(1, 0).Sort();
\r
210 seen.Check(new CollectionEvent<int>[] {});
\r
214 public void Shuffle()
\r
216 list.Add(4); list.Add(56); list.Add(8);
\r
219 seen.Check(new CollectionEvent<int>[] {
\r
220 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
\r
222 list.View(1, 0).Shuffle();
\r
223 seen.Check(new CollectionEvent<int>[] {});
\r
227 public void RemoveAt()
\r
229 list.Add(4); list.Add(56); list.Add(8);
\r
232 seen.Check(new CollectionEvent<int>[] {
\r
233 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(56,1), list),
\r
234 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), list),
\r
235 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
\r
239 public void RemoveInterval()
\r
241 list.Add(4); list.Add(56); list.Add(8);
\r
243 list.RemoveInterval(1, 2);
\r
244 seen.Check(new CollectionEvent<int>[] {
\r
245 new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(false,2,1), list),
\r
246 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
\r
248 list.RemoveInterval(1, 0);
\r
249 seen.Check(new CollectionEvent<int>[] {});
\r
253 public void Update()
\r
255 list.Add(4); list.Add(56); list.Add(8);
\r
258 seen.Check(new CollectionEvent<int>[] {
\r
259 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), list),
\r
260 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(53, 1), list),
\r
261 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
\r
264 seen.Check(new CollectionEvent<int>[] {});
\r
268 public void FindOrAdd()
\r
270 list.Add(4); list.Add(56); list.Add(8);
\r
273 list.FindOrAdd(ref val);
\r
274 seen.Check(new CollectionEvent<int>[] {});
\r
276 list.FindOrAdd(ref val);
\r
277 seen.Check(new CollectionEvent<int>[] {
\r
278 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), list),
\r
279 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
\r
284 public void UpdateOrAdd()
\r
286 list.Add(4); list.Add(56); list.Add(8);
\r
289 list.UpdateOrAdd(val);
\r
290 seen.Check(new CollectionEvent<int>[] {
\r
291 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), list),
\r
292 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(53, 1), list),
\r
293 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
\r
296 list.UpdateOrAdd(val);
\r
297 seen.Check(new CollectionEvent<int>[] {
\r
298 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), list),
\r
299 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
\r
301 list.UpdateOrAdd(51, out val);
\r
302 seen.Check(new CollectionEvent<int>[] {
\r
303 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(53, 1), list),
\r
304 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(51, 1), list),
\r
305 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
\r
308 list.UpdateOrAdd(81, out val);
\r
309 seen.Check(new CollectionEvent<int>[] {
\r
310 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(81, 1), list),
\r
311 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
\r
316 public void RemoveItem()
\r
318 list.Add(4); list.Add(56); list.Add(18);
\r
321 seen.Check(new CollectionEvent<int>[] {
\r
322 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), list),
\r
323 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
\r
325 seen.Check(new CollectionEvent<int>[] {
\r
326 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(18, 1), list),
\r
327 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
\r
331 public void RemoveAll()
\r
333 for (int i = 0; i < 10; i++)
\r
335 list.Add(10 * i + 5);
\r
338 list.RemoveAll<int>(new int[] { 32, 187, 45 });
\r
339 //TODO: the order depends on internals of the HashSet
\r
340 seen.Check(new CollectionEvent<int>[] {
\r
341 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(35, 1), list),
\r
342 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(45, 1), list),
\r
343 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
\r
344 list.RemoveAll<int>(new int[] { 200, 300 });
\r
345 seen.Check(new CollectionEvent<int>[] {});
\r
349 public void Clear()
\r
351 list.Add(4); list.Add(56); list.Add(8);
\r
353 list.View(1, 1).Clear();
\r
354 seen.Check(new CollectionEvent<int>[] {
\r
355 new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(false,1,1), list),
\r
356 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
\r
359 seen.Check(new CollectionEvent<int>[] {
\r
360 new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(true,2,0), list),
\r
361 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
\r
364 seen.Check(new CollectionEvent<int>[] {});
\r
368 public void ListDispose()
\r
370 list.Add(4); list.Add(56); list.Add(8);
\r
372 list.View(1, 1).Dispose();
\r
373 seen.Check(new CollectionEvent<int>[] {});
\r
375 seen.Check(new CollectionEvent<int>[] {
\r
376 new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(true,3,0), list),
\r
377 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
\r
380 seen.Check(new CollectionEvent<int>[] {});
\r
385 public void RetainAll()
\r
387 for (int i = 0; i < 10; i++)
\r
389 list.Add(10 * i + 5);
\r
392 list.RetainAll<int>(new int[] { 32, 187, 45, 62, 82, 95, 2 });
\r
393 seen.Check(new CollectionEvent<int>[] {
\r
394 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(15, 1), list),
\r
395 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(25, 1), list),
\r
396 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(55, 1), list),
\r
397 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(75, 1), list),
\r
398 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
\r
399 list.RetainAll<int>(new int[] { 32, 187, 45, 62, 82, 95, 2 });
\r
400 seen.Check(new CollectionEvent<int>[] {});
\r
404 public void RemoveAllCopies()
\r
406 for (int i = 0; i < 10; i++)
\r
408 list.Add(3 * i + 5);
\r
411 list.RemoveAllCopies(14);
\r
412 seen.Check(new CollectionEvent<int>[] {
\r
413 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(11, 1), list),
\r
414 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(14, 1), list),
\r
415 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(17, 1), list),
\r
416 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
\r
417 list.RemoveAllCopies(14);
\r
418 seen.Check(new CollectionEvent<int>[] {});
\r
425 seen.Check(new CollectionEvent<int>[0]);
\r
427 seen.Check(new CollectionEvent<int>[] {
\r
428 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(23, 1), list),
\r
429 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
\r
433 public void AddAll()
\r
435 for (int i = 0; i < 10; i++)
\r
437 list.Add(10 * i + 5);
\r
440 list.AddAll<int>(new int[] { 45, 56, 67 });
\r
441 seen.Check(new CollectionEvent<int>[] {
\r
442 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), list),
\r
443 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(56, 1), list),
\r
444 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), list),
\r
445 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
\r
446 list.AddAll<int>(new int[] { });
\r
447 seen.Check(new CollectionEvent<int>[] {});
\r
451 public void Dispose() { list = null; seen = null; }
\r
454 [ExpectedException(typeof(UnlistenableEventException))]
\r
455 public void ViewChanged()
\r
457 IList<int> w = list.View(0, 0);
\r
458 w.CollectionChanged += new CollectionChangedHandler<int>(w_CollectionChanged);
\r
462 [ExpectedException(typeof(UnlistenableEventException))]
\r
463 public void ViewCleared()
\r
465 IList<int> w = list.View(0, 0);
\r
466 w.CollectionCleared += new CollectionClearedHandler<int>(w_CollectionCleared);
\r
470 [ExpectedException(typeof(UnlistenableEventException))]
\r
471 public void ViewAdded()
\r
473 IList<int> w = list.View(0, 0);
\r
474 w.ItemsAdded += new ItemsAddedHandler<int>(w_ItemAdded);
\r
478 [ExpectedException(typeof(UnlistenableEventException))]
\r
479 public void ViewInserted()
\r
481 IList<int> w = list.View(0, 0);
\r
482 w.ItemInserted += new ItemInsertedHandler<int>(w_ItemInserted);
\r
486 [ExpectedException(typeof(UnlistenableEventException))]
\r
487 public void ViewRemoved()
\r
489 IList<int> w = list.View(0, 0);
\r
490 w.ItemsRemoved += new ItemsRemovedHandler<int>(w_ItemRemoved);
\r
494 [ExpectedException(typeof(UnlistenableEventException))]
\r
495 public void ViewRemovedAt()
\r
497 IList<int> w = list.View(0, 0);
\r
498 w.ItemRemovedAt += new ItemRemovedAtHandler<int>(w_ItemRemovedAt);
\r
501 void w_CollectionChanged(object sender)
\r
503 throw new NotImplementedException();
\r
506 void w_CollectionCleared(object sender, ClearedEventArgs eventArgs)
\r
508 throw new NotImplementedException();
\r
511 void w_ItemAdded(object sender, ItemCountEventArgs<int> eventArgs)
\r
513 throw new NotImplementedException();
\r
516 void w_ItemInserted(object sender, ItemAtEventArgs<int> eventArgs)
\r
518 throw new NotImplementedException();
\r
521 void w_ItemRemoved(object sender, ItemCountEventArgs<int> eventArgs)
\r
523 throw new NotImplementedException();
\r
526 void w_ItemRemovedAt(object sender, ItemAtEventArgs<int> eventArgs)
\r
528 throw new NotImplementedException();
\r
533 public class StackQueue
\r
536 private ArrayList<int> list;
\r
537 CollectionEventList<int> seen;
\r
542 list = new ArrayList<int>(TenEqualityComparer.Default);
\r
543 seen = new CollectionEventList<int>(IntEqualityComparer.Default);
\r
546 private void listen() { seen.Listen(list, EventTypeEnum.All); }
\r
549 public void EnqueueDequeue()
\r
553 seen.Check(new CollectionEvent<int>[] {
\r
554 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(67,0), list),
\r
555 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), list),
\r
556 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
\r
558 seen.Check(new CollectionEvent<int>[] {
\r
559 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(2,1), list),
\r
560 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(2, 1), list),
\r
561 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
\r
563 seen.Check(new CollectionEvent<int>[] {
\r
564 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(67,0), list),
\r
565 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(67, 1), list),
\r
566 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
\r
568 seen.Check(new CollectionEvent<int>[] {
\r
569 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(2,0), list),
\r
570 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(2, 1), list),
\r
571 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
\r
575 public void PushPop()
\r
578 seen.Check(new CollectionEvent<int>[0]);
\r
580 seen.Check(new CollectionEvent<int>[] {
\r
581 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(23,0), list),
\r
582 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(23, 1), list),
\r
583 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
\r
585 seen.Check(new CollectionEvent<int>[] {
\r
586 new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(-12,1), list),
\r
587 new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(-12, 1), list),
\r
588 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
\r
590 seen.Check(new CollectionEvent<int>[] {
\r
591 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(-12,1), list),
\r
592 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(-12, 1), list),
\r
593 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
\r
595 seen.Check(new CollectionEvent<int>[] {
\r
596 new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(23,0), list),
\r
597 new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(23, 1), list),
\r
598 new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
\r
602 public void Dispose() { list = null; seen = null; }
\r
609 /// Tests to see if the collection classes are robust for enumerable arguments that throw exceptions.
\r
612 public class BadEnumerable
\r
614 private ArrayList<int> list;
\r
619 list = new ArrayList<int>();
\r
623 public void InsertAll()
\r
625 list.Add(4); list.Add(56); list.Add(8);
\r
628 list.InsertAll<int>(1, new BadEnumerable<int>(new BadEnumerableException(), 9, 8, 7));
\r
629 Assert.Fail("Should not get here");
\r
631 catch (BadEnumerableException) { }
\r
632 Assert.IsTrue(list.Check());
\r
633 Assert.IsTrue(IC.eq(list, 4, 9, 8, 7, 56, 8));
\r
638 public void AddAll()
\r
640 list.Add(4); list.Add(56); list.Add(8);
\r
643 list.View(0, 1).AddAll<int>(new BadEnumerable<int>(new BadEnumerableException(), 9, 8, 7));
\r
644 Assert.Fail("Should not get here");
\r
646 catch (BadEnumerableException) { }
\r
647 Assert.IsTrue(list.Check());
\r
648 Assert.IsTrue(IC.eq(list, 4, 9, 8, 7, 56, 8));
\r
652 public void RemoveAll()
\r
654 list.Add(4); list.Add(56); list.Add(8);
\r
657 list.RemoveAll(new BadEnumerable<int>(new BadEnumerableException(), 9, 8, 7));
\r
658 Assert.Fail("Should not get here");
\r
660 catch (BadEnumerableException) { }
\r
661 Assert.IsTrue(list.Check());
\r
662 Assert.IsTrue(IC.eq(list, 4, 56, 8));
\r
666 public void RetainAll()
\r
668 list.Add(4); list.Add(56); list.Add(8);
\r
671 list.RetainAll(new BadEnumerable<int>(new BadEnumerableException(), 9, 8, 7));
\r
672 Assert.Fail("Should not get here");
\r
674 catch (BadEnumerableException) { }
\r
675 Assert.IsTrue(list.Check());
\r
676 Assert.IsTrue(IC.eq(list, 4, 56, 8));
\r
681 public void ContainsAll()
\r
683 list.Add(4); list.Add(56); list.Add(8);
\r
686 list.ContainsAll(new BadEnumerable<int>(new BadEnumerableException(), 4, 18));
\r
687 Assert.Fail("Should not get here");
\r
689 catch (BadEnumerableException) { }
\r
690 Assert.IsTrue(list.Check());
\r
691 Assert.IsTrue(IC.eq(list, 4, 56, 8));
\r
696 public void Dispose() { list = null; }
\r
700 /// Tests to see if the collection classes are robust for delegate arguments that throw exceptions.
\r
703 public class BadFun
\r
705 private ArrayList<int> list;
\r
710 list = new ArrayList<int>();
\r
714 public void NoTests() { }
\r
717 public void Dispose() { list = null; }
\r
721 namespace Enumerable
\r
724 public class Multiops
\r
726 private ArrayList<int> list;
\r
728 private Fun<int, bool> always, never, even;
\r
734 list = new ArrayList<int>();
\r
735 always = delegate { return true; };
\r
736 never = delegate { return false; };
\r
737 even = delegate(int i) { return i % 2 == 0; };
\r
744 Assert.IsTrue(list.All(always));
\r
745 Assert.IsTrue(list.All(never));
\r
746 Assert.IsTrue(list.All(even));
\r
748 Assert.IsTrue(list.All(always));
\r
749 Assert.IsFalse(list.All(never));
\r
750 Assert.IsTrue(list.All(even));
\r
752 Assert.IsTrue(list.All(always));
\r
753 Assert.IsFalse(list.All(never));
\r
754 Assert.IsFalse(list.All(even));
\r
759 public void Exists()
\r
761 Assert.IsFalse(list.Exists(always));
\r
762 Assert.IsFalse(list.Exists(never));
\r
763 Assert.IsFalse(list.Exists(even));
\r
765 Assert.IsTrue(list.Exists(always));
\r
766 Assert.IsFalse(list.Exists(never));
\r
767 Assert.IsFalse(list.Exists(even));
\r
769 Assert.IsTrue(list.Exists(always));
\r
770 Assert.IsFalse(list.Exists(never));
\r
771 Assert.IsTrue(list.Exists(even));
\r
776 public void Apply()
\r
779 Act<int> a = delegate(int i) { sum = i + 10 * sum; };
\r
782 Assert.AreEqual(0, sum);
\r
784 list.Add(5); list.Add(8); list.Add(7); list.Add(5);
\r
786 Assert.AreEqual(5875, sum);
\r
791 public void Dispose() { list = null; }
\r
797 public class GetEnumerator
\r
799 private ArrayList<int> list;
\r
803 public void Init() { list = new ArrayList<int>(); }
\r
807 public void Empty()
\r
809 SCG.IEnumerator<int> e = list.GetEnumerator();
\r
811 Assert.IsFalse(e.MoveNext());
\r
816 public void Normal()
\r
825 SCG.IEnumerator<int> e = list.GetEnumerator();
\r
827 Assert.IsTrue(e.MoveNext());
\r
828 Assert.AreEqual(5, e.Current);
\r
829 Assert.IsTrue(e.MoveNext());
\r
830 Assert.AreEqual(8, e.Current);
\r
831 Assert.IsTrue(e.MoveNext());
\r
832 Assert.AreEqual(5, e.Current);
\r
833 Assert.IsTrue(e.MoveNext());
\r
834 Assert.AreEqual(5, e.Current);
\r
835 Assert.IsTrue(e.MoveNext());
\r
836 Assert.AreEqual(10, e.Current);
\r
837 Assert.IsTrue(e.MoveNext());
\r
838 Assert.AreEqual(1, e.Current);
\r
839 Assert.IsFalse(e.MoveNext());
\r
844 public void DoDispose()
\r
850 SCG.IEnumerator<int> e = list.GetEnumerator();
\r
859 [ExpectedException(typeof(CollectionModifiedException))]
\r
860 public void MoveNextAfterUpdate()
\r
866 SCG.IEnumerator<int> e = list.GetEnumerator();
\r
874 public void Dispose() { list = null; }
\r
878 namespace CollectionOrSink
\r
881 public class Formatting
\r
883 ICollection<int> coll;
\r
884 IFormatProvider rad16;
\r
886 public void Init() { coll = Factory.New<int>(); rad16 = new RadixFormatProvider(16); }
\r
888 public void Dispose() { coll = null; rad16 = null; }
\r
890 public void Format()
\r
892 Assert.AreEqual("[ ]", coll.ToString());
\r
893 coll.AddAll<int>(new int[] { -4, 28, 129, 65530 });
\r
894 Assert.AreEqual("[ 0:-4, 1:28, 2:129, 3:65530 ]", coll.ToString());
\r
895 Assert.AreEqual("[ 0:-4, 1:1C, 2:81, 3:FFFA ]", coll.ToString(null, rad16));
\r
896 Assert.AreEqual("[ 0:-4, 1:28... ]", coll.ToString("L14", null));
\r
897 Assert.AreEqual("[ 0:-4, 1:1C... ]", coll.ToString("L14", rad16));
\r
902 public class CollectionOrSink
\r
904 private ArrayList<int> list;
\r
908 public void Init() { list = new ArrayList<int>(); }
\r
911 public void Choose()
\r
914 Assert.AreEqual(7, list.Choose());
\r
918 [ExpectedException(typeof(NoSuchItemException))]
\r
919 public void BadChoose()
\r
925 public void CountEtAl()
\r
927 Assert.AreEqual(0, list.Count);
\r
928 Assert.IsTrue(list.IsEmpty);
\r
929 Assert.IsTrue(list.AllowsDuplicates);
\r
931 Assert.AreEqual(1, list.Count);
\r
932 Assert.IsFalse(list.IsEmpty);
\r
934 Assert.AreEqual(2, list.Count);
\r
935 Assert.IsFalse(list.IsEmpty);
\r
937 Assert.AreEqual(3, list.Count);
\r
942 public void AddAll()
\r
944 list.Add(3); list.Add(4); list.Add(5);
\r
946 ArrayList<int> list2 = new ArrayList<int>();
\r
948 list2.AddAll(list);
\r
949 Assert.IsTrue(IC.eq(list2, 3, 4, 5));
\r
950 list.AddAll(list2);
\r
951 Assert.IsTrue(IC.eq(list2, 3, 4, 5));
\r
952 Assert.IsTrue(IC.eq(list, 3, 4, 5, 3, 4, 5));
\r
957 public void Dispose() { list = null; }
\r
961 public class FindPredicate
\r
963 private ArrayList<int> list;
\r
964 Fun<int, bool> pred;
\r
969 list = new ArrayList<int>(TenEqualityComparer.Default);
\r
970 pred = delegate(int i) { return i % 5 == 0; };
\r
974 public void Dispose() { list = null; }
\r
980 Assert.IsFalse(list.Find(pred, out i));
\r
981 list.AddAll<int>(new int[] { 4, 22, 67, 37 });
\r
982 Assert.IsFalse(list.Find(pred, out i));
\r
983 list.AddAll<int>(new int[] { 45, 122, 675, 137 });
\r
984 Assert.IsTrue(list.Find(pred, out i));
\r
985 Assert.AreEqual(45, i);
\r
989 public void FindLast()
\r
992 Assert.IsFalse(list.FindLast(pred, out i));
\r
993 list.AddAll<int>(new int[] { 4, 22, 67, 37 });
\r
994 Assert.IsFalse(list.FindLast(pred, out i));
\r
995 list.AddAll<int>(new int[] { 45, 122, 675, 137 });
\r
996 Assert.IsTrue(list.FindLast(pred, out i));
\r
997 Assert.AreEqual(675, i);
\r
1001 public void FindIndex()
\r
1003 Assert.IsFalse(0 <= list.FindIndex(pred));
\r
1004 list.AddAll<int>(new int[] { 4, 22, 67, 37 });
\r
1005 Assert.IsFalse(0 <= list.FindIndex(pred));
\r
1006 list.AddAll<int>(new int[] { 45, 122, 675, 137 });
\r
1007 Assert.AreEqual(4, list.FindIndex(pred));
\r
1011 public void FindLastIndex()
\r
1013 Assert.IsFalse(0 <= list.FindLastIndex(pred));
\r
1014 list.AddAll<int>(new int[] { 4, 22, 67, 37 });
\r
1015 Assert.IsFalse(0 <= list.FindLastIndex(pred));
\r
1016 list.AddAll<int>(new int[] { 45, 122, 675, 137 });
\r
1017 Assert.AreEqual(6, list.FindLastIndex(pred));
\r
1022 public class UniqueItems
\r
1024 private ArrayList<int> list;
\r
1027 public void Init() { list = new ArrayList<int>(); }
\r
1030 public void Dispose() { list = null; }
\r
1033 public void Test()
\r
1035 Assert.IsTrue(IC.seteq(list.UniqueItems()));
\r
1036 Assert.IsTrue(IC.seteq(list.ItemMultiplicities()));
\r
1037 list.AddAll<int>(new int[] { 7, 9, 7 });
\r
1038 Assert.IsTrue(IC.seteq(list.UniqueItems(), 7, 9));
\r
1039 Assert.IsTrue(IC.seteq(list.ItemMultiplicities(), 7, 2, 9, 1));
\r
1044 public class ArrayTest
\r
1046 private ArrayList<int> list;
\r
1052 public void Init()
\r
1054 list = new ArrayList<int>();
\r
1056 for (int i = 0; i < 10; i++)
\r
1062 public void Dispose() { list = null; }
\r
1065 private string aeq(int[] a, params int[] b)
\r
1067 if (a.Length != b.Length)
\r
1068 return "Lengths differ: " + a.Length + " != " + b.Length;
\r
1070 for (int i = 0; i < a.Length; i++)
\r
1072 return String.Format("{0}'th elements differ: {1} != {2}", i, a[i], b[i]);
\r
1074 return "Alles klar";
\r
1079 public void ToArray()
\r
1081 Assert.AreEqual("Alles klar", aeq(list.ToArray()));
\r
1084 Assert.AreEqual("Alles klar", aeq(list.ToArray(), 7, 7));
\r
1089 public void CopyTo()
\r
1091 list.CopyTo(a, 1);
\r
1092 Assert.AreEqual("Alles klar", aeq(a, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009));
\r
1094 list.CopyTo(a, 2);
\r
1095 Assert.AreEqual("Alles klar", aeq(a, 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009));
\r
1099 list.CopyTo(a, 4);
\r
1100 Assert.AreEqual("Alles klar", aeq(a, 1000, 1001, 6, 1003, 6, 4, 4, 9, 1008, 1009));
\r
1103 list.CopyTo(a, 9);
\r
1104 Assert.AreEqual("Alles klar", aeq(a, 1000, 1001, 6, 1003, 6, 4, 4, 9, 1008, 7));
\r
1109 [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1110 public void CopyToBad()
\r
1112 list.CopyTo(a, 11);
\r
1117 [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1118 public void CopyToBad2()
\r
1120 list.CopyTo(a, -1);
\r
1125 [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1126 public void CopyToTooFar()
\r
1130 list.CopyTo(a, 9);
\r
1137 private ArrayList<int> list;
\r
1141 public void Init()
\r
1143 list = new ArrayList<int>();
\r
1148 public void Dispose() { list = null; }
\r
1154 Assert.IsNotNull(list.SyncRoot);
\r
1162 namespace EditableCollection
\r
1165 public class Searching
\r
1167 private ArrayList<int> list;
\r
1171 public void Init() { list = new ArrayList<int>(); }
\r
1174 [ExpectedException(typeof(NullReferenceException))]
\r
1175 public void NullEqualityComparerinConstructor1()
\r
1177 new ArrayList<int>(null);
\r
1181 [ExpectedException(typeof(NullReferenceException))]
\r
1182 public void NullEqualityComparerinConstructor2()
\r
1184 new ArrayList<int>(5, null);
\r
1188 public void Contains()
\r
1190 Assert.IsFalse(list.Contains(5));
\r
1192 Assert.IsTrue(list.Contains(5));
\r
1193 Assert.IsFalse(list.Contains(7));
\r
1196 Assert.IsTrue(list.Contains(5));
\r
1197 Assert.IsFalse(list.Contains(7));
\r
1198 Assert.IsTrue(list.Contains(8));
\r
1199 Assert.IsTrue(list.Contains(10));
\r
1201 Assert.IsTrue(list.Contains(5));
\r
1202 Assert.IsFalse(list.Contains(7));
\r
1203 Assert.IsFalse(list.Contains(8));
\r
1204 Assert.IsTrue(list.Contains(10));
\r
1209 public void ContainsCount()
\r
1211 Assert.AreEqual(0, list.ContainsCount(5));
\r
1213 Assert.AreEqual(1, list.ContainsCount(5));
\r
1214 Assert.AreEqual(0, list.ContainsCount(7));
\r
1216 Assert.AreEqual(1, list.ContainsCount(5));
\r
1217 Assert.AreEqual(0, list.ContainsCount(7));
\r
1218 Assert.AreEqual(1, list.ContainsCount(8));
\r
1220 Assert.AreEqual(2, list.ContainsCount(5));
\r
1221 Assert.AreEqual(0, list.ContainsCount(7));
\r
1222 Assert.AreEqual(1, list.ContainsCount(8));
\r
1227 public void RemoveAllCopies()
\r
1229 list.Add(5); list.Add(7); list.Add(5);
\r
1230 Assert.AreEqual(2, list.ContainsCount(5));
\r
1231 Assert.AreEqual(1, list.ContainsCount(7));
\r
1232 list.RemoveAllCopies(5);
\r
1233 Assert.AreEqual(0, list.ContainsCount(5));
\r
1234 Assert.AreEqual(1, list.ContainsCount(7));
\r
1235 list.Add(5); list.Add(8); list.Add(5);
\r
1236 list.RemoveAllCopies(8);
\r
1237 Assert.IsTrue(IC.eq(list, 7, 5, 5));
\r
1242 public void FindAll()
\r
1244 Fun<int, bool> f = delegate(int i) { return i % 2 == 0; };
\r
1246 Assert.IsTrue(list.FindAll(f).IsEmpty);
\r
1247 list.Add(5); list.Add(8); list.Add(5); list.Add(10); list.Add(8);
\r
1248 Assert.IsTrue(((ArrayList<int>)list.FindAll(f)).Check());
\r
1249 Assert.IsTrue(IC.eq(list.FindAll(f), 8, 10, 8));
\r
1254 public void ContainsAll()
\r
1256 ArrayList<int> list2 = new ArrayList<int>();
\r
1258 Assert.IsTrue(list.ContainsAll(list2));
\r
1260 Assert.IsFalse(list.ContainsAll(list2));
\r
1262 Assert.IsTrue(list.ContainsAll(list2));
\r
1264 Assert.IsTrue(list.ContainsAll(list2));
\r
1266 Assert.IsFalse(list.ContainsAll(list2));
\r
1268 Assert.IsTrue(list.ContainsAll(list2));
\r
1273 public void RetainAll()
\r
1275 ArrayList<int> list2 = new ArrayList<int>();
\r
1277 list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6);
\r
1278 list2.Add(5); list2.Add(4); list2.Add(7); list2.Add(7); list2.Add(4);
\r
1279 list.RetainAll(list2);
\r
1280 Assert.IsTrue(list.Check());
\r
1281 Assert.IsTrue(IC.eq(list, 4, 4, 5));
\r
1282 list.Add(5); list.Add(4); list.Add(6);
\r
1284 list2.Add(5); list2.Add(5); list2.Add(6);
\r
1285 list.RetainAll(list2);
\r
1286 Assert.IsTrue(list.Check());
\r
1287 Assert.IsTrue(IC.eq(list, 5, 5, 6));
\r
1289 list2.Add(7); list2.Add(8); list2.Add(9);
\r
1290 list.RetainAll(list2);
\r
1291 Assert.IsTrue(list.Check());
\r
1292 Assert.IsTrue(IC.eq(list));
\r
1297 public void RemoveAll()
\r
1299 ArrayList<int> list2 = new ArrayList<int>();
\r
1301 list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6);
\r
1302 list2.Add(5); list2.Add(4); list2.Add(7); list2.Add(7); list2.Add(4);
\r
1303 list.RemoveAll(list2);
\r
1304 Assert.IsTrue(list.Check());
\r
1305 Assert.IsTrue(IC.eq(list, 4, 6));
\r
1306 list.Add(5); list.Add(4); list.Add(6);
\r
1308 list2.Add(6); list2.Add(5); list2.Add(5); list2.Add(6);
\r
1309 list.RemoveAll(list2);
\r
1310 Assert.IsTrue(list.Check());
\r
1311 Assert.IsTrue(IC.eq(list, 4, 4));
\r
1313 list2.Add(7); list2.Add(8); list2.Add(9);
\r
1314 list.RemoveAll(list2);
\r
1315 Assert.IsTrue(list.Check());
\r
1316 Assert.IsTrue(IC.eq(list, 4, 4));
\r
1321 public void Remove()
\r
1323 Assert.IsFalse(list.FIFO);
\r
1324 list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6);
\r
1325 Assert.IsFalse(list.Remove(2));
\r
1326 Assert.IsTrue(list.Check());
\r
1327 Assert.IsTrue(list.Remove(4));
\r
1328 Assert.IsTrue(list.Check());
\r
1329 Assert.IsTrue(IC.eq(list, 4, 4, 5, 6));
\r
1330 Assert.AreEqual(6, list.RemoveLast());
\r
1331 Assert.IsTrue(list.Check());
\r
1332 Assert.IsTrue(IC.eq(list, 4, 4, 5));
\r
1334 Assert.AreEqual(4, list.RemoveFirst());
\r
1335 Assert.IsTrue(list.Check());
\r
1336 Assert.IsTrue(IC.eq(list, 4, 5, 7));
\r
1340 list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6);
\r
1341 Assert.IsFalse(list.Remove(2));
\r
1342 Assert.IsTrue(list.Check());
\r
1343 Assert.IsTrue(list.Remove(4));
\r
1344 Assert.IsTrue(list.Check());
\r
1345 Assert.IsTrue(IC.eq(list, 4, 5, 4, 6));
\r
1346 Assert.AreEqual(6, list.RemoveLast());
\r
1347 Assert.IsTrue(list.Check());
\r
1348 Assert.IsTrue(IC.eq(list, 4, 5, 4));
\r
1350 Assert.AreEqual(4, list.RemoveFirst());
\r
1351 Assert.IsTrue(list.Check());
\r
1352 Assert.IsTrue(IC.eq(list, 5, 4, 7));
\r
1357 public void Clear()
\r
1359 list.Add(7); list.Add(7);
\r
1361 Assert.IsTrue(list.IsEmpty);
\r
1366 public void Dispose() { list = null; }
\r
1376 public class Searching
\r
1378 private IIndexed<int> dit;
\r
1382 public void Init()
\r
1384 dit = new ArrayList<int>();
\r
1389 public void IndexOf()
\r
1391 Assert.AreEqual(~0, dit.IndexOf(6));
\r
1393 Assert.AreEqual(~1, dit.IndexOf(6));
\r
1394 Assert.AreEqual(~1, dit.LastIndexOf(6));
\r
1395 Assert.AreEqual(0, dit.IndexOf(7));
\r
1396 dit.Add(5); dit.Add(7); dit.Add(8); dit.Add(7);
\r
1397 Assert.AreEqual(~5, dit.IndexOf(6));
\r
1398 Assert.AreEqual(0, dit.IndexOf(7));
\r
1399 Assert.AreEqual(4, dit.LastIndexOf(7));
\r
1400 Assert.AreEqual(3, dit.IndexOf(8));
\r
1401 Assert.AreEqual(1, dit.LastIndexOf(5));
\r
1406 public void Dispose()
\r
1415 public class Removing
\r
1417 private IIndexed<int> dit;
\r
1421 public void Init()
\r
1423 dit = new ArrayList<int>();
\r
1428 public void RemoveAt()
\r
1430 dit.Add(5); dit.Add(7); dit.Add(9); dit.Add(1); dit.Add(2);
\r
1431 Assert.AreEqual(7, dit.RemoveAt(1));
\r
1432 Assert.IsTrue(((ArrayList<int>)dit).Check());
\r
1433 Assert.IsTrue(IC.eq(dit, 5, 9, 1, 2));
\r
1434 Assert.AreEqual(5, dit.RemoveAt(0));
\r
1435 Assert.IsTrue(((ArrayList<int>)dit).Check());
\r
1436 Assert.IsTrue(IC.eq(dit, 9, 1, 2));
\r
1437 Assert.AreEqual(2, dit.RemoveAt(2));
\r
1438 Assert.IsTrue(((ArrayList<int>)dit).Check());
\r
1439 Assert.IsTrue(IC.eq(dit, 9, 1));
\r
1444 [ExpectedException(typeof(IndexOutOfRangeException))]
\r
1445 public void RemoveAtBad0()
\r
1452 [ExpectedException(typeof(IndexOutOfRangeException))]
\r
1453 public void RemoveAtBadM1()
\r
1460 [ExpectedException(typeof(IndexOutOfRangeException))]
\r
1461 public void RemoveAtBad1()
\r
1469 public void RemoveInterval()
\r
1471 dit.RemoveInterval(0, 0);
\r
1472 dit.Add(10); dit.Add(20); dit.Add(30); dit.Add(40); dit.Add(50); dit.Add(60);
\r
1473 dit.RemoveInterval(3, 0);
\r
1474 Assert.IsTrue(((ArrayList<int>)dit).Check());
\r
1475 Assert.IsTrue(IC.eq(dit, 10, 20, 30, 40, 50, 60));
\r
1476 dit.RemoveInterval(3, 1);
\r
1477 Assert.IsTrue(((ArrayList<int>)dit).Check());
\r
1478 Assert.IsTrue(IC.eq(dit, 10, 20, 30, 50, 60));
\r
1479 dit.RemoveInterval(1, 3);
\r
1480 Assert.IsTrue(((ArrayList<int>)dit).Check());
\r
1481 Assert.IsTrue(IC.eq(dit, 10, 60));
\r
1482 dit.RemoveInterval(0, 2);
\r
1483 Assert.IsTrue(((ArrayList<int>)dit).Check());
\r
1484 Assert.IsTrue(IC.eq(dit));
\r
1485 dit.Add(10); dit.Add(20); dit.Add(30); dit.Add(40); dit.Add(50); dit.Add(60);
\r
1486 dit.RemoveInterval(0, 2);
\r
1487 Assert.IsTrue(((ArrayList<int>)dit).Check());
\r
1488 Assert.IsTrue(IC.eq(dit, 30, 40, 50, 60));
\r
1489 dit.RemoveInterval(2, 2);
\r
1490 Assert.IsTrue(((ArrayList<int>)dit).Check());
\r
1491 Assert.IsTrue(IC.eq(dit, 30, 40));
\r
1496 public void Dispose()
\r
1509 public class Searching
\r
1511 private IList<int> lst;
\r
1515 public void Init() { lst = new ArrayList<int>(); }
\r
1519 public void Dispose() { lst = null; }
\r
1523 [ExpectedException(typeof(NoSuchItemException))]
\r
1524 public void FirstBad()
\r
1526 int f = lst.First;
\r
1531 [ExpectedException(typeof(NoSuchItemException))]
\r
1532 public void LastBad()
\r
1539 public void FirstLast()
\r
1542 Assert.AreEqual(19, lst.First);
\r
1543 Assert.AreEqual(19, lst.Last);
\r
1544 lst.Add(34); lst.InsertFirst(12);
\r
1545 Assert.AreEqual(12, lst.First);
\r
1546 Assert.AreEqual(34, lst.Last);
\r
1551 public void This()
\r
1554 Assert.AreEqual(34, lst[0]);
\r
1556 Assert.AreEqual(56, lst.First);
\r
1557 lst.Add(7); lst.Add(7); lst.Add(7); lst.Add(7);
\r
1558 lst[0] = 45; lst[2] = 78; lst[4] = 101;
\r
1559 Assert.IsTrue(IC.eq(lst, 45, 7, 78, 7, 101));
\r
1564 [ExpectedException(typeof(IndexOutOfRangeException))]
\r
1565 public void ThisBadEmptyGet()
\r
1572 [ExpectedException(typeof(IndexOutOfRangeException))]
\r
1573 public void ThisBadLowGet()
\r
1582 [ExpectedException(typeof(IndexOutOfRangeException))]
\r
1583 public void ThisBadHiGet()
\r
1592 [ExpectedException(typeof(IndexOutOfRangeException))]
\r
1593 public void ThisBadEmptySet()
\r
1600 [ExpectedException(typeof(IndexOutOfRangeException))]
\r
1601 public void ThisBadLowSet()
\r
1609 [ExpectedException(typeof(IndexOutOfRangeException))]
\r
1610 public void ThisBadHiSet()
\r
1620 public class Inserting
\r
1622 private IList<int> lst;
\r
1626 public void Init() { lst = new ArrayList<int>(); }
\r
1630 public void Dispose() { lst = null; }
\r
1634 public void Insert()
\r
1637 Assert.IsTrue(IC.eq(lst, 5));
\r
1639 Assert.IsTrue(IC.eq(lst, 7, 5));
\r
1641 Assert.IsTrue(IC.eq(lst, 7, 4, 5));
\r
1643 Assert.IsTrue(IC.eq(lst, 7, 4, 5, 2));
\r
1647 public void InsertDuplicate()
\r
1650 Assert.IsTrue(IC.eq(lst, 5));
\r
1652 Assert.IsTrue(IC.eq(lst, 7, 5));
\r
1654 Assert.IsTrue(IC.eq(lst, 7, 5, 5));
\r
1659 public void InsertAllDuplicate1()
\r
1662 Assert.IsTrue(IC.eq(lst, 3));
\r
1664 Assert.IsTrue(IC.eq(lst, 7, 3));
\r
1665 lst.InsertAll<int>(1, new int[] { 1, 2, 3, 4 });
\r
1666 Assert.IsTrue(IC.eq(lst, 7, 1, 2, 3, 4, 3));
\r
1667 Assert.IsTrue(lst.Check());
\r
1670 public void InsertAllDuplicate2()
\r
1673 Assert.IsTrue(IC.eq(lst, 3));
\r
1675 Assert.IsTrue(IC.eq(lst, 7, 3));
\r
1676 lst.InsertAll<int>(1, new int[] { 5, 6, 5, 8 });
\r
1677 Assert.IsTrue(lst.Check());
\r
1678 Assert.IsTrue(IC.eq(lst, 7, 5, 6, 5, 8, 3));
\r
1683 [ExpectedException(typeof(IndexOutOfRangeException))]
\r
1684 public void BadInsertLow()
\r
1687 lst.Insert(-1, 9);
\r
1692 [ExpectedException(typeof(IndexOutOfRangeException))]
\r
1693 public void BadInsertHi()
\r
1696 lst.Insert(2, 11);
\r
1701 public void FIFO()
\r
1703 for (int i = 0; i < 7; i++)
\r
1706 Assert.IsFalse(lst.FIFO);
\r
1707 Assert.AreEqual(12, lst.Remove());
\r
1708 Assert.AreEqual(10, lst.Remove());
\r
1710 Assert.AreEqual(0, lst.Remove());
\r
1711 Assert.AreEqual(2, lst.Remove());
\r
1713 Assert.AreEqual(8, lst.Remove());
\r
1714 Assert.AreEqual(6, lst.Remove());
\r
1719 public void InsertFirstLast()
\r
1721 lst.InsertFirst(4);
\r
1722 lst.InsertLast(5);
\r
1723 lst.InsertFirst(14);
\r
1724 lst.InsertLast(15);
\r
1725 lst.InsertFirst(24);
\r
1726 lst.InsertLast(25);
\r
1727 lst.InsertFirst(34);
\r
1728 lst.InsertLast(55);
\r
1729 Assert.IsTrue(IC.eq(lst, 34, 24, 14, 4, 5, 15, 25, 55));
\r
1734 public void InsertFirst()
\r
1740 lst.ViewOf(2).InsertFirst(7);
\r
1741 Assert.IsTrue(lst.Check());
\r
1742 Assert.IsTrue(IC.eq(lst, 7, 2, 3, 2, 5));
\r
1743 lst.ViewOf(3).InsertFirst(8);
\r
1744 Assert.IsTrue(lst.Check());
\r
1745 Assert.IsTrue(IC.eq(lst, 7, 2, 8, 3, 2, 5));
\r
1746 lst.ViewOf(5).InsertFirst(9);
\r
1747 Assert.IsTrue(lst.Check());
\r
1748 Assert.IsTrue(IC.eq(lst, 7, 2, 8, 3, 2, 9, 5));
\r
1752 public void InsertAfter()
\r
1759 lst.LastViewOf(2).InsertLast(7);
\r
1760 Assert.IsTrue(lst.Check());
\r
1761 Assert.IsTrue(IC.eq(lst, 1, 2, 3, 2, 7, 5));
\r
1762 lst.LastViewOf(1).InsertLast(8);
\r
1763 Assert.IsTrue(lst.Check());
\r
1764 Assert.IsTrue(IC.eq(lst, 1, 8, 2, 3, 2, 7, 5));
\r
1765 lst.LastViewOf(5).InsertLast(9);
\r
1766 Assert.IsTrue(lst.Check());
\r
1767 Assert.IsTrue(IC.eq(lst, 1, 8, 2, 3, 2, 7, 5, 9));
\r
1771 public void InsertAll()
\r
1778 IList<int> lst2 = new ArrayList<int>();
\r
1780 lst2.Add(7); lst2.Add(8); lst2.Add(9);
\r
1781 lst.InsertAll(0, lst2);
\r
1782 Assert.IsTrue(lst.Check());
\r
1783 Assert.IsTrue(IC.eq(lst, 7, 8, 9, 1, 2, 3, 4));
\r
1784 lst.InsertAll(7, lst2);
\r
1785 Assert.IsTrue(lst.Check());
\r
1786 Assert.IsTrue(IC.eq(lst, 7, 8, 9, 1, 2, 3, 4, 7, 8, 9));
\r
1787 lst.InsertAll(5, lst2);
\r
1788 Assert.IsTrue(lst.Check());
\r
1789 Assert.IsTrue(IC.eq(lst, 7, 8, 9, 1, 2, 7, 8, 9, 3, 4, 7, 8, 9));
\r
1796 Fun<int, string> m = delegate(int i) { return "<<" + i + ">>"; };
\r
1797 IList<string> r = lst.Map(m);
\r
1799 Assert.IsTrue(r.Check());
\r
1800 Assert.IsTrue(r.IsEmpty);
\r
1806 Assert.IsTrue(r.Check());
\r
1807 Assert.AreEqual(4, r.Count);
\r
1808 for (int i = 0; i < 4; i++)
\r
1809 Assert.AreEqual("<<" + (i + 1) + ">>", r[i]);
\r
1813 [ExpectedException(typeof(CollectionModifiedException))]
\r
1814 public void BadMapper()
\r
1819 Fun<int, bool> m = delegate(int i) { if (i == 2) lst.Add(7); return true; };
\r
1824 [ExpectedException(typeof(CollectionModifiedException))]
\r
1825 public void ModifyingFindAll()
\r
1830 Fun<int, bool> m = delegate(int i) { if (i == 2) lst.Add(7); return true; };
\r
1835 [ExpectedException(typeof(CollectionModifiedException))]
\r
1836 public void BadMapperView()
\r
1838 lst = lst.View(0, 0);
\r
1842 Fun<int, bool> m = delegate(int i) { if (i == 2) lst.Add(7); return true; };
\r
1847 [ExpectedException(typeof(CollectionModifiedException))]
\r
1848 public void ModifyingFindAllView()
\r
1850 lst = lst.View(0, 0);
\r
1854 Fun<int, bool> m = delegate(int i) { if (i == 2) lst.Add(7); return true; };
\r
1859 [ExpectedException(typeof(NoSuchItemException))]
\r
1860 public void BadRemove() { lst.Remove(); }
\r
1863 [ExpectedException(typeof(NoSuchItemException))]
\r
1864 public void BadRemoveFirst() { lst.RemoveFirst(); }
\r
1867 [ExpectedException(typeof(NoSuchItemException))]
\r
1868 public void BadRemoveLast() { lst.RemoveLast(); }
\r
1872 public void RemoveFirstLast()
\r
1878 Assert.AreEqual(1, lst.RemoveFirst());
\r
1879 Assert.AreEqual(4, lst.RemoveLast());
\r
1880 Assert.AreEqual(2, lst.RemoveFirst());
\r
1881 Assert.AreEqual(3, lst.RemoveLast());
\r
1882 Assert.IsTrue(lst.IsEmpty);
\r
1887 public void Reverse()
\r
1889 for (int i = 0; i < 10; i++)
\r
1893 Assert.IsTrue(lst.Check());
\r
1894 Assert.IsTrue(IC.eq(lst, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0));
\r
1895 lst.View(0, 3).Reverse();
\r
1896 Assert.IsTrue(lst.Check());
\r
1897 Assert.IsTrue(IC.eq(lst, 7, 8, 9, 6, 5, 4, 3, 2, 1, 0));
\r
1898 lst.View(7, 0).Reverse();
\r
1899 Assert.IsTrue(lst.Check());
\r
1900 Assert.IsTrue(IC.eq(lst, 7, 8, 9, 6, 5, 4, 3, 2, 1, 0));
\r
1901 lst.View(7, 3).Reverse();
\r
1902 Assert.IsTrue(lst.Check());
\r
1903 Assert.IsTrue(IC.eq(lst, 7, 8, 9, 6, 5, 4, 3, 0, 1, 2));
\r
1904 lst.View(5, 1).Reverse();
\r
1905 Assert.IsTrue(lst.Check());
\r
1906 Assert.IsTrue(IC.eq(lst, 7, 8, 9, 6, 5, 4, 3, 0, 1, 2));
\r
1911 [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1912 public void BadReverse()
\r
1914 for (int i = 0; i < 10; i++)
\r
1917 lst.View(8, 3).Reverse();
\r
1922 public class Combined
\r
1924 private IList<KeyValuePair<int, int>> lst;
\r
1928 public void Init()
\r
1930 lst = new ArrayList<KeyValuePair<int, int>>(new KeyValuePairEqualityComparer<int, int>());
\r
1931 for (int i = 0; i < 10; i++)
\r
1932 lst.Add(new KeyValuePair<int, int>(i, i + 30));
\r
1937 public void Dispose() { lst = null; }
\r
1941 public void Find()
\r
1943 KeyValuePair<int, int> p = new KeyValuePair<int, int>(3, 78);
\r
1944 Assert.IsTrue(lst.Find(ref p));
\r
1945 Assert.AreEqual(3, p.Key);
\r
1946 Assert.AreEqual(33, p.Value);
\r
1947 p = new KeyValuePair<int, int>(13, 78);
\r
1948 Assert.IsFalse(lst.Find(ref p));
\r
1953 public void FindOrAdd()
\r
1955 KeyValuePair<int, int> p = new KeyValuePair<int, int>(3, 78);
\r
1957 Assert.IsTrue(lst.FindOrAdd(ref p));
\r
1958 Assert.AreEqual(3, p.Key);
\r
1959 Assert.AreEqual(33, p.Value);
\r
1960 p = new KeyValuePair<int, int>(13, 79);
\r
1961 Assert.IsFalse(lst.FindOrAdd(ref p));
\r
1962 Assert.AreEqual(13, lst[10].Key);
\r
1963 Assert.AreEqual(79, lst[10].Value);
\r
1968 public void Update()
\r
1970 KeyValuePair<int, int> p = new KeyValuePair<int, int>(3, 78);
\r
1972 Assert.IsTrue(lst.Update(p));
\r
1973 Assert.AreEqual(3, lst[3].Key);
\r
1974 Assert.AreEqual(78, lst[3].Value);
\r
1975 p = new KeyValuePair<int, int>(13, 78);
\r
1976 Assert.IsFalse(lst.Update(p));
\r
1981 public void UpdateOrAdd()
\r
1983 KeyValuePair<int, int> p = new KeyValuePair<int, int>(3, 78);
\r
1985 Assert.IsTrue(lst.UpdateOrAdd(p));
\r
1986 Assert.AreEqual(3, lst[3].Key);
\r
1987 Assert.AreEqual(78, lst[3].Value);
\r
1988 p = new KeyValuePair<int, int>(13, 79);
\r
1989 Assert.IsFalse(lst.UpdateOrAdd(p));
\r
1990 Assert.AreEqual(13, lst[10].Key);
\r
1991 Assert.AreEqual(79, lst[10].Value);
\r
1996 public void RemoveWithReturn()
\r
1998 KeyValuePair<int, int> p = new KeyValuePair<int, int>(3, 78);
\r
2000 Assert.IsTrue(lst.Remove(p, out p));
\r
2001 Assert.AreEqual(3, p.Key);
\r
2002 Assert.AreEqual(33, p.Value);
\r
2003 Assert.AreEqual(4, lst[3].Key);
\r
2004 Assert.AreEqual(34, lst[3].Value);
\r
2005 p = new KeyValuePair<int, int>(13, 78);
\r
2006 Assert.IsFalse(lst.Remove(p, out p));
\r
2012 public class SortingTests
\r
2014 private IList<int> lst;
\r
2018 public void Init() { lst = new ArrayList<int>(); }
\r
2022 public void Dispose() { lst = null; }
\r
2026 public void Sort()
\r
2028 lst.Add(5); lst.Add(6); lst.Add(5); lst.Add(7); lst.Add(3);
\r
2029 Assert.IsFalse(lst.IsSorted(new IC()));
\r
2030 lst.Sort(new IC());
\r
2031 Assert.IsTrue(lst.IsSorted());
\r
2032 Assert.IsTrue(lst.IsSorted(new IC()));
\r
2033 Assert.IsTrue(IC.eq(lst, 3, 5, 5, 6, 7));
\r
2038 public void Stability()
\r
2040 IList<KeyValuePair<int, string>> lst2 = new ArrayList<KeyValuePair<int, string>>();
\r
2041 SCG.IComparer<KeyValuePair<int, string>> c = new KeyValuePairComparer<int, string>(new IC());
\r
2043 lst2.Add(new KeyValuePair<int, string>(5, "a"));
\r
2044 lst2.Add(new KeyValuePair<int, string>(5, "b"));
\r
2045 lst2.Add(new KeyValuePair<int, string>(6, "c"));
\r
2046 lst2.Add(new KeyValuePair<int, string>(4, "d"));
\r
2047 lst2.Add(new KeyValuePair<int, string>(3, "e"));
\r
2048 lst2.Add(new KeyValuePair<int, string>(4, "f"));
\r
2049 lst2.Add(new KeyValuePair<int, string>(5, "handle"));
\r
2050 Assert.IsFalse(lst2.IsSorted(c));
\r
2052 Assert.IsTrue(lst2.IsSorted(c));
\r
2054 KeyValuePair<int, string> p = lst2.RemoveFirst();
\r
2056 Assert.AreEqual(3, p.Key);
\r
2057 Assert.AreEqual("e", p.Value);
\r
2058 p = lst2.RemoveFirst();
\r
2059 Assert.AreEqual(4, p.Key);
\r
2060 Assert.AreEqual("d", p.Value);
\r
2061 p = lst2.RemoveFirst();
\r
2062 Assert.AreEqual(4, p.Key);
\r
2063 Assert.AreEqual("f", p.Value);
\r
2064 p = lst2.RemoveFirst();
\r
2065 Assert.AreEqual(5, p.Key);
\r
2066 Assert.AreEqual("a", p.Value);
\r
2067 p = lst2.RemoveFirst();
\r
2068 Assert.AreEqual(5, p.Key);
\r
2069 Assert.AreEqual("b", p.Value);
\r
2070 p = lst2.RemoveFirst();
\r
2071 Assert.AreEqual(5, p.Key);
\r
2072 Assert.AreEqual("handle", p.Value);
\r
2073 p = lst2.RemoveFirst();
\r
2074 Assert.AreEqual(6, p.Key);
\r
2075 Assert.AreEqual("c", p.Value);
\r
2076 Assert.IsTrue(lst2.IsEmpty);
\r
2081 public class ShuffleTests
\r
2083 private IList<int> lst;
\r
2087 public void Init() { lst = new ArrayList<int>(); }
\r
2091 public void Dispose() { lst = null; }
\r
2095 public void Shuffle()
\r
2097 lst.Add(5); lst.Add(6); lst.Add(5); lst.Add(7); lst.Add(3);
\r
2098 for (int i = 0; i < 100; i++)
\r
2100 lst.Shuffle(new C5Random(i + 1));
\r
2101 Assert.IsTrue(lst.Check(), "Check " + i);
\r
2102 int[] lst2 = lst.ToArray();
\r
2103 Sorting.IntroSort<int>(lst2);
\r
2104 Assert.IsTrue(IC.eq(lst2, 3, 5, 5, 6, 7), "Contents " + i);
\r
2112 namespace IStackQueue
\r
2115 public class Stack
\r
2117 private IStack<int> list;
\r
2121 public void Init() { list = new ArrayList<int>(); }
\r
2125 public void Normal()
\r
2132 Assert.AreEqual(9, list.Pop());
\r
2133 Assert.AreEqual(8, list.Pop());
\r
2134 Assert.AreEqual(7, list.Pop());
\r
2135 Assert.AreEqual(5, list.Pop());
\r
2136 Assert.AreEqual(7, list.Pop());
\r
2141 [ExpectedException(typeof(NoSuchItemException))]
\r
2142 public void PopEmpty()
\r
2145 Assert.AreEqual(5, list.Pop());
\r
2151 public void Dispose() { list = null; }
\r
2154 public class Queue
\r
2156 private IQueue<int> list;
\r
2160 public void Init() { list = new ArrayList<int>(); }
\r
2164 public void Normal()
\r
2171 Assert.AreEqual(7, list.Dequeue());
\r
2172 Assert.AreEqual(5, list.Dequeue());
\r
2173 Assert.AreEqual(7, list.Dequeue());
\r
2174 Assert.AreEqual(8, list.Dequeue());
\r
2175 Assert.AreEqual(9, list.Dequeue());
\r
2180 [ExpectedException(typeof(NoSuchItemException))]
\r
2181 public void DeQueueEmpty()
\r
2184 Assert.AreEqual(5, list.Dequeue());
\r
2190 public void Dispose() { list = null; }
\r
2198 public class Range
\r
2200 private IList<int> lst;
\r
2204 public void Init() { lst = new ArrayList<int>(); }
\r
2208 public void Dispose() { lst = null; }
\r
2212 public void GetRange()
\r
2214 //Assert.IsTrue(IC.eq(lst[0, 0)));
\r
2215 for (int i = 0; i < 10; i++) lst.Add(i);
\r
2217 Assert.IsTrue(IC.eq(lst[0, 3], 0, 1, 2));
\r
2218 Assert.IsTrue(IC.eq(lst[3, 4], 3, 4, 5, 6));
\r
2219 Assert.IsTrue(IC.eq(lst[6, 4], 6, 7, 8, 9));
\r
2224 [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
2225 public void BadGetRange()
\r
2227 object foo = lst[0, 11];
\r
2232 public void Backwards()
\r
2234 for (int i = 0; i < 10; i++) lst.Add(i);
\r
2236 Assert.IsTrue(IC.eq(lst.Backwards(), 9, 8, 7, 6, 5, 4, 3, 2, 1, 0));
\r
2237 Assert.IsTrue(IC.eq(lst[0, 4].Backwards(), 3, 2, 1, 0));
\r
2238 Assert.IsTrue(IC.eq(lst[3, 4].Backwards(), 6, 5, 4, 3));
\r
2239 Assert.IsTrue(IC.eq(lst[6, 4].Backwards(), 9, 8, 7, 6));
\r
2244 public void DirectionAndCount()
\r
2246 for (int i = 0; i < 10; i++) lst.Add(i);
\r
2248 Assert.AreEqual(EnumerationDirection.Forwards, lst.Direction);
\r
2249 Assert.AreEqual(EnumerationDirection.Forwards, lst[3, 4].Direction);
\r
2250 Assert.AreEqual(EnumerationDirection.Backwards, lst[3, 4].Backwards().Direction);
\r
2251 Assert.AreEqual(EnumerationDirection.Backwards, lst.Backwards().Direction);
\r
2252 Assert.AreEqual(4, lst[3, 4].Count);
\r
2253 Assert.AreEqual(4, lst[3, 4].Backwards().Count);
\r
2254 Assert.AreEqual(10, lst.Backwards().Count);
\r
2259 [ExpectedException(typeof(CollectionModifiedException))]
\r
2260 public void MoveNextAfterUpdate()
\r
2262 for (int i = 0; i < 10; i++) lst.Add(i);
\r
2264 foreach (int i in lst)
\r
2278 public class Simple
\r
2280 ArrayList<int> list, view;
\r
2284 public void Init()
\r
2286 list = new ArrayList<int>();
\r
2287 list.Add(0); list.Add(1); list.Add(2); list.Add(3);
\r
2288 view = (ArrayList<int>)list.View(1, 2);
\r
2293 public void Dispose()
\r
2295 list = view = null;
\r
2301 Assert.IsTrue(list.Check());
\r
2302 Assert.IsTrue(view.Check());
\r
2306 //static void pint(IEnumerable<int> l) { foreach (int cell in l) Console.WriteLine(cell); }
\r
2309 public void InsertPointer()
\r
2311 IList<int> view2 = list.View(2, 0);
\r
2312 list.Insert(view2, 7);
\r
2314 list.Insert(list, 8);
\r
2316 view.Insert(view2, 9);
\r
2318 view.Insert(list.View(3, 2), 10);
\r
2320 view.Insert(list.ViewOf(0), 11);
\r
2322 Assert.IsTrue(IC.eq(list, 0, 11, 1, 9, 7, 2, 10, 3, 8));
\r
2323 Assert.IsTrue(IC.eq(view, 11, 1, 9, 7, 2, 10));
\r
2327 [ExpectedException(typeof(IndexOutOfRangeException))]
\r
2328 public void InsertPointerBad1()
\r
2330 view.Insert(list.View(0, 0), 7);
\r
2334 [ExpectedException(typeof(IndexOutOfRangeException))]
\r
2335 public void InsertPointerBad2()
\r
2337 view.Insert(list, 7);
\r
2341 [ExpectedException(typeof(IncompatibleViewException))]
\r
2342 public void InsertPointerBad3()
\r
2344 list.Insert(new ArrayList<int>(), 7);
\r
2348 [ExpectedException(typeof(IncompatibleViewException))]
\r
2349 public void InsertPointerBad4()
\r
2351 list.Insert(new ArrayList<int>().View(0, 0), 7);
\r
2356 public void Span()
\r
2358 IList<int> span = list.View(1, 0).Span(list.View(2, 0));
\r
2359 Assert.IsTrue(span.Check());
\r
2360 Assert.AreEqual(1, span.Offset);
\r
2361 Assert.AreEqual(1, span.Count);
\r
2362 span = list.View(0, 2).Span(list.View(2, 2));
\r
2363 Assert.IsTrue(span.Check());
\r
2364 Assert.AreEqual(0, span.Offset);
\r
2365 Assert.AreEqual(4, span.Count);
\r
2366 span = list.View(3, 1).Span(list.View(1, 1));
\r
2367 Assert.IsNull(span);
\r
2371 public void ViewOf()
\r
2373 for (int i = 0; i < 4; i++)
\r
2375 IList<int> v = view.ViewOf(2);
\r
2376 Assert.IsTrue(v.Check());
\r
2377 Assert.IsTrue(IC.eq(v, 2));
\r
2378 Assert.AreEqual(2, v.Offset);
\r
2379 v = list.ViewOf(2);
\r
2380 Assert.IsTrue(v.Check());
\r
2381 Assert.IsTrue(IC.eq(v, 2));
\r
2382 Assert.AreEqual(2, v.Offset);
\r
2383 v = list.LastViewOf(2);
\r
2384 Assert.IsTrue(v.Check());
\r
2385 Assert.IsTrue(IC.eq(v, 2));
\r
2386 Assert.AreEqual(6, v.Offset);
\r
2390 public void ArrayStuff()
\r
2392 Assert.IsTrue(IC.eq(view.ToArray(), 1, 2));
\r
2393 int[] extarray = new int[5];
\r
2394 view.CopyTo(extarray, 2);
\r
2395 Assert.IsTrue(IC.eq(extarray, 0, 0, 1, 2, 0));
\r
2399 public void BadViewOf()
\r
2401 Assert.IsNull(view.ViewOf(5));
\r
2402 Assert.IsNull(view.LastViewOf(5));
\r
2403 Assert.IsNull(view.ViewOf(3));
\r
2404 Assert.IsNull(view.LastViewOf(3));
\r
2405 Assert.IsNull(view.ViewOf(0));
\r
2406 Assert.IsNull(view.LastViewOf(0));
\r
2413 Assert.IsTrue(IC.eq(list, 0, 1, 2, 3));
\r
2414 Assert.IsTrue(IC.eq(view, 1, 2));
\r
2415 view.InsertFirst(10);
\r
2417 Assert.IsTrue(IC.eq(list, 0, 10, 1, 2, 3));
\r
2418 Assert.IsTrue(IC.eq(view, 10, 1, 2));
\r
2420 Assert.IsFalse(view.IsReadOnly);
\r
2421 Assert.IsTrue(view.AllowsDuplicates);
\r
2422 Assert.IsTrue(view.IsEmpty);
\r
2424 Assert.IsTrue(IC.eq(list, 0, 3));
\r
2425 Assert.IsTrue(IC.eq(view));
\r
2427 Assert.IsFalse(view.IsEmpty);
\r
2428 Assert.IsTrue(view.AllowsDuplicates);
\r
2429 Assert.IsFalse(view.IsReadOnly);
\r
2431 Assert.IsTrue(IC.eq(list, 0, 8, 3));
\r
2432 Assert.IsTrue(IC.eq(view, 8));
\r
2435 Assert.IsTrue(IC.eq(list, 0, 8, 12, 3));
\r
2436 Assert.IsTrue(IC.eq(view, 8, 12));
\r
2437 view./*ViewOf(12)*/InsertLast(15);
\r
2439 Assert.IsTrue(IC.eq(list, 0, 8, 12, 15, 3));
\r
2440 Assert.IsTrue(IC.eq(view, 8, 12, 15));
\r
2441 view.ViewOf(12).InsertFirst(18);
\r
2443 Assert.IsTrue(IC.eq(list, 0, 8, 18, 12, 15, 3));
\r
2444 Assert.IsTrue(IC.eq(view, 8, 18, 12, 15));
\r
2446 ArrayList<int> lst2 = new ArrayList<int>();
\r
2448 lst2.Add(90); lst2.Add(92);
\r
2449 view.AddAll(lst2);
\r
2451 Assert.IsTrue(IC.eq(list, 0, 8, 18, 12, 15, 90, 92, 3));
\r
2452 Assert.IsTrue(IC.eq(view, 8, 18, 12, 15, 90, 92));
\r
2453 view.InsertLast(66);
\r
2456 Assert.IsTrue(IC.eq(list, 0, 8, 18, 12, 15, 90, 92, 66, 3));
\r
2457 Assert.IsTrue(IC.eq(view, 8, 18, 12, 15, 90, 92, 66));
\r
2462 public void Bxxx()
\r
2464 Assert.IsTrue(IC.eq(view.Backwards(), 2, 1));
\r
2465 Assert.AreSame(list, view.Underlying);
\r
2466 Assert.IsNull(list.Underlying);
\r
2467 Assert.AreEqual(EnumerationDirection.Forwards, view.Direction);
\r
2468 Assert.AreEqual(EnumerationDirection.Backwards, view.Backwards().Direction);
\r
2469 Assert.AreEqual(0, list.Offset);
\r
2470 Assert.AreEqual(1, view.Offset);
\r
2475 public void Contains()
\r
2477 Assert.IsTrue(view.Contains(1));
\r
2478 Assert.IsFalse(view.Contains(0));
\r
2480 ArrayList<int> lst2 = new ArrayList<int>();
\r
2483 Assert.IsTrue(view.ContainsAll(lst2));
\r
2485 Assert.IsFalse(view.ContainsAll(lst2));
\r
2486 Assert.AreEqual(Speed.Linear, view.ContainsSpeed);
\r
2487 Assert.AreEqual(2, view.Count);
\r
2489 Assert.AreEqual(1, view.ContainsCount(2));
\r
2490 Assert.AreEqual(2, view.ContainsCount(1));
\r
2491 Assert.AreEqual(3, view.Count);
\r
2496 public void CreateView()
\r
2498 ArrayList<int> view2 = (ArrayList<int>)view.View(1, 0);
\r
2500 Assert.AreSame(list, view2.Underlying);
\r
2505 public void FIFO()
\r
2507 Assert.IsFalse(view.FIFO);
\r
2509 view.Add(23); view.Add(24); view.Add(25);
\r
2511 Assert.IsTrue(IC.eq(view, 1, 2, 23, 24, 25));
\r
2512 Assert.AreEqual(1, view.Remove());
\r
2514 Assert.IsTrue(IC.eq(view, 2, 23, 24, 25));
\r
2515 view.FIFO = false;
\r
2516 Assert.IsFalse(view.FIFO);
\r
2517 Assert.AreEqual(25, view.Remove());
\r
2519 Assert.IsTrue(IC.eq(view, 2, 23, 24));
\r
2524 public void MapEtc()
\r
2526 ArrayList<double> dbl = (ArrayList<double>)view.Map(new Fun<int, double>(delegate(int i) { return i / 10.0; }));
\r
2528 Assert.IsTrue(dbl.Check());
\r
2529 Assert.AreEqual(0.1, dbl[0]);
\r
2530 Assert.AreEqual(0.2, dbl[1]);
\r
2531 for (int i = 0; i < 10; i++) view.Add(i);
\r
2533 list = (ArrayList<int>)view.FindAll(new Fun<int, bool>(delegate(int i) { return i % 4 == 1; }));
\r
2534 Assert.IsTrue(list.Check());
\r
2535 Assert.IsTrue(IC.eq(list, 1, 1, 5, 9));
\r
2542 Assert.AreEqual(1, view.First);
\r
2543 Assert.AreEqual(2, view.Last);
\r
2548 public void Indexing()
\r
2551 for (int i = 0; i < 20; i++) list.Add(i);
\r
2553 view = (ArrayList<int>)list.View(5, 7);
\r
2554 for (int i = 0; i < 7; i++) Assert.AreEqual(i + 5, view[i]);
\r
2556 for (int i = 0; i < 7; i++) Assert.AreEqual(i, view.IndexOf(i + 5));
\r
2558 for (int i = 0; i < 7; i++) Assert.AreEqual(i, view.LastIndexOf(i + 5));
\r
2563 public void Insert()
\r
2565 view.Insert(0, 34);
\r
2566 view.Insert(1, 35);
\r
2567 view.Insert(4, 36);
\r
2568 Assert.IsTrue(view.Check());
\r
2569 Assert.IsTrue(IC.eq(view, 34, 35, 1, 2, 36));
\r
2571 IList<int> list2 = new ArrayList<int>();
\r
2573 list2.AddAll(view);
\r
2574 view.InsertAll(3, list2);
\r
2575 Assert.IsTrue(view.Check());
\r
2576 Assert.IsTrue(IC.eq(view, 34, 35, 1, 34, 35, 1, 2, 36, 2, 36));
\r
2580 [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
2581 public void RangeCheck1()
\r
2583 IList<int> lst = new ArrayList<int>();
\r
2585 lst = lst.View(1, 1);
\r
2589 [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
2590 public void RangeCheck2()
\r
2592 IList<int> lst = new ArrayList<int>();
\r
2594 lst = lst.View(1, -1);
\r
2599 public void Sort()
\r
2601 view.Add(45); view.Add(47); view.Add(46); view.Add(48);
\r
2602 Assert.IsFalse(view.IsSorted(new IC()));
\r
2603 view.Sort(new IC());
\r
2605 Assert.IsTrue(IC.eq(list, 0, 1, 2, 45, 46, 47, 48, 3));
\r
2606 Assert.IsTrue(IC.eq(view, 1, 2, 45, 46, 47, 48));
\r
2611 public void Remove()
\r
2613 view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0);
\r
2614 Assert.IsTrue(IC.eq(view, 1, 2, 1, 5, 3, 1, 3, 0));
\r
2615 Assert.IsTrue(view.Remove(1));
\r
2617 Assert.IsTrue(IC.eq(view, 1, 2, 1, 5, 3, 3, 0));
\r
2618 Assert.IsTrue(view.Remove(1));
\r
2620 Assert.IsTrue(IC.eq(view, 1, 2, 5, 3, 3, 0));
\r
2621 Assert.IsTrue(view.Remove(0));
\r
2623 Assert.IsTrue(IC.eq(view, 1, 2, 5, 3, 3));
\r
2624 view.RemoveAllCopies(3);
\r
2626 Assert.IsTrue(IC.eq(view, 1, 2, 5));
\r
2627 Assert.IsTrue(IC.eq(list, 0, 1, 2, 5, 3));
\r
2628 view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0);
\r
2629 Assert.IsTrue(IC.eq(view, 1, 2, 5, 1, 5, 3, 1, 3, 0));
\r
2632 view.Clear(); view.Add(1); view.Add(2);
\r
2634 view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0);
\r
2635 Assert.IsTrue(IC.eq(view, 1, 2, 1, 5, 3, 1, 3, 0));
\r
2636 Assert.IsTrue(view.Remove(1));
\r
2638 Assert.IsTrue(IC.eq(view, 2, 1, 5, 3, 1, 3, 0));
\r
2639 Assert.IsTrue(view.Remove(1));
\r
2641 Assert.IsTrue(IC.eq(view, 2, 5, 3, 1, 3, 0));
\r
2642 Assert.IsTrue(view.Remove(0));
\r
2644 Assert.IsTrue(IC.eq(view, 2, 5, 3, 1, 3));
\r
2645 view.RemoveAllCopies(3);
\r
2647 Assert.IsTrue(IC.eq(view, 2, 5, 1));
\r
2648 Assert.IsTrue(IC.eq(list, 0, 2, 5, 1, 3));
\r
2649 view.Add(1); view.Add(5); view.Add(3); view.Add(1); view.Add(3); view.Add(0);
\r
2650 Assert.IsTrue(IC.eq(view, 2, 5, 1, 1, 5, 3, 1, 3, 0));
\r
2652 view.FIFO = false;
\r
2654 ArrayList<int> l2 = new ArrayList<int>();
\r
2656 l2.Add(1); l2.Add(2); l2.Add(2); l2.Add(3); l2.Add(1);
\r
2657 view.RemoveAll(l2);
\r
2659 Assert.IsTrue(IC.eq(view, 5, 5, 1, 3, 0));
\r
2660 view.RetainAll(l2);
\r
2662 Assert.IsTrue(IC.eq(view, 1, 3));
\r
2663 view.Add(2); view.Add(4); view.Add(5);
\r
2664 Assert.AreEqual(1, view.RemoveAt(0));
\r
2665 Assert.AreEqual(5, view.RemoveAt(3));
\r
2666 Assert.AreEqual(2, view.RemoveAt(1));
\r
2668 Assert.IsTrue(IC.eq(view, 3, 4));
\r
2670 Assert.AreEqual(3, view.RemoveFirst());
\r
2671 Assert.AreEqual(8, view.RemoveLast());
\r
2672 view.Add(2); view.Add(5); view.Add(3); view.Add(1);
\r
2673 view.RemoveInterval(1, 2);
\r
2675 Assert.IsTrue(IC.eq(view, 4, 3, 1));
\r
2680 public void Reverse()
\r
2683 for (int i = 0; i < 10; i++) view.Add(10 + i);
\r
2685 view.View(3, 4).Reverse();
\r
2687 Assert.IsTrue(IC.eq(view, 10, 11, 12, 16, 15, 14, 13, 17, 18, 19));
\r
2689 Assert.IsTrue(IC.eq(view, 19, 18, 17, 13, 14, 15, 16, 12, 11, 10));
\r
2690 Assert.IsTrue(IC.eq(list, 0, 19, 18, 17, 13, 14, 15, 16, 12, 11, 10, 3));
\r
2695 public void Slide()
\r
2699 Assert.IsTrue(IC.eq(view, 2, 3));
\r
2702 Assert.IsTrue(IC.eq(view, 0, 1));
\r
2705 Assert.IsTrue(IC.eq(view, 0, 1, 2));
\r
2708 Assert.IsTrue(IC.eq(view, 2));
\r
2709 Assert.AreEqual(view, view.Slide(-1, 0));
\r
2711 Assert.IsTrue(IC.eq(view));
\r
2713 Assert.IsTrue(IC.eq(list, 0, 28, 1, 2, 3));
\r
2716 public void Iterate()
\r
2720 foreach (int i in new int[] { 2, 4, 8, 13, 6, 1, 2, 7 }) list.Add(i);
\r
2722 view = (ArrayList<int>)list.View(list.Count - 2, 2);
\r
2725 if ((view.Last - view.First) % 2 == 1)
\r
2726 view.Insert(1, 666);
\r
2728 if (view.Offset == 0)
\r
2731 view.Slide(-1, 2);
\r
2733 Assert.IsTrue(list.Check());
\r
2734 Assert.IsTrue(IC.eq(list, 2, 4, 8, 666, 13, 6, 1, 666, 2, 666, 7));
\r
2739 public void SyncRoot()
\r
2741 Assert.AreSame(view.SyncRoot, list.SyncRoot);
\r
2745 public class MulipleViews
\r
2748 IList<int>[][] views;
\r
2750 public void Init()
\r
2752 list = new ArrayList<int>();
\r
2753 for (int i = 0; i < 6; i++)
\r
2755 views = new IList<int>[7][];
\r
2756 for (int i = 0; i < 7; i++)
\r
2758 views[i] = new IList<int>[7 - i];
\r
2759 for (int j = 0; j < 7 - i; j++)
\r
2760 views[i][j] = list.View(i, j);
\r
2764 public void Dispose()
\r
2770 public void Insert()
\r
2772 Assert.IsTrue(list.Check(), "list check before insert");
\r
2773 list.Insert(3, 777);
\r
2774 Assert.IsTrue(list.Check(), "list check after insert");
\r
2775 for (int i = 0; i < 7; i++)
\r
2776 for (int j = 0; j < 7 - i; j++)
\r
2778 Assert.AreEqual(i < 3 || (i == 3 && j == 0) ? i : i + 1, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
\r
2779 Assert.AreEqual(i < 3 && i + j > 3 ? j + 1 : j, views[i][j].Count, "view[" + i + "][" + j + "] count");
\r
2783 public void RemoveAt()
\r
2785 Assert.IsTrue(list.Check(), "list check before remove");
\r
2787 Assert.IsTrue(list.Check(), "list check after remove");
\r
2788 for (int i = 0; i < 7; i++)
\r
2789 for (int j = 0; j < 7 - i; j++)
\r
2791 Assert.AreEqual(i <= 3 ? i : i - 1, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
\r
2792 Assert.AreEqual(i <= 3 && i + j > 3 ? j - 1 : j, views[i][j].Count, "view[" + i + "][" + j + "] count");
\r
2797 public void RemoveInterval()
\r
2799 Assert.IsTrue(list.Check(), "list check before remove");
\r
2800 list.RemoveInterval(3, 2);
\r
2801 Assert.IsTrue(list.Check(), "list check after remove");
\r
2802 for (int i = 0; i < 7; i++)
\r
2803 for (int j = 0; j < 7 - i; j++)
\r
2805 Assert.AreEqual(i <= 3 ? i : i <= 5 ? 3 : i - 2, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
\r
2806 Assert.AreEqual(j == 0 ? 0 : i <= 3 && i + j > 4 ? j - 2 : i > 4 || i + j <= 3 ? j : j - 1, views[i][j].Count, "view[" + i + "][" + j + "] count");
\r
2812 public void InsertAtEnd()
\r
2814 Assert.IsTrue(list.Check(), "list check before insert");
\r
2815 list.InsertLast(777);
\r
2816 Assert.IsTrue(list.Check(), "list check after insert");
\r
2817 for (int i = 0; i < 7; i++)
\r
2818 for (int j = 0; j < 7 - i; j++)
\r
2820 Assert.AreEqual(i, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
\r
2821 Assert.AreEqual(j, views[i][j].Count, "view[" + i + "][" + j + "] count");
\r
2825 public void RemoveAtEnd()
\r
2827 Assert.IsTrue(list.Check(), "list check before remove");
\r
2829 Assert.IsTrue(list.Check(), "list check after remove");
\r
2830 for (int i = 0; i < 7; i++)
\r
2831 for (int j = 0; j < 7 - i; j++)
\r
2833 Assert.AreEqual(i <= 5 ? i : i - 1, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
\r
2834 Assert.AreEqual(i <= 5 && i + j > 5 ? j - 1 : j, views[i][j].Count, "view[" + i + "][" + j + "] count");
\r
2838 public void InsertAtStart()
\r
2840 Assert.IsTrue(list.Check(), "list check before insert");
\r
2841 list.Insert(0, 777);
\r
2842 Assert.IsTrue(list.Check(), "list check after insert");
\r
2843 for (int i = 0; i < 7; i++)
\r
2844 for (int j = 0; j < 7 - i; j++)
\r
2846 Assert.AreEqual(i == 0 && j == 0 ? 0 : i + 1, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
\r
2847 Assert.AreEqual(j, views[i][j].Count, "view[" + i + "][" + j + "] count");
\r
2851 public void RemoveAtStart()
\r
2853 Assert.IsTrue(list.Check(), "list check before remove");
\r
2855 Assert.IsTrue(list.Check(), "list check after remove");
\r
2856 for (int i = 0; i < 7; i++)
\r
2857 for (int j = 0; j < 7 - i; j++)
\r
2859 Assert.AreEqual(i == 0 ? i : i - 1, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
\r
2860 Assert.AreEqual(i == 0 && j > 0 ? j - 1 : j, views[i][j].Count, "view[" + i + "][" + j + "] count");
\r
2864 public void Clear()
\r
2866 Assert.IsTrue(list.Check(), "list check before clear");
\r
2867 views[2][3].Clear();
\r
2868 Assert.IsTrue(list.Check(), "list check after clear");
\r
2869 for (int i = 0; i < 7; i++)
\r
2870 for (int j = 0; j < 7 - i; j++)
\r
2872 Assert.AreEqual(i < 2 ? i : i < 6 ? 2 : i - 3, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
\r
2873 Assert.AreEqual(s(i, j), views[i][j].Count, "view[" + i + "][" + j + "] count");
\r
2877 private int s(int i, int j)
\r
2879 if (j == 0) return 0;
\r
2880 int k = i + j - 1; //end
\r
2881 if (i > 4 || k <= 1) return j;
\r
2882 if (i >= 2) return k > 4 ? k - 4 : 0;
\r
2883 if (i <= 2) return k >= 4 ? j - 3 : 2 - i;
\r
2887 public void InsertAll()
\r
2889 ArrayList<int> list2 = new ArrayList<int>();
\r
2890 for (int i = 0; i < 5; i++) { list2.Add(100 + i); }
\r
2891 Assert.IsTrue(list.Check(), "list check before insertAll");
\r
2892 list.InsertAll(3, list2);
\r
2893 Assert.IsTrue(list.Check(), "list check after insertAll");
\r
2894 for (int i = 0; i < 7; i++)
\r
2895 for (int j = 0; j < 7 - i; j++)
\r
2897 Assert.AreEqual(i < 3 || (i == 3 && j == 0) ? i : i + 5, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
\r
2898 Assert.AreEqual(i < 3 && i + j > 3 ? j + 5 : j, views[i][j].Count, "view[" + i + "][" + j + "] count");
\r
2903 public void AddAll()
\r
2905 ArrayList<int> list2 = new ArrayList<int>();
\r
2906 for (int i = 0; i < 5; i++) { list2.Add(100 + i); }
\r
2907 Assert.IsTrue(list.Check(), "list check before AddAll");
\r
2908 list.View(1, 2).AddAll(list2);
\r
2909 Assert.IsTrue(list.Check(), "list check after AddAll");
\r
2910 for (int i = 0; i < 7; i++)
\r
2911 for (int j = 0; j < 7 - i; j++)
\r
2913 Assert.AreEqual(i < 3 || (i == 3 && j == 0) ? i : i + 5, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
\r
2914 Assert.AreEqual(i < 3 && i + j > 3 ? j + 5 : j, views[i][j].Count, "view[" + i + "][" + j + "] count");
\r
2919 public void RemoveAll1()
\r
2921 ArrayList<int> list2 = new ArrayList<int>();
\r
2922 list2.Add(1); list2.Add(3); list2.Add(4);
\r
2924 for (int i = 0; i < 7; i++)
\r
2926 for (int j = 0; j < 7 - i; j++)
\r
2928 list = new ArrayList<int>();
\r
2929 for (int k = 0; k < 6; k++) list.Add(k);
\r
2930 ArrayList<int> v = (ArrayList<int>)list.View(i, j);
\r
2931 list.RemoveAll(list2);
\r
2932 Assert.IsTrue(list.Check(), "list check after RemoveAll, i=" + i + ", j=" + j);
\r
2937 public void RemoveAll2()
\r
2939 ArrayList<int> list2 = new ArrayList<int>();
\r
2940 list2.Add(1); list2.Add(3); list2.Add(4);
\r
2941 Assert.IsTrue(list.Check(), "list check before RemoveAll");
\r
2942 list.RemoveAll(list2);
\r
2944 Assert.AreEqual(0, views[0][0].Offset, "view [0][0] offset");
\r
2945 Assert.AreEqual(0, views[0][1].Offset, "view [0][1] offset");
\r
2946 Assert.AreEqual(0, views[0][2].Offset, "view [0][2] offset");
\r
2947 Assert.AreEqual(0, views[0][3].Offset, "view [0][3] offset");
\r
2948 Assert.AreEqual(0, views[0][4].Offset, "view [0][4] offset");
\r
2949 Assert.AreEqual(0, views[0][5].Offset, "view [0][5] offset");
\r
2950 Assert.AreEqual(0, views[0][6].Offset, "view [0][6] offset");
\r
2951 Assert.AreEqual(1, views[1][0].Offset, "view [1][0] offset");
\r
2952 Assert.AreEqual(1, views[1][1].Offset, "view [1][1] offset");
\r
2953 Assert.AreEqual(1, views[1][2].Offset, "view [1][2] offset");
\r
2954 Assert.AreEqual(1, views[1][3].Offset, "view [1][3] offset");
\r
2955 Assert.AreEqual(1, views[1][4].Offset, "view [1][4] offset");
\r
2956 Assert.AreEqual(1, views[1][5].Offset, "view [1][5] offset");
\r
2957 Assert.AreEqual(1, views[2][0].Offset, "view [2][0] offset");
\r
2958 Assert.AreEqual(1, views[2][1].Offset, "view [2][1] offset");
\r
2959 Assert.AreEqual(1, views[2][2].Offset, "view [2][2] offset");
\r
2960 Assert.AreEqual(1, views[2][3].Offset, "view [2][3] offset");
\r
2961 Assert.AreEqual(1, views[2][4].Offset, "view [2][4] offset");
\r
2962 Assert.AreEqual(2, views[3][0].Offset, "view [3][0] offset");
\r
2963 Assert.AreEqual(2, views[3][1].Offset, "view [3][1] offset");
\r
2964 Assert.AreEqual(2, views[3][2].Offset, "view [3][2] offset");
\r
2965 Assert.AreEqual(2, views[3][3].Offset, "view [3][3] offset");
\r
2966 Assert.AreEqual(2, views[4][0].Offset, "view [4][0] offset");
\r
2967 Assert.AreEqual(2, views[4][1].Offset, "view [4][1] offset");
\r
2968 Assert.AreEqual(2, views[4][2].Offset, "view [4][2] offset");
\r
2969 Assert.AreEqual(2, views[5][0].Offset, "view [5][0] offset");
\r
2970 Assert.AreEqual(2, views[5][1].Offset, "view [5][1] offset");
\r
2971 Assert.AreEqual(3, views[6][0].Offset, "view [6][0] offset");
\r
2973 Assert.AreEqual(0, views[0][0].Count, "view [0][0] count");
\r
2974 Assert.AreEqual(1, views[0][1].Count, "view [0][1] count");
\r
2975 Assert.AreEqual(1, views[0][2].Count, "view [0][2] count");
\r
2976 Assert.AreEqual(2, views[0][3].Count, "view [0][3] count");
\r
2977 Assert.AreEqual(2, views[0][4].Count, "view [0][4] count");
\r
2978 Assert.AreEqual(2, views[0][5].Count, "view [0][5] count");
\r
2979 Assert.AreEqual(3, views[0][6].Count, "view [0][6] count");
\r
2980 Assert.AreEqual(0, views[1][0].Count, "view [1][0] count");
\r
2981 Assert.AreEqual(0, views[1][1].Count, "view [1][1] count");
\r
2982 Assert.AreEqual(1, views[1][2].Count, "view [1][2] count");
\r
2983 Assert.AreEqual(1, views[1][3].Count, "view [1][3] count");
\r
2984 Assert.AreEqual(1, views[1][4].Count, "view [1][4] count");
\r
2985 Assert.AreEqual(2, views[1][5].Count, "view [1][5] count");
\r
2986 Assert.AreEqual(0, views[2][0].Count, "view [2][0] count");
\r
2987 Assert.AreEqual(1, views[2][1].Count, "view [2][1] count");
\r
2988 Assert.AreEqual(1, views[2][2].Count, "view [2][2] count");
\r
2989 Assert.AreEqual(1, views[2][3].Count, "view [2][3] count");
\r
2990 Assert.AreEqual(2, views[2][4].Count, "view [2][4] count");
\r
2991 Assert.AreEqual(0, views[3][0].Count, "view [3][0] count");
\r
2992 Assert.AreEqual(0, views[3][1].Count, "view [3][1] count");
\r
2993 Assert.AreEqual(0, views[3][2].Count, "view [3][2] count");
\r
2994 Assert.AreEqual(1, views[3][3].Count, "view [3][3] count");
\r
2995 Assert.AreEqual(0, views[4][0].Count, "view [4][0] count");
\r
2996 Assert.AreEqual(0, views[4][1].Count, "view [4][1] count");
\r
2997 Assert.AreEqual(1, views[4][2].Count, "view [4][2] count");
\r
2998 Assert.AreEqual(0, views[5][0].Count, "view [5][0] count");
\r
2999 Assert.AreEqual(1, views[5][1].Count, "view [5][1] count");
\r
3000 Assert.AreEqual(0, views[6][0].Count, "view [6][0] count");
\r
3002 Assert.IsTrue(list.Check(), "list check after RemoveAll");
\r
3006 public void RetainAll()
\r
3008 ArrayList<int> list2 = new ArrayList<int>();
\r
3009 list2.Add(2); list2.Add(4); list2.Add(5);
\r
3010 Assert.IsTrue(list.Check(), "list check before RetainAll");
\r
3011 list.RetainAll(list2);
\r
3013 Assert.AreEqual(0, views[0][0].Offset, "view [0][0] offset");
\r
3014 Assert.AreEqual(0, views[0][1].Offset, "view [0][1] offset");
\r
3015 Assert.AreEqual(0, views[0][2].Offset, "view [0][2] offset");
\r
3016 Assert.AreEqual(0, views[0][3].Offset, "view [0][3] offset");
\r
3017 Assert.AreEqual(0, views[0][4].Offset, "view [0][4] offset");
\r
3018 Assert.AreEqual(0, views[0][5].Offset, "view [0][5] offset");
\r
3019 Assert.AreEqual(0, views[0][6].Offset, "view [0][6] offset");
\r
3020 Assert.AreEqual(0, views[1][0].Offset, "view [1][0] offset");
\r
3021 Assert.AreEqual(0, views[1][1].Offset, "view [1][1] offset");
\r
3022 Assert.AreEqual(0, views[1][2].Offset, "view [1][2] offset");
\r
3023 Assert.AreEqual(0, views[1][3].Offset, "view [1][3] offset");
\r
3024 Assert.AreEqual(0, views[1][4].Offset, "view [1][4] offset");
\r
3025 Assert.AreEqual(0, views[1][5].Offset, "view [1][5] offset");
\r
3026 Assert.AreEqual(0, views[2][0].Offset, "view [2][0] offset");
\r
3027 Assert.AreEqual(0, views[2][1].Offset, "view [2][1] offset");
\r
3028 Assert.AreEqual(0, views[2][2].Offset, "view [2][2] offset");
\r
3029 Assert.AreEqual(0, views[2][3].Offset, "view [2][3] offset");
\r
3030 Assert.AreEqual(0, views[2][4].Offset, "view [2][4] offset");
\r
3031 Assert.AreEqual(1, views[3][0].Offset, "view [3][0] offset");
\r
3032 Assert.AreEqual(1, views[3][1].Offset, "view [3][1] offset");
\r
3033 Assert.AreEqual(1, views[3][2].Offset, "view [3][2] offset");
\r
3034 Assert.AreEqual(1, views[3][3].Offset, "view [3][3] offset");
\r
3035 Assert.AreEqual(1, views[4][0].Offset, "view [4][0] offset");
\r
3036 Assert.AreEqual(1, views[4][1].Offset, "view [4][1] offset");
\r
3037 Assert.AreEqual(1, views[4][2].Offset, "view [4][2] offset");
\r
3038 Assert.AreEqual(2, views[5][0].Offset, "view [5][0] offset");
\r
3039 Assert.AreEqual(2, views[5][1].Offset, "view [5][1] offset");
\r
3040 Assert.AreEqual(3, views[6][0].Offset, "view [6][0] offset");
\r
3042 Assert.AreEqual(0, views[0][0].Count, "view [0][0] count");
\r
3043 Assert.AreEqual(0, views[0][1].Count, "view [0][1] count");
\r
3044 Assert.AreEqual(0, views[0][2].Count, "view [0][2] count");
\r
3045 Assert.AreEqual(1, views[0][3].Count, "view [0][3] count");
\r
3046 Assert.AreEqual(1, views[0][4].Count, "view [0][4] count");
\r
3047 Assert.AreEqual(2, views[0][5].Count, "view [0][5] count");
\r
3048 Assert.AreEqual(3, views[0][6].Count, "view [0][6] count");
\r
3049 Assert.AreEqual(0, views[1][0].Count, "view [1][0] count");
\r
3050 Assert.AreEqual(0, views[1][1].Count, "view [1][1] count");
\r
3051 Assert.AreEqual(1, views[1][2].Count, "view [1][2] count");
\r
3052 Assert.AreEqual(1, views[1][3].Count, "view [1][3] count");
\r
3053 Assert.AreEqual(2, views[1][4].Count, "view [1][4] count");
\r
3054 Assert.AreEqual(3, views[1][5].Count, "view [1][5] count");
\r
3055 Assert.AreEqual(0, views[2][0].Count, "view [2][0] count");
\r
3056 Assert.AreEqual(1, views[2][1].Count, "view [2][1] count");
\r
3057 Assert.AreEqual(1, views[2][2].Count, "view [2][2] count");
\r
3058 Assert.AreEqual(2, views[2][3].Count, "view [2][3] count");
\r
3059 Assert.AreEqual(3, views[2][4].Count, "view [2][4] count");
\r
3060 Assert.AreEqual(0, views[3][0].Count, "view [3][0] count");
\r
3061 Assert.AreEqual(0, views[3][1].Count, "view [3][1] count");
\r
3062 Assert.AreEqual(1, views[3][2].Count, "view [3][2] count");
\r
3063 Assert.AreEqual(2, views[3][3].Count, "view [3][3] count");
\r
3064 Assert.AreEqual(0, views[4][0].Count, "view [4][0] count");
\r
3065 Assert.AreEqual(1, views[4][1].Count, "view [4][1] count");
\r
3066 Assert.AreEqual(2, views[4][2].Count, "view [4][2] count");
\r
3067 Assert.AreEqual(0, views[5][0].Count, "view [5][0] count");
\r
3068 Assert.AreEqual(1, views[5][1].Count, "view [5][1] count");
\r
3069 Assert.AreEqual(0, views[6][0].Count, "view [6][0] count");
\r
3071 Assert.IsTrue(list.Check(), "list check after RetainAll");
\r
3075 public void RemoveAllCopies()
\r
3077 ArrayList<int> list2 = new ArrayList<int>();
\r
3078 list2.Add(0); list2.Add(2); list2.Add(2); list2.Add(2); list2.Add(5); list2.Add(2); list2.Add(1);
\r
3079 for (int i = 0; i < 7; i++)
\r
3081 for (int j = 0; j < 7 - i; j++)
\r
3083 list = new ArrayList<int>();
\r
3084 list.AddAll(list2);
\r
3085 ArrayList<int> v = (ArrayList<int>)list.View(i, j);
\r
3086 list.RemoveAllCopies(2);
\r
3087 Assert.AreEqual((i == 0 && j > 0 ? 1 : 0) + (i <= 4 && i + j > 4 ? 1 : 0) + (i <= 6 && i + j > 6 ? 1 : 0), v.Count, "v.Count, i=" + i + ", j=" + j);
\r
3088 Assert.AreEqual(i == 0 ? 0 : i <= 4 ? 1 : i <= 6 ? 2 : 3, v.Offset, "v.Offset, i=" + i + ", j=" + j);
\r
3089 Assert.IsTrue(list.Check(), "list check after RemoveAllCopies, i=" + i + ", j=" + j);
\r
3094 private void checkDisposed(bool reverse, int start, int count)
\r
3097 for (int i = 0; i < 7; i++)
\r
3098 for (int j = 0; j < 7 - i; j++)
\r
3100 if (i + j <= start || i >= start + count || (i <= start && i + j >= start + count) || (reverse && start <= i && start + count >= i + j))
\r
3104 k = views[i][j].Count;
\r
3106 catch (ViewDisposedException)
\r
3108 Assert.Fail("view[" + i + "][" + j + "] threw");
\r
3110 Assert.AreEqual(j, views[i][j].Count, "view[" + i + "][" + j + "] size");
\r
3111 if (reverse && ((j > 0 && start <= i && start + count >= i + j) || (j == 0 && start < i && start + count > i)))
\r
3112 Assert.AreEqual(start + (start + count - i - j), views[i][j].Offset, "view[" + i + "][" + j + "] offset (mirrored)");
\r
3114 Assert.AreEqual(i, views[i][j].Offset, "view[" + i + "][" + j + "] offset");
\r
3120 k = views[i][j].Count;
\r
3121 Assert.Fail("view[" + i + "][" + j + "] no throw");
\r
3123 catch (ViewDisposedException) { }
\r
3129 public void Reverse()
\r
3131 int start = 2, count = 3;
\r
3132 IList<int> list2 = list.View(start, count);
\r
3133 Assert.IsTrue(list.Check(), "list check before Reverse");
\r
3135 Assert.IsTrue(list.Check(), "list check after Reverse");
\r
3136 checkDisposed(true, start, count);
\r
3139 public void Sort()
\r
3141 int start = 2, count = 3;
\r
3142 IList<int> list2 = list.View(start, count);
\r
3143 Assert.IsTrue(list.Check(), "list check before Sort");
\r
3145 Assert.IsTrue(list.Check(), "list check after Sort");
\r
3146 checkDisposed(false, start, count);
\r
3149 public void Shuffle()
\r
3151 int start = 2, count = 3;
\r
3152 IList<int> list2 = list.View(start, count);
\r
3153 Assert.IsTrue(list.Check(), "list check before Shuffle");
\r
3155 Assert.IsTrue(list.Check(), "list check after Shuffle");
\r
3156 checkDisposed(false, start, count);
\r
3166 namespace ArrayListOfTreesORLists
\r
3169 public class MultiLevelUnorderedOfUnOrdered
\r
3171 private ICollection<int> dit, dat, dut;
\r
3173 private ICollection<ICollection<int>> Dit, Dat, Dut;
\r
3177 public void Init()
\r
3179 dit = new ArrayList<int>();
\r
3180 dat = new TreeSet<int>(Comparer<int>.Default, EqualityComparer<int>.Default);
\r
3181 dut = new ArrayList<int>();
\r
3182 dit.Add(2); dit.Add(1);
\r
3183 dat.Add(1); dat.Add(2);
\r
3185 Dit = new ArrayList<ICollection<int>>();
\r
3186 Dat = new ArrayList<ICollection<int>>();
\r
3187 Dut = new ArrayList<ICollection<int>>();
\r
3192 public void Check()
\r
3194 Assert.IsTrue(dit.UnsequencedEquals(dat));
\r
3195 Assert.IsFalse(dit.UnsequencedEquals(dut));
\r
3200 public void Multi()
\r
3202 Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
\r
3203 Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
\r
3204 Assert.IsTrue(Dit.UnsequencedEquals(Dat));
\r
3205 Assert.IsFalse(Dit.UnsequencedEquals(Dut));
\r
3210 public void Dispose()
\r
3212 dit = dat = dut = null;
\r
3213 Dit = Dat = Dut = null;
\r
3220 public class MultiLevelOrderedOfUnOrdered
\r
3222 private ICollection<int> dit, dat, dut;
\r
3224 private ISequenced<ICollection<int>> Dit, Dat, Dut;
\r
3228 public void Init()
\r
3230 dit = new ArrayList<int>();
\r
3231 dat = new TreeSet<int>(Comparer<int>.Default, EqualityComparer<int>.Default);
\r
3232 dut = new ArrayList<int>();
\r
3233 dit.Add(2); dit.Add(1);
\r
3234 dat.Add(1); dat.Add(2);
\r
3236 Dit = new ArrayList<ICollection<int>>();
\r
3237 Dat = new ArrayList<ICollection<int>>();
\r
3238 Dut = new ArrayList<ICollection<int>>();
\r
3243 public void Check()
\r
3245 Assert.IsTrue(dit.UnsequencedEquals(dat));
\r
3246 Assert.IsFalse(dit.UnsequencedEquals(dut));
\r
3251 public void Multi()
\r
3253 Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
\r
3254 Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
\r
3255 Dut.Add(dit); Dut.Add(dut); Dut.Add(dat);
\r
3256 Assert.IsFalse(Dit.SequencedEquals(Dat));
\r
3257 Assert.IsTrue(Dit.SequencedEquals(Dut));
\r
3262 public void Dispose()
\r
3264 dit = dat = dut = null;
\r
3265 Dit = Dat = Dut = null;
\r
3272 public class MultiLevelUnOrderedOfOrdered
\r
3274 private ISequenced<int> dit, dat, dut, dot;
\r
3276 private ICollection<ISequenced<int>> Dit, Dat, Dut, Dot;
\r
3280 public void Init()
\r
3282 dit = new TreeSet<int>(Comparer<int>.Default, EqualityComparer<int>.Default);
\r
3283 dat = new ArrayList<int>();
\r
3284 dut = new ArrayList<int>();
\r
3285 dot = new ArrayList<int>();
\r
3286 dit.Add(2); dit.Add(1);
\r
3287 dat.Add(2); dat.Add(1);
\r
3289 dot.Add(1); dot.Add(2);
\r
3290 Dit = new ArrayList<ISequenced<int>>();
\r
3291 Dat = new ArrayList<ISequenced<int>>();
\r
3292 Dut = new ArrayList<ISequenced<int>>();
\r
3293 Dot = new ArrayList<ISequenced<int>>();
\r
3298 public void Check()
\r
3300 Assert.IsFalse(dit.SequencedEquals(dat));
\r
3301 Assert.IsTrue(dit.SequencedEquals(dot));
\r
3302 Assert.IsFalse(dit.SequencedEquals(dut));
\r
3307 public void Multi()
\r
3309 Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
\r
3310 Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
\r
3311 Dut.Add(dot); Dut.Add(dut); Dut.Add(dit);
\r
3312 Dot.Add(dit); Dot.Add(dit); Dot.Add(dut);
\r
3313 Assert.IsTrue(Dit.UnsequencedEquals(Dut));
\r
3314 Assert.IsFalse(Dit.UnsequencedEquals(Dat));
\r
3315 Assert.IsTrue(Dit.UnsequencedEquals(Dot));
\r
3320 public void Dispose()
\r
3322 dit = dat = dut = dot = null;
\r
3323 Dit = Dat = Dut = Dot = null;
\r
3330 public class MultiLevelOrderedOfOrdered
\r
3332 private ISequenced<int> dit, dat, dut, dot;
\r
3334 private ISequenced<ISequenced<int>> Dit, Dat, Dut, Dot;
\r
3338 public void Init()
\r
3340 dit = new TreeSet<int>(Comparer<int>.Default, EqualityComparer<int>.Default);
\r
3341 dat = new ArrayList<int>();
\r
3342 dut = new ArrayList<int>();
\r
3343 dot = new ArrayList<int>();
\r
3344 dit.Add(2); dit.Add(1);
\r
3345 dat.Add(2); dat.Add(1);
\r
3347 dot.Add(1); dot.Add(2);
\r
3348 Dit = new ArrayList<ISequenced<int>>();
\r
3349 Dat = new ArrayList<ISequenced<int>>();
\r
3350 Dut = new ArrayList<ISequenced<int>>();
\r
3351 Dot = new ArrayList<ISequenced<int>>();
\r
3356 public void Check()
\r
3358 Assert.IsFalse(dit.SequencedEquals(dat));
\r
3359 Assert.IsTrue(dit.SequencedEquals(dot));
\r
3360 Assert.IsFalse(dit.SequencedEquals(dut));
\r
3365 public void Multi()
\r
3367 Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
\r
3368 Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
\r
3369 Dut.Add(dot); Dut.Add(dut); Dut.Add(dit);
\r
3370 Dot.Add(dit); Dot.Add(dit); Dot.Add(dut);
\r
3371 Assert.IsTrue(Dit.SequencedEquals(Dut));
\r
3372 Assert.IsFalse(Dit.SequencedEquals(Dat));
\r
3373 Assert.IsFalse(Dit.SequencedEquals(Dot));
\r
3378 public void Dispose()
\r
3380 dit = dat = dut = dot = null;
\r
3381 Dit = Dat = Dut = Dot = null;
\r
3389 namespace HashingAndEquals
\r
3392 public class ISequenced
\r
3394 private ISequenced<int> dit, dat, dut;
\r
3398 public void Init()
\r
3400 dit = new ArrayList<int>();
\r
3401 dat = new ArrayList<int>();
\r
3402 dut = new ArrayList<int>();
\r
3407 public void EmptyEmpty()
\r
3409 Assert.IsTrue(dit.SequencedEquals(dat));
\r
3414 public void EmptyNonEmpty()
\r
3417 Assert.IsFalse(dit.SequencedEquals(dat));
\r
3418 Assert.IsFalse(dat.SequencedEquals(dit));
\r
3422 public void HashVal()
\r
3424 Assert.AreEqual(CHC.sequencedhashcode(), dit.GetSequencedHashCode());
\r
3426 Assert.AreEqual(CHC.sequencedhashcode(3), dit.GetSequencedHashCode());
\r
3428 Assert.AreEqual(CHC.sequencedhashcode(3, 7), dit.GetSequencedHashCode());
\r
3429 Assert.AreEqual(CHC.sequencedhashcode(), dut.GetSequencedHashCode());
\r
3431 Assert.AreEqual(CHC.sequencedhashcode(7), dut.GetSequencedHashCode());
\r
3433 Assert.AreEqual(CHC.sequencedhashcode(7, 3), dut.GetSequencedHashCode());
\r
3438 public void EqualHashButDifferent()
\r
3440 dit.Add(0); dit.Add(31);
\r
3441 dat.Add(1); dat.Add(0);
\r
3442 Assert.AreEqual(dit.GetSequencedHashCode(), dat.GetSequencedHashCode());
\r
3443 Assert.IsFalse(dit.SequencedEquals(dat));
\r
3448 public void Normal()
\r
3453 Assert.IsFalse(dit.SequencedEquals(dat));
\r
3454 Assert.IsFalse(dat.SequencedEquals(dit));
\r
3456 Assert.IsTrue(dit.SequencedEquals(dat));
\r
3457 Assert.IsTrue(dat.SequencedEquals(dit));
\r
3462 public void WrongOrder()
\r
3466 Assert.IsTrue(dit.SequencedEquals(dut));
\r
3467 Assert.IsTrue(dut.SequencedEquals(dit));
\r
3469 ((ArrayList<int>)dut).InsertFirst(7);
\r
3470 Assert.IsFalse(dit.SequencedEquals(dut));
\r
3471 Assert.IsFalse(dut.SequencedEquals(dit));
\r
3476 public void Reflexive()
\r
3478 Assert.IsTrue(dit.SequencedEquals(dit));
\r
3480 Assert.IsTrue(dit.SequencedEquals(dit));
\r
3482 Assert.IsTrue(dit.SequencedEquals(dit));
\r
3487 public void Dispose()
\r
3498 public class IEditableCollection
\r
3500 private ICollection<int> dit, dat, dut;
\r
3504 public void Init()
\r
3506 dit = new ArrayList<int>();
\r
3507 dat = new ArrayList<int>();
\r
3508 dut = new ArrayList<int>();
\r
3513 public void EmptyEmpty()
\r
3515 Assert.IsTrue(dit.UnsequencedEquals(dat));
\r
3520 public void EmptyNonEmpty()
\r
3523 Assert.IsFalse(dit.UnsequencedEquals(dat));
\r
3524 Assert.IsFalse(dat.UnsequencedEquals(dit));
\r
3529 public void HashVal()
\r
3531 Assert.AreEqual(CHC.unsequencedhashcode(), dit.GetUnsequencedHashCode());
\r
3533 Assert.AreEqual(CHC.unsequencedhashcode(3), dit.GetUnsequencedHashCode());
\r
3535 Assert.AreEqual(CHC.unsequencedhashcode(3, 7), dit.GetUnsequencedHashCode());
\r
3536 Assert.AreEqual(CHC.unsequencedhashcode(), dut.GetUnsequencedHashCode());
\r
3538 Assert.AreEqual(CHC.unsequencedhashcode(3), dut.GetUnsequencedHashCode());
\r
3540 Assert.AreEqual(CHC.unsequencedhashcode(7, 3), dut.GetUnsequencedHashCode());
\r
3545 public void EqualHashButDifferent()
\r
3547 dit.Add(-1657792980); dit.Add(-1570288808);
\r
3548 dat.Add(1862883298); dat.Add(-272461342);
\r
3549 Assert.AreEqual(dit.GetUnsequencedHashCode(), dat.GetUnsequencedHashCode());
\r
3550 Assert.IsFalse(dit.UnsequencedEquals(dat));
\r
3555 public void Normal()
\r
3560 Assert.IsFalse(dit.UnsequencedEquals(dat));
\r
3561 Assert.IsFalse(dat.UnsequencedEquals(dit));
\r
3563 Assert.IsTrue(dit.UnsequencedEquals(dat));
\r
3564 Assert.IsTrue(dat.UnsequencedEquals(dit));
\r
3569 public void WrongOrder()
\r
3573 Assert.IsTrue(dit.UnsequencedEquals(dut));
\r
3574 Assert.IsTrue(dut.UnsequencedEquals(dit));
\r
3577 Assert.IsTrue(dit.UnsequencedEquals(dut));
\r
3578 Assert.IsTrue(dut.UnsequencedEquals(dit));
\r
3583 public void Reflexive()
\r
3585 Assert.IsTrue(dit.UnsequencedEquals(dit));
\r
3587 Assert.IsTrue(dit.UnsequencedEquals(dit));
\r
3589 Assert.IsTrue(dit.UnsequencedEquals(dit));
\r
3594 public void Dispose()
\r
3605 public class MultiLevelUnorderedOfUnOrdered
\r
3607 private ICollection<int> dit, dat, dut;
\r
3609 private ICollection<ICollection<int>> Dit, Dat, Dut;
\r
3613 public void Init()
\r
3615 dit = new ArrayList<int>();
\r
3616 dat = new ArrayList<int>();
\r
3617 dut = new ArrayList<int>();
\r
3618 dit.Add(2); dit.Add(1);
\r
3619 dat.Add(1); dat.Add(2);
\r
3621 Dit = new ArrayList<ICollection<int>>();
\r
3622 Dat = new ArrayList<ICollection<int>>();
\r
3623 Dut = new ArrayList<ICollection<int>>();
\r
3628 public void Check()
\r
3630 Assert.IsTrue(dit.UnsequencedEquals(dat));
\r
3631 Assert.IsFalse(dit.UnsequencedEquals(dut));
\r
3636 public void Multi()
\r
3638 Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
\r
3639 Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
\r
3640 Assert.IsTrue(Dit.UnsequencedEquals(Dat));
\r
3641 Assert.IsFalse(Dit.UnsequencedEquals(Dut));
\r
3646 public void Dispose()
\r
3648 dit = dat = dut = null;
\r
3649 Dit = Dat = Dut = null;
\r
3656 public class MultiLevelOrderedOfUnOrdered
\r
3658 private ICollection<int> dit, dat, dut;
\r
3660 private ISequenced<ICollection<int>> Dit, Dat, Dut;
\r
3664 public void Init()
\r
3666 dit = new ArrayList<int>();
\r
3667 dat = new ArrayList<int>();
\r
3668 dut = new ArrayList<int>();
\r
3669 dit.Add(2); dit.Add(1);
\r
3670 dat.Add(1); dat.Add(2);
\r
3672 Dit = new ArrayList<ICollection<int>>();
\r
3673 Dat = new ArrayList<ICollection<int>>();
\r
3674 Dut = new ArrayList<ICollection<int>>();
\r
3679 public void Check()
\r
3681 Assert.IsTrue(dit.UnsequencedEquals(dat));
\r
3682 Assert.IsFalse(dit.UnsequencedEquals(dut));
\r
3687 public void Multi()
\r
3689 Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
\r
3690 Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
\r
3691 Dut.Add(dit); Dut.Add(dut); Dut.Add(dat);
\r
3692 Assert.IsFalse(Dit.SequencedEquals(Dat));
\r
3693 Assert.IsTrue(Dit.SequencedEquals(Dut));
\r
3698 public void Dispose()
\r
3700 dit = dat = dut = null;
\r
3701 Dit = Dat = Dut = null;
\r
3708 public class MultiLevelUnOrderedOfOrdered
\r
3710 private ISequenced<int> dit, dat, dut, dot;
\r
3712 private ICollection<ISequenced<int>> Dit, Dat, Dut, Dot;
\r
3716 public void Init()
\r
3718 dit = new ArrayList<int>();
\r
3719 dat = new ArrayList<int>();
\r
3720 dut = new ArrayList<int>();
\r
3721 dot = new ArrayList<int>();
\r
3722 dit.Add(2); dit.Add(1);
\r
3723 dat.Add(1); dat.Add(2);
\r
3725 dot.Add(2); dot.Add(1);
\r
3726 Dit = new ArrayList<ISequenced<int>>();
\r
3727 Dat = new ArrayList<ISequenced<int>>();
\r
3728 Dut = new ArrayList<ISequenced<int>>();
\r
3729 Dot = new ArrayList<ISequenced<int>>();
\r
3734 public void Check()
\r
3736 Assert.IsFalse(dit.SequencedEquals(dat));
\r
3737 Assert.IsTrue(dit.SequencedEquals(dot));
\r
3738 Assert.IsFalse(dit.SequencedEquals(dut));
\r
3743 public void Multi()
\r
3745 Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
\r
3746 Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
\r
3747 Dut.Add(dot); Dut.Add(dut); Dut.Add(dit);
\r
3748 Dot.Add(dit); Dot.Add(dit); Dot.Add(dut);
\r
3749 Assert.IsTrue(Dit.UnsequencedEquals(Dut));
\r
3750 Assert.IsFalse(Dit.UnsequencedEquals(Dat));
\r
3751 Assert.IsTrue(Dit.UnsequencedEquals(Dot));
\r
3756 public void Dispose()
\r
3758 dit = dat = dut = dot = null;
\r
3759 Dit = Dat = Dut = Dot = null;
\r
3766 public class MultiLevelOrderedOfOrdered
\r
3768 private ISequenced<int> dit, dat, dut, dot;
\r
3770 private ISequenced<ISequenced<int>> Dit, Dat, Dut, Dot;
\r
3774 public void Init()
\r
3776 dit = new ArrayList<int>();
\r
3777 dat = new ArrayList<int>();
\r
3778 dut = new ArrayList<int>();
\r
3779 dot = new ArrayList<int>();
\r
3780 dit.Add(2); dit.Add(1);
\r
3781 dat.Add(1); dat.Add(2);
\r
3783 dot.Add(2); dot.Add(1);
\r
3784 Dit = new ArrayList<ISequenced<int>>();
\r
3785 Dat = new ArrayList<ISequenced<int>>();
\r
3786 Dut = new ArrayList<ISequenced<int>>();
\r
3787 Dot = new ArrayList<ISequenced<int>>();
\r
3792 public void Check()
\r
3794 Assert.IsFalse(dit.SequencedEquals(dat));
\r
3795 Assert.IsTrue(dit.SequencedEquals(dot));
\r
3796 Assert.IsFalse(dit.SequencedEquals(dut));
\r
3801 public void Multi()
\r
3803 Dit.Add(dit); Dit.Add(dut); Dit.Add(dit);
\r
3804 Dat.Add(dut); Dat.Add(dit); Dat.Add(dat);
\r
3805 Dut.Add(dot); Dut.Add(dut); Dut.Add(dit);
\r
3806 Dot.Add(dit); Dot.Add(dit); Dot.Add(dut);
\r
3807 Assert.IsTrue(Dit.SequencedEquals(Dut));
\r
3808 Assert.IsFalse(Dit.SequencedEquals(Dat));
\r
3809 Assert.IsFalse(Dit.SequencedEquals(Dot));
\r
3814 public void Dispose()
\r
3816 dit = dat = dut = dot = null;
\r
3817 Dit = Dat = Dut = Dot = null;
\r