public static void TestListResizing(IUnmanagedMemoryPool pool) { Random random = new Random(5); var list = new QuickList <int>(4, pool); List <int> controlList = new List <int>(); for (int iterationIndex = 0; iterationIndex < 100000; ++iterationIndex) { if (random.NextDouble() < 0.7) { list.Add(iterationIndex, pool); controlList.Add(iterationIndex); } if (random.NextDouble() < 0.2) { var indexToRemove = random.Next(list.Count); list.RemoveAt(indexToRemove); controlList.RemoveAt(indexToRemove); } if (iterationIndex % 1000 == 0) { list.EnsureCapacity(list.Count * 3, pool); } else if (iterationIndex % 7777 == 0) { list.Compact(pool); } } Debug.Assert(list.Count == controlList.Count); for (int i = 0; i < list.Count; ++i) { var a = list[i]; var b = controlList[i]; Debug.Assert(a == b); Debug.Assert(list.Count == controlList.Count); } list.Dispose(pool); }
public static void TestListResizing() { Random random = new Random(5); UnsafeBufferPool <int> pool = new UnsafeBufferPool <int>(); QuickList <int> list = new QuickList <int>(pool, 2); List <int> controlList = new List <int>(); for (int iterationIndex = 0; iterationIndex < 100000; ++iterationIndex) { if (random.NextDouble() < 0.7) { list.Add(iterationIndex); controlList.Add(iterationIndex); } if (random.NextDouble() < 0.2) { var indexToRemove = random.Next(list.Count); list.RemoveAt(indexToRemove); controlList.RemoveAt(indexToRemove); } if (iterationIndex % 1000 == 0) { list.EnsureCapacity(list.Count * 3); } else if (iterationIndex % 7777 == 0) { list.Compact(); } } Assert.IsTrue(list.Count == controlList.Count); for (int i = 0; i < list.Count; ++i) { var a = list[i]; var b = controlList[i]; Assert.IsTrue(a == b); Assert.IsTrue(list.Count == controlList.Count); } }
public static void TestListResizing() { Random random = new Random(5); UnsafeBufferPool<int> pool = new UnsafeBufferPool<int>(); QuickList<int> list = new QuickList<int>(pool, 2); List<int> controlList = new List<int>(); for (int iterationIndex = 0; iterationIndex < 100000; ++iterationIndex) { if (random.NextDouble() < 0.7) { list.Add(iterationIndex); controlList.Add(iterationIndex); } if (random.NextDouble() < 0.2) { var indexToRemove = random.Next(list.Count); list.RemoveAt(indexToRemove); controlList.RemoveAt(indexToRemove); } if (iterationIndex % 1000 == 0) { list.EnsureCapacity(list.Count * 3); } else if (iterationIndex % 7777 == 0) { list.Compact(); } } Assert.IsTrue(list.Count == controlList.Count); for (int i = 0; i < list.Count; ++i) { var a = list[i]; var b = controlList[i]; Assert.IsTrue(a == b); Assert.IsTrue(list.Count == controlList.Count); } }