/mcs/class/Mono.C5/Test/arrays/ArrayListTest.cs
C# | 3840 lines | 3213 code | 596 blank | 31 comment | 128 complexity | 52f9b691a04199e37b226030aa67e1b4 MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
Large files files are truncated, but you can click here to view the full file
- /*
- Copyright (c) 2003-2006 Niels Kokholm and Peter Sestoft
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- */
- using System;
- using C5;
- using NUnit.Framework;
- using SCG = System.Collections.Generic;
- namespace C5UnitTests.arrays.list
- {
- using CollectionOfInt = ArrayList<int>;
- [TestFixture]
- public class GenericTesters
- {
- [Test]
- public void TestEvents()
- {
- Fun<CollectionOfInt> factory = delegate() { return new CollectionOfInt(TenEqualityComparer.Default); };
- new C5UnitTests.Templates.Events.ListTester<CollectionOfInt>().Test(factory);
- new C5UnitTests.Templates.Events.QueueTester<CollectionOfInt>().Test(factory);
- new C5UnitTests.Templates.Events.StackTester<CollectionOfInt>().Test(factory);
- }
- [Test]
- public void Extensible()
- {
- C5UnitTests.Templates.Extensible.Clone.Tester<CollectionOfInt>();
- C5UnitTests.Templates.Extensible.Clone.ViewTester<CollectionOfInt>();
- C5UnitTests.Templates.Extensible.Serialization.Tester<CollectionOfInt>();
- C5UnitTests.Templates.Extensible.Serialization.ViewTester<CollectionOfInt>();
- }
- [Test]
- public void List()
- {
- C5UnitTests.Templates.List.Dispose.Tester<CollectionOfInt>();
- C5UnitTests.Templates.List.SCG_IList.Tester<CollectionOfInt>();
- }
- }
- static class Factory
- {
- public static ICollection<T> New<T>() { return new ArrayList<T>(); }
- }
- namespace Events
- {
- [TestFixture]
- public class IList_
- {
- private ArrayList<int> list;
- CollectionEventList<int> seen;
- [SetUp]
- public void Init()
- {
- list = new ArrayList<int>(TenEqualityComparer.Default);
- seen = new CollectionEventList<int>(IntEqualityComparer.Default);
- }
- private void listen() { seen.Listen(list, EventTypeEnum.Added); }
- [Test]
- public void Listenable()
- {
- Assert.AreEqual(EventTypeEnum.All, list.ListenableEvents);
- Assert.AreEqual(EventTypeEnum.None, list.ActiveEvents);
- listen();
- Assert.AreEqual(EventTypeEnum.Added, list.ActiveEvents);
- }
- [Test]
- public void SetThis()
- {
- list.Add(4); list.Add(56); list.Add(8);
- listen();
- list[1] = 45;
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), list),
- new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(56,1), list),
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(45,1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
- });
- }
- [Test]
- public void Insert()
- {
- list.Add(4); list.Add(56); list.Add(8);
- listen();
- list.Insert(1, 45);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(45,1), list),
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
- });
- }
- [Test]
- public void InsertAll()
- {
- list.Add(4); list.Add(56); list.Add(8);
- listen();
- list.InsertAll<int>(1, new int[] { 666, 777, 888 });
- //seen.Print(Console.Error);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(666,1), list),
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(666, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(777,2), list),
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(777, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(888,3), list),
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(888, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
- });
- list.InsertAll<int>(1, new int[] {});
- seen.Check(new CollectionEvent<int>[] {});
- }
- [Test]
- public void InsertFirstLast()
- {
- list.Add(4); list.Add(56); list.Add(8);
- listen();
- list.InsertFirst(45);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(45,0), list),
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
- });
- list.InsertLast(88);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(88,4), list),
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(88, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
- });
- }
- [Test]
- public void Remove()
- {
- list.Add(4); list.Add(56); list.Add(8);
- listen();
- list.Remove();
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(8, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
- }
- [Test]
- public void RemoveFirst()
- {
- list.Add(4); list.Add(56); list.Add(8);
- listen();
- list.RemoveFirst();
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(4,0), list),
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(4, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
- }
- [Test]
- public void RemoveLast()
- {
- list.Add(4); list.Add(56); list.Add(8);
- listen();
- list.RemoveLast();
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(8,2), list),
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(8, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
- }
- [Test]
- public void Reverse()
- {
- list.Add(4); list.Add(56); list.Add(8);
- listen();
- list.Reverse();
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
- });
- list.View(1, 0).Reverse();
- seen.Check(new CollectionEvent<int>[] {});
- }
- [Test]
- public void Sort()
- {
- list.Add(4); list.Add(56); list.Add(8);
- listen();
- list.Sort();
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
- });
- list.View(1, 0).Sort();
- seen.Check(new CollectionEvent<int>[] {});
- }
- [Test]
- public void Shuffle()
- {
- list.Add(4); list.Add(56); list.Add(8);
- listen();
- list.Shuffle();
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
- });
- list.View(1, 0).Shuffle();
- seen.Check(new CollectionEvent<int>[] {});
- }
- [Test]
- public void RemoveAt()
- {
- list.Add(4); list.Add(56); list.Add(8);
- listen();
- list.RemoveAt(1);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(56,1), list),
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
- }
- [Test]
- public void RemoveInterval()
- {
- list.Add(4); list.Add(56); list.Add(8);
- listen();
- list.RemoveInterval(1, 2);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(false,2,1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
- });
- list.RemoveInterval(1, 0);
- seen.Check(new CollectionEvent<int>[] {});
- }
- [Test]
- public void Update()
- {
- list.Add(4); list.Add(56); list.Add(8);
- listen();
- list.Update(53);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(53, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
- });
- list.Update(67);
- seen.Check(new CollectionEvent<int>[] {});
- }
- [Test]
- public void FindOrAdd()
- {
- list.Add(4); list.Add(56); list.Add(8);
- listen();
- int val = 53;
- list.FindOrAdd(ref val);
- seen.Check(new CollectionEvent<int>[] {});
- val = 67;
- list.FindOrAdd(ref val);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
- });
- }
- [Test]
- public void UpdateOrAdd()
- {
- list.Add(4); list.Add(56); list.Add(8);
- listen();
- int val = 53;
- list.UpdateOrAdd(val);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(53, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
- });
- val = 67;
- list.UpdateOrAdd(val);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
- });
- list.UpdateOrAdd(51, out val);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(53, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(51, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
- });
- val = 67;
- list.UpdateOrAdd(81, out val);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(81, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
- });
- }
- [Test]
- public void RemoveItem()
- {
- list.Add(4); list.Add(56); list.Add(18);
- listen();
- list.Remove(53);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(56, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
- list.Remove(11);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(18, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
- }
- [Test]
- public void RemoveAll()
- {
- for (int i = 0; i < 10; i++)
- {
- list.Add(10 * i + 5);
- }
- listen();
- list.RemoveAll<int>(new int[] { 32, 187, 45 });
- //TODO: the order depends on internals of the HashSet
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(35, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(45, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
- list.RemoveAll<int>(new int[] { 200, 300 });
- seen.Check(new CollectionEvent<int>[] {});
- }
- [Test]
- public void Clear()
- {
- list.Add(4); list.Add(56); list.Add(8);
- listen();
- list.View(1, 1).Clear();
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(false,1,1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
- });
- list.Clear();
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(true,2,0), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
- });
- list.Clear();
- seen.Check(new CollectionEvent<int>[] {});
- }
- [Test]
- public void ListDispose()
- {
- list.Add(4); list.Add(56); list.Add(8);
- listen();
- list.View(1, 1).Dispose();
- seen.Check(new CollectionEvent<int>[] {});
- list.Dispose();
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Cleared, new ClearedRangeEventArgs(true,3,0), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)
- });
- list.Dispose();
- seen.Check(new CollectionEvent<int>[] {});
- }
- [Test]
- public void RetainAll()
- {
- for (int i = 0; i < 10; i++)
- {
- list.Add(10 * i + 5);
- }
- listen();
- list.RetainAll<int>(new int[] { 32, 187, 45, 62, 82, 95, 2 });
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(15, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(25, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(55, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(75, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
- list.RetainAll<int>(new int[] { 32, 187, 45, 62, 82, 95, 2 });
- seen.Check(new CollectionEvent<int>[] {});
- }
- [Test]
- public void RemoveAllCopies()
- {
- for (int i = 0; i < 10; i++)
- {
- list.Add(3 * i + 5);
- }
- listen();
- list.RemoveAllCopies(14);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(11, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(14, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(17, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
- list.RemoveAllCopies(14);
- seen.Check(new CollectionEvent<int>[] {});
- }
- [Test]
- public void Add()
- {
- listen();
- seen.Check(new CollectionEvent<int>[0]);
- list.Add(23);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(23, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
- }
- [Test]
- public void AddAll()
- {
- for (int i = 0; i < 10; i++)
- {
- list.Add(10 * i + 5);
- }
- listen();
- list.AddAll<int>(new int[] { 45, 56, 67 });
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(45, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(56, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
- list.AddAll<int>(new int[] { });
- seen.Check(new CollectionEvent<int>[] {});
- }
- [TearDown]
- public void Dispose() { list = null; seen = null; }
- [Test]
- [ExpectedException(typeof(UnlistenableEventException))]
- public void ViewChanged()
- {
- IList<int> w = list.View(0, 0);
- w.CollectionChanged += new CollectionChangedHandler<int>(w_CollectionChanged);
- }
- [Test]
- [ExpectedException(typeof(UnlistenableEventException))]
- public void ViewCleared()
- {
- IList<int> w = list.View(0, 0);
- w.CollectionCleared += new CollectionClearedHandler<int>(w_CollectionCleared);
- }
- [Test]
- [ExpectedException(typeof(UnlistenableEventException))]
- public void ViewAdded()
- {
- IList<int> w = list.View(0, 0);
- w.ItemsAdded += new ItemsAddedHandler<int>(w_ItemAdded);
- }
- [Test]
- [ExpectedException(typeof(UnlistenableEventException))]
- public void ViewInserted()
- {
- IList<int> w = list.View(0, 0);
- w.ItemInserted += new ItemInsertedHandler<int>(w_ItemInserted);
- }
- [Test]
- [ExpectedException(typeof(UnlistenableEventException))]
- public void ViewRemoved()
- {
- IList<int> w = list.View(0, 0);
- w.ItemsRemoved += new ItemsRemovedHandler<int>(w_ItemRemoved);
- }
- [Test]
- [ExpectedException(typeof(UnlistenableEventException))]
- public void ViewRemovedAt()
- {
- IList<int> w = list.View(0, 0);
- w.ItemRemovedAt += new ItemRemovedAtHandler<int>(w_ItemRemovedAt);
- }
- void w_CollectionChanged(object sender)
- {
- throw new NotImplementedException();
- }
- void w_CollectionCleared(object sender, ClearedEventArgs eventArgs)
- {
- throw new NotImplementedException();
- }
- void w_ItemAdded(object sender, ItemCountEventArgs<int> eventArgs)
- {
- throw new NotImplementedException();
- }
- void w_ItemInserted(object sender, ItemAtEventArgs<int> eventArgs)
- {
- throw new NotImplementedException();
- }
- void w_ItemRemoved(object sender, ItemCountEventArgs<int> eventArgs)
- {
- throw new NotImplementedException();
- }
- void w_ItemRemovedAt(object sender, ItemAtEventArgs<int> eventArgs)
- {
- throw new NotImplementedException();
- }
- }
- [TestFixture]
- public class StackQueue
- {
- private ArrayList<int> list;
- CollectionEventList<int> seen;
- [SetUp]
- public void Init()
- {
- list = new ArrayList<int>(TenEqualityComparer.Default);
- seen = new CollectionEventList<int>(IntEqualityComparer.Default);
- }
- private void listen() { seen.Listen(list, EventTypeEnum.All); }
- [Test]
- public void EnqueueDequeue()
- {
- listen();
- list.Enqueue(67);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(67,0), list),
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(67, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
- list.Enqueue(2);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(2,1), list),
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(2, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
- list.Dequeue();
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(67,0), list),
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(67, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
- list.Dequeue();
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(2,0), list),
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(2, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
- }
- [Test]
- public void PushPop()
- {
- listen();
- seen.Check(new CollectionEvent<int>[0]);
- list.Push(23);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(23,0), list),
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(23, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
- list.Push(-12);
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.Inserted, new ItemAtEventArgs<int>(-12,1), list),
- new CollectionEvent<int>(EventTypeEnum.Added, new ItemCountEventArgs<int>(-12, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
- list.Pop();
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(-12,1), list),
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(-12, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
- list.Pop();
- seen.Check(new CollectionEvent<int>[] {
- new CollectionEvent<int>(EventTypeEnum.RemovedAt, new ItemAtEventArgs<int>(23,0), list),
- new CollectionEvent<int>(EventTypeEnum.Removed, new ItemCountEventArgs<int>(23, 1), list),
- new CollectionEvent<int>(EventTypeEnum.Changed, new EventArgs(), list)});
- }
- [TearDown]
- public void Dispose() { list = null; seen = null; }
- }
- }
- namespace Safety
- {
- /// <summary>
- /// Tests to see if the collection classes are robust for enumerable arguments that throw exceptions.
- /// </summary>
- [TestFixture]
- public class BadEnumerable
- {
- private ArrayList<int> list;
- [SetUp]
- public void Init()
- {
- list = new ArrayList<int>();
- }
- [Test]
- public void InsertAll()
- {
- list.Add(4); list.Add(56); list.Add(8);
- try
- {
- list.InsertAll<int>(1, new BadEnumerable<int>(new BadEnumerableException(), 9, 8, 7));
- Assert.Fail("Should not get here");
- }
- catch (BadEnumerableException) { }
- Assert.IsTrue(list.Check());
- Assert.IsTrue(IC.eq(list, 4, 9, 8, 7, 56, 8));
- }
- [Test]
- public void AddAll()
- {
- list.Add(4); list.Add(56); list.Add(8);
- try
- {
- list.View(0, 1).AddAll<int>(new BadEnumerable<int>(new BadEnumerableException(), 9, 8, 7));
- Assert.Fail("Should not get here");
- }
- catch (BadEnumerableException) { }
- Assert.IsTrue(list.Check());
- Assert.IsTrue(IC.eq(list, 4, 9, 8, 7, 56, 8));
- }
- [Test]
- public void RemoveAll()
- {
- list.Add(4); list.Add(56); list.Add(8);
- try
- {
- list.RemoveAll(new BadEnumerable<int>(new BadEnumerableException(), 9, 8, 7));
- Assert.Fail("Should not get here");
- }
- catch (BadEnumerableException) { }
- Assert.IsTrue(list.Check());
- Assert.IsTrue(IC.eq(list, 4, 56, 8));
- }
- [Test]
- public void RetainAll()
- {
- list.Add(4); list.Add(56); list.Add(8);
- try
- {
- list.RetainAll(new BadEnumerable<int>(new BadEnumerableException(), 9, 8, 7));
- Assert.Fail("Should not get here");
- }
- catch (BadEnumerableException) { }
- Assert.IsTrue(list.Check());
- Assert.IsTrue(IC.eq(list, 4, 56, 8));
- }
- [Test]
- public void ContainsAll()
- {
- list.Add(4); list.Add(56); list.Add(8);
- try
- {
- list.ContainsAll(new BadEnumerable<int>(new BadEnumerableException(), 4, 18));
- Assert.Fail("Should not get here");
- }
- catch (BadEnumerableException) { }
- Assert.IsTrue(list.Check());
- Assert.IsTrue(IC.eq(list, 4, 56, 8));
- }
- [TearDown]
- public void Dispose() { list = null; }
- }
- /// <summary>
- /// Tests to see if the collection classes are robust for delegate arguments that throw exceptions.
- /// </summary>
- [TestFixture]
- public class BadFun
- {
- private ArrayList<int> list;
- [SetUp]
- public void Init()
- {
- list = new ArrayList<int>();
- }
- [Test]
- public void NoTests() { }
- [TearDown]
- public void Dispose() { list = null; }
- }
- }
- namespace Enumerable
- {
- [TestFixture]
- public class Multiops
- {
- private ArrayList<int> list;
- private Fun<int, bool> always, never, even;
- [SetUp]
- public void Init()
- {
- list = new ArrayList<int>();
- always = delegate { return true; };
- never = delegate { return false; };
- even = delegate(int i) { return i % 2 == 0; };
- }
- [Test]
- public void All()
- {
- Assert.IsTrue(list.All(always));
- Assert.IsTrue(list.All(never));
- Assert.IsTrue(list.All(even));
- list.Add(8);
- Assert.IsTrue(list.All(always));
- Assert.IsFalse(list.All(never));
- Assert.IsTrue(list.All(even));
- list.Add(5);
- Assert.IsTrue(list.All(always));
- Assert.IsFalse(list.All(never));
- Assert.IsFalse(list.All(even));
- }
- [Test]
- public void Exists()
- {
- Assert.IsFalse(list.Exists(always));
- Assert.IsFalse(list.Exists(never));
- Assert.IsFalse(list.Exists(even));
- list.Add(5);
- Assert.IsTrue(list.Exists(always));
- Assert.IsFalse(list.Exists(never));
- Assert.IsFalse(list.Exists(even));
- list.Add(8);
- Assert.IsTrue(list.Exists(always));
- Assert.IsFalse(list.Exists(never));
- Assert.IsTrue(list.Exists(even));
- }
- [Test]
- public void Apply()
- {
- int sum = 0;
- Act<int> a = delegate(int i) { sum = i + 10 * sum; };
- list.Apply(a);
- Assert.AreEqual(0, sum);
- sum = 0;
- list.Add(5); list.Add(8); list.Add(7); list.Add(5);
- list.Apply(a);
- Assert.AreEqual(5875, sum);
- }
- [TearDown]
- public void Dispose() { list = null; }
- }
- [TestFixture]
- public class GetEnumerator
- {
- private ArrayList<int> list;
- [SetUp]
- public void Init() { list = new ArrayList<int>(); }
- [Test]
- public void Empty()
- {
- SCG.IEnumerator<int> e = list.GetEnumerator();
- Assert.IsFalse(e.MoveNext());
- }
- [Test]
- public void Normal()
- {
- list.Add(5);
- list.Add(8);
- list.Add(5);
- list.Add(5);
- list.Add(10);
- list.Add(1);
- SCG.IEnumerator<int> e = list.GetEnumerator();
- Assert.IsTrue(e.MoveNext());
- Assert.AreEqual(5, e.Current);
- Assert.IsTrue(e.MoveNext());
- Assert.AreEqual(8, e.Current);
- Assert.IsTrue(e.MoveNext());
- Assert.AreEqual(5, e.Current);
- Assert.IsTrue(e.MoveNext());
- Assert.AreEqual(5, e.Current);
- Assert.IsTrue(e.MoveNext());
- Assert.AreEqual(10, e.Current);
- Assert.IsTrue(e.MoveNext());
- Assert.AreEqual(1, e.Current);
- Assert.IsFalse(e.MoveNext());
- }
- [Test]
- public void DoDispose()
- {
- list.Add(5);
- list.Add(8);
- list.Add(5);
- SCG.IEnumerator<int> e = list.GetEnumerator();
- e.MoveNext();
- e.MoveNext();
- e.Dispose();
- }
- [Test]
- [ExpectedException(typeof(CollectionModifiedException))]
- public void MoveNextAfterUpdate()
- {
- list.Add(5);
- list.Add(8);
- list.Add(5);
- SCG.IEnumerator<int> e = list.GetEnumerator();
- e.MoveNext();
- list.Add(99);
- e.MoveNext();
- }
- [TearDown]
- public void Dispose() { list = null; }
- }
- }
- namespace CollectionOrSink
- {
- [TestFixture]
- public class Formatting
- {
- ICollection<int> coll;
- IFormatProvider rad16;
- [SetUp]
- public void Init() { coll = Factory.New<int>(); rad16 = new RadixFormatProvider(16); }
- [TearDown]
- public void Dispose() { coll = null; rad16 = null; }
- [Test]
- public void Format()
- {
- Assert.AreEqual("[ ]", coll.ToString());
- coll.AddAll<int>(new int[] { -4, 28, 129, 65530 });
- Assert.AreEqual("[ 0:-4, 1:28, 2:129, 3:65530 ]", coll.ToString());
- Assert.AreEqual("[ 0:-4, 1:1C, 2:81, 3:FFFA ]", coll.ToString(null, rad16));
- Assert.AreEqual("[ 0:-4, 1:28... ]", coll.ToString("L14", null));
- Assert.AreEqual("[ 0:-4, 1:1C... ]", coll.ToString("L14", rad16));
- }
- }
- [TestFixture]
- public class CollectionOrSink
- {
- private ArrayList<int> list;
- [SetUp]
- public void Init() { list = new ArrayList<int>(); }
- [Test]
- public void Choose()
- {
- list.Add(7);
- Assert.AreEqual(7, list.Choose());
- }
- [Test]
- [ExpectedException(typeof(NoSuchItemException))]
- public void BadChoose()
- {
- list.Choose();
- }
- [Test]
- public void CountEtAl()
- {
- Assert.AreEqual(0, list.Count);
- Assert.IsTrue(list.IsEmpty);
- Assert.IsTrue(list.AllowsDuplicates);
- list.Add(5);
- Assert.AreEqual(1, list.Count);
- Assert.IsFalse(list.IsEmpty);
- list.Add(5);
- Assert.AreEqual(2, list.Count);
- Assert.IsFalse(list.IsEmpty);
- list.Add(8);
- Assert.AreEqual(3, list.Count);
- }
- [Test]
- public void AddAll()
- {
- list.Add(3); list.Add(4); list.Add(5);
- ArrayList<int> list2 = new ArrayList<int>();
- list2.AddAll(list);
- Assert.IsTrue(IC.eq(list2, 3, 4, 5));
- list.AddAll(list2);
- Assert.IsTrue(IC.eq(list2, 3, 4, 5));
- Assert.IsTrue(IC.eq(list, 3, 4, 5, 3, 4, 5));
- }
- [TearDown]
- public void Dispose() { list = null; }
- }
- [TestFixture]
- public class FindPredicate
- {
- private ArrayList<int> list;
- Fun<int, bool> pred;
- [SetUp]
- public void Init()
- {
- list = new ArrayList<int>(TenEqualityComparer.Default);
- pred = delegate(int i) { return i % 5 == 0; };
- }
- [TearDown]
- public void Dispose() { list = null; }
- [Test]
- public void Find()
- {
- int i;
- Assert.IsFalse(list.Find(pred, out i));
- list.AddAll<int>(new int[] { 4, 22, 67, 37 });
- Assert.IsFalse(list.Find(pred, out i));
- list.AddAll<int>(new int[] { 45, 122, 675, 137 });
- Assert.IsTrue(list.Find(pred, out i));
- Assert.AreEqual(45, i);
- }
- [Test]
- public void FindLast()
- {
- int i;
- Assert.IsFalse(list.FindLast(pred, out i));
- list.AddAll<int>(new int[] { 4, 22, 67, 37 });
- Assert.IsFalse(list.FindLast(pred, out i));
- list.AddAll<int>(new int[] { 45, 122, 675, 137 });
- Assert.IsTrue(list.FindLast(pred, out i));
- Assert.AreEqual(675, i);
- }
- [Test]
- public void FindIndex()
- {
- Assert.IsFalse(0 <= list.FindIndex(pred));
- list.AddAll<int>(new int[] { 4, 22, 67, 37 });
- Assert.IsFalse(0 <= list.FindIndex(pred));
- list.AddAll<int>(new int[] { 45, 122, 675, 137 });
- Assert.AreEqual(4, list.FindIndex(pred));
- }
- [Test]
- public void FindLastIndex()
- {
- Assert.IsFalse(0 <= list.FindLastIndex(pred));
- list.AddAll<int>(new int[] { 4, 22, 67, 37 });
- Assert.IsFalse(0 <= list.FindLastIndex(pred));
- list.AddAll<int>(new int[] { 45, 122, 675, 137 });
- Assert.AreEqual(6, list.FindLastIndex(pred));
- }
- }
- [TestFixture]
- public class UniqueItems
- {
- private ArrayList<int> list;
- [SetUp]
- public void Init() { list = new ArrayList<int>(); }
- [TearDown]
- public void Dispose() { list = null; }
- [Test]
- public void Test()
- {
- Assert.IsTrue(IC.seteq(list.UniqueItems()));
- Assert.IsTrue(IC.seteq(list.ItemMultiplicities()));
- list.AddAll<int>(new int[] { 7, 9, 7 });
- Assert.IsTrue(IC.seteq(list.UniqueItems(), 7, 9));
- Assert.IsTrue(IC.seteq(list.ItemMultiplicities(), 7, 2, 9, 1));
- }
- }
- [TestFixture]
- public class ArrayTest
- {
- private ArrayList<int> list;
- int[] a;
- [SetUp]
- public void Init()
- {
- list = new ArrayList<int>();
- a = new int[10];
- for (int i = 0; i < 10; i++)
- a[i] = 1000 + i;
- }
- [TearDown]
- public void Dispose() { list = null; }
- private string aeq(int[] a, params int[] b)
- {
- if (a.Length != b.Length)
- return "Lengths differ: " + a.Length + " != " + b.Length;
- for (int i = 0; i < a.Length; i++)
- if (a[i] != b[i])
- return String.Format("{0}'th elements differ: {1} != {2}", i, a[i], b[i]);
- return "Alles klar";
- }
- [Test]
- public void ToArray()
- {
- Assert.AreEqual("Alles klar", aeq(list.ToArray()));
- list.Add(7);
- list.Add(7);
- Assert.AreEqual("Alles klar", aeq(list.ToArray(), 7, 7));
- }
- [Test]
- public void CopyTo()
- {
- list.CopyTo(a, 1);
- Assert.AreEqual("Alles klar", aeq(a, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009));
- list.Add(6);
- list.CopyTo(a, 2);
- Assert.AreEqual("Alles klar", aeq(a, 1000, 1001, 6, 1003, 1004, 1005, 1006, 1007, 1008, 1009));
- list.Add(4);
- list.Add(4);
- list.Add(9);
- list.CopyTo(a, 4);
- Assert.AreEqual("Alles klar", aeq(a, 1000, 1001, 6, 1003, 6, 4, 4, 9, 1008, 1009));
- list.Clear();
- list.Add(7);
- list.CopyTo(a, 9);
- Assert.AreEqual("Alles klar", aeq(a, 1000, 1001, 6, 1003, 6, 4, 4, 9, 1008, 7));
- }
- [Test]
- [ExpectedException(typeof(ArgumentOutOfRangeException))]
- public void CopyToBad()
- {
- list.CopyTo(a, 11);
- }
- [Test]
- [ExpectedException(typeof(ArgumentOutOfRangeException))]
- public void CopyToBad2()
- {
- list.CopyTo(a, -1);
- }
- [Test]
- [ExpectedException(typeof(ArgumentOutOfRangeException))]
- public void CopyToTooFar()
- {
- list.Add(3);
- list.Add(3);
- list.CopyTo(a, 9);
- }
- }
- [TestFixture]
- public class Sync
- {
- private ArrayList<int> list;
- [SetUp]
- public void Init()
- {
- list = new ArrayList<int>();
- }
- [TearDown]
- public void Dispose() { list = null; }
- [Test]
- public void Get()
- {
- Assert.IsNotNull(((System.Collections.IList)list).SyncRoot);
- }
- }
- }
- namespace EditableCollection
- {
- [TestFixture]
- public class Searching
- {
- private ArrayList<int> list;
- [SetUp]
- public void Init() { list = new ArrayList<int>(); }
- [Test]
- [ExpectedException(typeof(NullReferenceException))]
- public void NullEqualityComparerinConstructor1()
- {
- new ArrayList<int>(null);
- }
- [Test]
- [ExpectedException(typeof(NullReferenceException))]
- public void NullEqualityComparerinConstructor2()
- {
- new ArrayList<int>(5, null);
- }
- [Test]
- public void Contains()
- {
- Assert.IsFalse(list.Contains(5));
- list.Add(5);
- Assert.IsTrue(list.Contains(5));
- Assert.IsFalse(list.Contains(7));
- list.Add(8);
- list.Add(10);
- Assert.IsTrue(list.Contains(5));
- Assert.IsFalse(list.Contains(7));
- Assert.IsTrue(list.Contains(8));
- Assert.IsTrue(list.Contains(10));
- list.Remove(8);
- Assert.IsTrue(list.Contains(5));
- Assert.IsFalse(list.Contains(7));
- Assert.IsFalse(list.Contains(8));
- Assert.IsTrue(list.Contains(10));
- }
- [Test]
- public void ContainsCount()
- {
- Assert.AreEqual(0, list.ContainsCount(5));
- list.Add(5);
- Assert.AreEqual(1, list.ContainsCount(5));
- Assert.AreEqual(0, list.ContainsCount(7));
- list.Add(8);
- Assert.AreEqual(1, list.ContainsCount(5));
- Assert.AreEqual(0, list.ContainsCount(7));
- Assert.AreEqual(1, list.ContainsCount(8));
- list.Add(5);
- Assert.AreEqual(2, list.ContainsCount(5));
- Assert.AreEqual(0, list.ContainsCount(7));
- Assert.AreEqual(1, list.ContainsCount(8));
- }
- [Test]
- public void RemoveAllCopies()
- {
- list.Add(5); list.Add(7); list.Add(5);
- Assert.AreEqual(2, list.ContainsCount(5));
- Assert.AreEqual(1, list.ContainsCount(7));
- list.RemoveAllCopies(5);
- Assert.AreEqual(0, list.ContainsCount(5));
- Assert.AreEqual(1, list.ContainsCount(7));
- list.Add(5); list.Add(8); list.Add(5);
- list.RemoveAllCopies(8);
- Assert.IsTrue(IC.eq(list, 7, 5, 5));
- }
- [Test]
- public void FindAll()
- {
- Fun<int, bool> f = delegate(int i) { return i % 2 == 0; };
- Assert.IsTrue(list.FindAll(f).IsEmpty);
- list.Add(5); list.Add(8); list.Add(5); list.Add(10); list.Add(8);
- Assert.IsTrue(((ArrayList<int>)list.FindAll(f)).Check());
- Assert.IsTrue(IC.eq(list.FindAll(f), 8, 10, 8));
- }
- [Test]
- public void ContainsAll()
- {
- ArrayList<int> list2 = new ArrayList<int>();
- Assert.IsTrue(list.ContainsAll(list2));
- list2.Add(4);
- Assert.IsFalse(list.ContainsAll(list2));
- list.Add(4);
- Assert.IsTrue(list.ContainsAll(list2));
- list.Add(5);
- Assert.IsTrue(list.ContainsAll(list2));
- list2.Add(4);
- Assert.IsFalse(list.ContainsAll(list2));
- list.Add(4);
- Assert.IsTrue(list.ContainsAll(list2));
- }
- [Test]
- public void RetainAll()
- {
- ArrayList<int> list2 = new ArrayList<int>();
- list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6);
- list2.Add(5); list2.Add(4); list2.Add(7); list2.Add(7); list2.Add(4);
- list.RetainAll(list2);
- Assert.IsTrue(list.Check());
- Assert.IsTrue(IC.eq(list, 4, 4, 5));
- list.Add(5); list.Add(4); list.Add(6);
- list2.Clear();
- list2.Add(5); list2.Add(5); list2.Add(6);
- list.RetainAll(list2);
- Assert.IsTrue(list.Check());
- Assert.IsTrue(IC.eq(list, 5, 5, 6));
- list2.Clear();
- list2.Add(7); list2.Add(8); list2.Add(9);
- list.RetainAll(list2);
- Assert.IsTrue(list.Check());
- Assert.IsTrue(IC.eq(list));
- }
- [Test]
- public void RemoveAll()
- {
- ArrayList<int> list2 = new ArrayList<int>();
- list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6);
- list2.Add(5); list2.Add(4); list2.Add(7); list2.Add(7); list2.Add(4);
- list.RemoveAll(list2);
- Assert.IsTrue(list.Check());
- Assert.IsTrue(IC.eq(list, 4, 6));
- list.Add(5); list.Add(4); list.Add(6);
- list2.Clear();
- list2.Add(6); list2.Add(5); list2.Add(5); list2.Add(6);
- list.RemoveAll(list2);
- Assert.IsTrue(list.Check());
- Assert.IsTrue(IC.eq(list, 4, 4));
- list2.Clear();
- list2.Add(7); list2.Add(8); list2.Add(9);
- list.RemoveAll(list2);
- Assert.IsTrue(list.Check());
- Assert.IsTrue(IC.eq(list, 4, 4));
- }
- [Test]
- public void Remove()
- {
- Assert.IsFalse(list.FIFO);
- list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6);
- Assert.IsFalse(list.Remove(2));
- Assert.IsTrue(list.Check());
- Assert.IsTrue(list.Remove(4));
- Assert.IsTrue(list.Check());
- Assert.IsTrue(IC.eq(list, 4, 4, 5, 6));
- Assert.AreEqual(6, list.RemoveLast());
- Assert.IsTrue(list.Check());
- Assert.IsTrue(IC.eq(list, 4, 4, 5));
- list.Add(7);
- Assert.AreEqual(4, list.RemoveFirst());
- Assert.IsTrue(list.Check());
- Assert.IsTrue(IC.eq(list, 4, 5, 7));
- list.FIFO = true;
- list.Clear();
- list.Add(4); list.Add(4); list.Add(5); list.Add(4); list.Add(6);
- Assert.IsFalse(list.Remove(2));
- Assert.IsTrue(list.Check());
- Assert.IsTrue(list.Remove(4));
- Assert.IsTrue(list.Check());
- Assert.IsTrue(IC.eq(list, 4, 5, 4, 6));
- Assert.AreEqual(6, list.RemoveLast());
- Assert.IsTrue(list.Check());
- Assert.IsTrue(IC.eq(list, 4, 5, 4));
- list.Add(7);
- Assert.AreEqual(4, list.RemoveFirst());
- Assert.IsTrue(list.Check());
- Assert.IsTrue(IC.eq(list, 5, 4, 7));
- }
- [Test]
- public void Clear()
- {
- list.Add(7); list.Add(7);
- list.Clear();
- Assert.IsTrue(list.IsEmpty);
- }
- [TearDown]
- public void Dispose() { list = null; }
- }
- }
- namespace Indexed
- {
- [TestFixture]
- public class Searching
- {
- private IIndexed<int> dit;
- [SetUp]
- public void Init()
- {
- dit = new ArrayList<int>();
- }
- [Test]
- public void IndexOf()
- {
- Assert.AreEqual(~0, dit.IndexOf(6));
- dit.Add(7);
- Assert.AreEqual(~1, dit.IndexOf(6));
- Assert.AreEqual(~1, dit.LastIndexOf(6));
- Assert.AreEqual(0, dit.IndexOf(7));
- dit.Add(5); dit.Add(7); dit.Add(8); dit.Add(7);
- Assert.AreEqual(~5, dit.IndexOf(6));
- Assert.AreEqual(0, dit.IndexOf(7));
- Assert.AreEqual(4, dit.LastIndexOf(7));
- Assert.AreEqual(3, dit.IndexOf(8));
- Assert.AreEqual(1, dit.LastIndexOf(5));
- }
- [TearDown]
- public void Dispose()
- {
- dit = null;
- }
- }
- [TestFixture]
- public class Removing
- {
- private IIndexed<int> dit;
- [SetUp]
- public void Init()
- {
- dit = new ArrayList<int>();
- }
- [Test]
- public void RemoveAt()
- {
- dit.Add(5); dit.Add(7); dit.Add(9); dit.Add(1); dit.Add(2);
- Assert.AreEqual(7, dit.RemoveAt(1));
- Assert.IsTrue(((ArrayList<int>)dit).Check());
- Assert.IsTrue(IC.eq(dit, 5, 9, 1, 2));
- Assert.AreEqual(5, dit.RemoveAt(0));
- Assert.IsTrue(((ArrayList<int>)dit).Check());
- Assert.IsTrue(IC.eq(dit, 9, 1, 2));
- Assert.AreEqual(2, dit.RemoveAt(2));
- Assert.IsTrue(((ArrayList<int>)dit).Check());
- Assert.IsTrue(IC.eq(dit, 9, 1));
- }
- [Test]
- [ExpectedException(typeof(IndexOutOfRangeException))]
- public void RemoveAtBad0()
- {
- dit.RemoveAt(0);
- }
- [Test]
- [ExpectedException(typeof(IndexOutOfRangeException))]
- public void RemoveAtBadM1()
- {
- dit.RemoveAt(-1);
- }
- [Test]
- [ExpectedException(typeof(IndexOutOfRangeException))]
- public void RemoveAtBad1()
- {
- dit.Add(8);
- dit.RemoveAt(1);
- }
- [Test]
- public void RemoveInterval()
- {
- dit.RemoveInterval(0, 0);
- dit.Add(10); dit.Add(20); dit.Add(30); dit.Add(40); dit.Add(50); dit.Add(60);
- dit.RemoveInterval(3, 0);
- Assert.IsTrue(((ArrayList<int>)dit).Check());
- Assert.IsTrue(IC.eq(dit, 10, 20, 30, 40, 50, 60));
- dit.RemoveInterval(3, 1);
- Assert.IsTrue(((ArrayList<int>)dit).Check());
- Assert.IsTrue(IC.eq(dit, 10, 20, 30, 50, 60));
- dit.RemoveInterval(1, 3);
- Assert.IsTrue(((ArrayList<int>)dit).Check());
- Assert.IsTrue(IC.eq(dit, 10, 60));
- dit.RemoveInterval(0, 2);
- Assert.IsTrue(((ArrayList<int>)dit).Check());
- Assert.IsTrue(IC.eq(dit));
- dit.Add(10); dit.Add(20); dit.Add(30); dit.Add(40); dit.Add(50); dit.Add(60);
- dit.RemoveInterval(0, 2);
- Assert.IsTrue(((ArrayList<int>)dit).Check());
- Assert.IsTrue(IC.eq(dit, 30, 40, 50, 60));
- dit.RemoveInterval(2, 2);
- Assert.IsTrue(((ArrayList<int>)dit).Check());
- Assert.IsTrue(IC.eq(dit, 30, 40));
- }
- [TearDown]
- public void Dispose()
- {
- dit = null;
- }
- }
- }
- namespace List
- {
- [TestFixture]
- public class Searching
- {
- private IList<int> lst;
- [SetUp]
- public void Init() { lst = new ArrayList<int>(); }
- [TearDown]
- public void Dispose() { lst = null; }
- [Test]
- [ExpectedException(typeof(NoSuchItemException))]
- public void FirstBad()
- {
- int f = lst.First;
- }
- [Test]
- [ExpectedException(typeof(NoSuchItemException))]
- public void LastBad()
- {
- int f = lst.Last;
- }
- [Test]
- public void FirstLast()
- {
- lst.Add(19);
- Assert.AreEqual(19, lst.First);
- Assert.AreEqual(19, lst.Last);
- lst.Add(34); lst.InsertFirst(12);
- Assert.AreEqual(12, lst.First);
- Assert.AreEqual(34, lst.Last);
- }
- [Test]
- public void This()
- {
- lst.Add(34);
- Assert.AreEqual(34, lst[0]);
- lst[0] = 56;
- Assert.AreEqual(56, lst.First);
- lst.Add(7); lst.Add(7); lst.Add(7); lst.Add(7);
- lst[0] = 45; lst[2] = 78; lst[4] = 101;
- Assert.IsTrue(IC.eq(lst, 45, 7, 78, 7, 101));
- }
- [Test]
- [ExpectedException(typeof(IndexOutOfRangeException))]
- public void ThisBadEmptyGet()
- {
- int f = lst[0];
- }
- [Test]
- [ExpectedException(typeof(IndexOutOfRangeException))]
- public void ThisBadLowGet()
- {
- lst.Add(7);
- int f = lst[-1];
- }
- [Test]
- [ExpectedException(typeof(IndexOutOfRangeException))]
- public void ThisBadHiGet()
- {
- lst.Add(6);
- int f = lst[1];
- }
- [Test]
- [ExpectedException(typeof(IndexOutOfRangeException))]
- public void ThisBadEmptySet()
- {
- lst[0] = 4;
- }
- [Test]
- [ExpectedException(typeof(IndexOutOfRangeException))]
- public void ThisBadLowSet()
- {
- lst.Add(7);
- lst[-1] = 9;
- }
- [Test]
- [ExpectedException(typeof(IndexOutOfRangeException))]
- public void ThisBadHiSet()
- {
- lst.Add(6);
- lst[1] = 11;
- }
- }
- [TestFixture]
- public class Inserting
- {
- private IList<int> lst;
- [SetUp]
- public void Init() { lst = new ArrayList<int>(); }
- [TearDown]
- public void Dispose() { lst = null; }
- [Test]
- public void Insert()
- {
- lst.Insert(0, 5);
- Assert.IsTrue(IC.eq(lst, 5));
- lst.Insert(0, 7);
- Assert.IsTrue(IC.eq(lst, 7, 5));
- lst.Insert(1, 4);
- Assert.IsTrue(IC.eq(lst, 7, 4, 5));
- lst.Insert(3, 2);
- Assert.IsTrue(IC.eq(lst, 7, 4, 5, 2));
- }
- [Test]
- public void InsertDuplicate()
- {
- lst.Insert(0, 5);
- Assert.IsTrue(IC.eq(lst, 5));
- lst.Insert(0, 7);
- Assert.IsTrue(IC.eq(lst, 7, 5));
- lst.Insert(1, 5);
- Assert.IsTrue(IC.eq(lst, 7, 5, 5));
- }
- [Test]
- public void InsertAllDuplicate1()
- {
- lst.Insert(0, 3);
- Assert.IsTrue(IC.eq(lst, 3));
- lst.Insert(0, 7);
- Assert.IsTrue(IC.eq(lst, 7, 3));
- lst.InsertAll<int>(1, new int[] { 1, 2, 3, 4 });
- Assert.IsTrue(IC.eq(lst, 7, 1, 2, 3, 4, 3));
- Assert.IsTrue(lst.Check());
- }
- [Test]
- public void InsertAllDuplicate2()
- {
- lst.Insert(0, 3);
- Assert.IsTrue(IC.eq(lst, 3));
- lst.Insert(0, 7);
- Assert.IsTrue(IC.eq(lst, 7, 3));
- lst.InsertAll<int>(1, new int[] { 5, 6, 5, 8 });
- Assert.IsTrue(lst.Check());
- Assert.IsTrue(IC.eq(lst, 7, 5, 6, 5, 8, 3));
- }
- [Test]
- [ExpectedException(typeof(IndexOutOfRangeException))]
- public void BadInsertLow()
- {
- lst.Add(7);
- lst.Insert(-1, 9);
- }
- [Test]
- [ExpectedException(typeof(IndexOutO…
Large files files are truncated, but you can click here to view the full file