public void RemoveOutOfRangeTest() { const int count = 10; IPersistentList <int> list = PersistentList <int> .Of(new int[count]); Assert.Throws <IndexOutOfRangeException>(() => list.RemoveAt(-1)); Assert.Throws <IndexOutOfRangeException>(() => list.RemoveAt(count)); }
private void CheckEmptyListBehaviour(IPersistentList <int> empty) { Assert.Equal(0, empty.Count); foreach (IEnumerator enumerator in new IEnumerator[] { empty.GetEnumerator(), ((IEnumerable)empty).GetEnumerator() }) { Assert.False(enumerator.MoveNext()); } Assert.Throws <IndexOutOfRangeException>(() => empty[0]); Assert.Throws <IndexOutOfRangeException>(() => empty.RemoveAt(0)); }
public void RemoveAt(int i) { if (small != null) { small.Remove(i); } else { large.RemoveAt(i); } }
private void AddRemoveAtTestImpl(InsertRemoveScenario scenario) { IPersistentList <int> list = PersistentList <int> .Empty; List <int> expected = new List <int>(); int i = 0; foreach (int position in scenario.InsertionOrder) { list = list.Add(position, i); expected.Insert(position, i); CheckListEquality(expected, list); i++; } foreach (int position in scenario.RemovalOrder) { list = list.RemoveAt(position, out int removedValue); Assert.Equal(expected[position], removedValue); expected.RemoveAt(position); CheckListEquality(expected, list); } }
static public void Main(string[] args) { int i; Storage db = StorageFactory.Instance.CreateStorage(); db.Open("testlist2.dbs", pagePoolSize); #if USE_GENERICS IPersistentList <Record> root = (IPersistentList <Record>)db.Root; if (root == null) { root = db.CreateList <Record>(); db.Root = root; } #else IPersistentList root = (IPersistentList)db.Root; if (root == null) { root = db.CreateList(); db.Root = root; } #endif DateTime start = DateTime.Now; for (i = 0; i < nRecords / 2; i++) { Record rec = new Record(); rec.i = i * 2; root.Add(rec); } for (i = 1; i < nRecords; i += 2) { Record rec = new Record(); rec.i = i; root.Insert(i, rec); } db.Commit(); Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - start)); start = DateTime.Now; for (i = 0; i < nRecords; i++) { #if USE_GENERICS Record rec = root[i]; #else Record rec = (Record)root[i]; #endif Debug.Assert(rec.i == i); } Console.WriteLine("Elapsed time for performing " + nRecords + " gets: " + (DateTime.Now - start)); start = DateTime.Now; i = 0; foreach (Record rec in root) { Debug.Assert(rec.i == i); i += 1; } Debug.Assert(i == nRecords); Console.WriteLine("Elapsed time for iteration through " + nRecords + " records: " + (DateTime.Now - start)); start = DateTime.Now; for (i = 0; i < nRecords; i++) { #if USE_GENERICS Record rec = root[0]; #else Record rec = (Record)root[0]; #endif Debug.Assert(rec.i == i); root.RemoveAt(0); rec.Deallocate(); } Debug.Assert(!root.GetEnumerator().MoveNext()); Console.WriteLine("Elapsed time for deleting " + nRecords + " records: " + (DateTime.Now - start)); db.Close(); }