public void ThrowIfDisposedTest() { var array = new NativeMemoryArray <int>(DefaultUnmanagedMemoryAllocator.Instance, 1); array.Dispose(); // should be able to dispose twice and do a "resize" to current size Assert.DoesNotThrow(() => array.Dispose()); Assert.DoesNotThrow(() => array.Resize(0)); // but should not be able to resurrect Assert.Throws <ObjectDisposedException>(() => array.Resize(1)); }
public void ResizeTest() { var intArrayRef = new int[1000]; var intArray = new NativeMemoryArray <int>(DefaultUnmanagedMemoryAllocator.Instance, 1000); var randomGenerator = new System.Random(8675309); // make this deterministic for (int idx = 0; idx < 1000; idx++) { if (randomGenerator.Next(4) >= 2) { // add data. intArrayRef[idx] = idx; intArray[idx] = idx; } else { intArrayRef[idx] = 0; intArray[idx] = 0; } } Array.Resize(ref intArrayRef, 335); intArray.Resize(335); Assert.AreEqual(intArrayRef.Length, intArray.Length); for (int idx = 0; idx < intArrayRef.Length; idx++) { Assert.AreEqual(intArrayRef[idx], intArray[idx]); } intArrayRef = new int[1000]; intArray.Dispose(); intArray = new NativeMemoryArray <int>(DefaultUnmanagedMemoryAllocator.Instance, 1000); for (int idx = 0; idx < 1000; idx++) { if (randomGenerator.Next(4) >= 2) { // add data. intArrayRef[idx] = idx; intArray[idx] = idx; } else { intArrayRef[idx] = 0; intArray[idx] = 0; } } Array.Resize(ref intArrayRef, 1235); intArray.Resize(1235); Assert.AreEqual(intArrayRef.Length, intArray.Length); for (int idx = 0; idx < intArrayRef.Length; idx++) { Assert.AreEqual(intArrayRef[idx], intArray[idx]); } intArray.Dispose(); }