public void InvalidTypeTest() { var arr = UnsafeArray.Allocate <int>(10); Assert.Catch <AssertException>(() => { UnsafeArray.Set <float>(arr, 4, 20); }); UnsafeArray.Free(arr); }
public void ConstructorTest() { var arr = UnsafeArray.Allocate <int>(10); Assert.AreEqual(UnsafeArray.GetLength(arr), 10); for (int i = 0; i < 10; i++) { Assert.AreEqual(0, UnsafeArray.Get <int>(arr, i)); } UnsafeArray.Free(arr); }
public void MutateTest() { var arr = UnsafeArray.Allocate <int>(10); for (int i = 0; i < 10; i++) { UnsafeArray.Set(arr, i, i); } for (int i = 0; i < 10; i++) { Assert.AreEqual(i, UnsafeArray.Get <int>(arr, i)); } UnsafeArray.Free(arr); }
public void TestBitSet() { UnsafeBitSet *bitSet = UnsafeBitSet.Allocate(64); UnsafeBitSet.Set(bitSet, 1); UnsafeBitSet.Set(bitSet, 2); UnsafeBitSet.Set(bitSet, 3); UnsafeBitSet.Set(bitSet, 61); UnsafeArray *setBits = UnsafeArray.Allocate <int>(UnsafeBitSet.GetSize(bitSet)); var setBitsCount = UnsafeBitSet.ToArray(bitSet, setBits); for (int i = 0; i < setBitsCount; i++) { Assert.IsTrue(UnsafeBitSet.IsSet(bitSet, UnsafeArray.Get <int>(setBits, i))); } UnsafeBitSet.Free(bitSet); UnsafeArray.Free(setBits); }
public void IteratorTest() { var arr = UnsafeArray.Allocate <int>(10); unsafe { var itr = UnsafeArray.GetEnumerator <int>(arr); for (int i = 0; i < 10; i++) { UnsafeArray.Set(arr, i, i * i); } int num = 0; foreach (int i in itr) { Assert.AreEqual(num * num, i); num++; } } UnsafeArray.Free(arr); }
public NativeArray(NativeArray <T> array) { m_inner = UnsafeArray.Allocate <T>(array.Length); Copy(array, this); }
public NativeArray(int length) { m_inner = UnsafeArray.Allocate <T>(length); }