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)); }
private static void CheckListEquality <T>(IList <T> expected, IPersistentList <T> given) { Assert.Equal(expected.Count, given.Count); // check using indexer for (int i = 0; i < expected.Count; i++) { Assert.Equal(expected[i], given[i]); } // same check using enumerators foreach (IEnumerator enumerator in new IEnumerator[] { given.GetEnumerator(), ((IEnumerable)given).GetEnumerator() }) { IEnumerator expectedEnumerator = expected.GetEnumerator(); while (expectedEnumerator.MoveNext()) { Assert.True(enumerator.MoveNext()); Assert.Equal(expectedEnumerator.Current, enumerator.Current); } Assert.False(enumerator.MoveNext()); } }
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(); }
public override IEnumerator GetEnumerator() { return(small != null?small.GetEnumerator() : large.GetEnumerator()); }