public void New() { using (var list = UnsafeRawList <int> .Null) { Assert.True(list.Equals(list)); Assert.Throws <NullReferenceException>(() => list.Count); Assert.Throws <NullReferenceException>(() => list.Capacity); Assert.Throws <NullReferenceException>(() => list.Ptr); Assert.Throws <NullReferenceException>(() => list.Add(0)); } using (var list = new UnsafeRawList <int>()) { Assert.Equal(0, list.Count); Assert.True(list.Capacity >= 0); Assert.NotEqual(IntPtr.Zero, list.Ptr); } using (var list = new UnsafeRawList <int>(10)) { Assert.Equal(0, list.Count); Assert.Equal(10, list.Capacity); Assert.NotEqual(IntPtr.Zero, list.Ptr); } ReadOnlySpan <int> source = Enumerable.Range(0, 100).ToArray(); using (var list = new UnsafeRawList <int>(source)) { Assert.Equal(source.Length, list.Count); Assert.True(source.Length >= list.Capacity); Assert.NotEqual(IntPtr.Zero, list.Ptr); Assert.True(list.AsSpan().SequenceEqual(source)); } }
public void RemoveAt() { const int Count = 10; ReadOnlySpan <int> source = Enumerable.Range(0, Count).ToArray(); using (var list = new UnsafeRawList <int>(source)) { Assert.True(list.AsSpan().SequenceEqual(source)); list.RemoveAt(5); Assert.True(list.AsSpan().SequenceEqual(new[] { 0, 1, 2, 3, 4, 6, 7, 8, 9 })); list.RemoveAt(0); Assert.True(list.AsSpan().SequenceEqual(new[] { 1, 2, 3, 4, 6, 7, 8, 9 })); list.RemoveAt(1); Assert.True(list.AsSpan().SequenceEqual(new[] { 1, 3, 4, 6, 7, 8, 9 })); list.RemoveAt(6); Assert.True(list.AsSpan().SequenceEqual(new[] { 1, 3, 4, 6, 7, 8, })); } }
public void Add() { using (var list = new UnsafeRawList <int>()) { const int Count = 10; for (int i = 0; i < Count; i++) { list.Add(i); } for (int i = 0; i < list.Count; i++) { Assert.Equal(i, list[i]); } } ReadOnlySpan <int> source = Enumerable.Range(0, 100).ToArray(); using (var list = new UnsafeRawList <int>(source)) { list.AddRange(source); Assert.True(list.AsSpan(0, source.Length).SequenceEqual(source)); Assert.True(list.AsSpan(source.Length, source.Length).SequenceEqual(source)); } }
public void Dispose() { _srcToDest?.Dispose(); foreach (var l in _destLists.AsSpan()) { l.Dispose(); } _destLists.Dispose(); _destToSrc?.Dispose(); foreach (var l in _srcLists.AsSpan()) { l.Dispose(); } _srcLists.Dispose(); }