public void Add() { var list = new LightweightList <int>(); for (int i = 0; i < 10; i++) { list.Add(i); } Assert.Equal(16, list.Capacity); Assert.Equal(16, list.GetInternalArray().Length); Assert.Equal(10, list.Count); Assert.Equal(10, list.AsSpan().Length); var span = list.AsSpan(); var arr = list.GetInternalArray(); for (int i = 0; i < 10; i++) { Assert.Equal(i, list[i]); Assert.Equal(i, span[i]); Assert.Equal(i, arr[i]); } }
public void RemoveRange() { var list = new LightweightList <int>(); for (int i = 0; i < 10; i++) { list.Add(i); } list.RemoveRange(0, 3); var span = list.AsSpan(); var arr = list.GetInternalArray(); Assert.Equal(7, list.Count); Assert.Equal(7, span.Length); for (int i = 0, j = 3; i < 7; i++, j++) { Assert.Equal(j, list[i]); Assert.Equal(j, span[i]); Assert.Equal(j, arr[i]); } list.RemoveRange(5, 2); span = list.AsSpan(); arr = list.GetInternalArray(); Assert.Equal(5, list.Count); Assert.Equal(5, span.Length); for (int i = 0, j = 3; i < 5; i++, j++) { Assert.Equal(j, list[i]); Assert.Equal(j, span[i]); Assert.Equal(j, arr[i]); } list.RemoveRange(2, 2); span = list.AsSpan(); arr = list.GetInternalArray(); Assert.Equal(3, list.Count); Assert.Equal(3, span.Length); Assert.Equal(3, list[0]); Assert.Equal(3, span[0]); Assert.Equal(3, arr[0]); Assert.Equal(4, list[1]); Assert.Equal(4, span[1]); Assert.Equal(4, arr[1]); Assert.Equal(7, list[2]); Assert.Equal(7, span[2]); Assert.Equal(7, arr[2]); }
public void Clear() { var list = new LightweightList <int>(); for (int i = 0; i < 10; i++) { list.Add(i); } list.Clear(); Assert.Equal(16, list.Capacity); Assert.Equal(16, list.GetInternalArray().Length); Assert.Equal(0, list.Count); Assert.Equal(0, list.AsSpan().Length); }
public void RemoveAt() { var list = new LightweightList <int>(); for (int i = 0; i < 10; i++) { list.Add(i); } list.RemoveAt(9); var span = list.AsSpan(); var arr = list.GetInternalArray(); Assert.Equal(16, list.Capacity); Assert.Equal(16, list.GetInternalArray().Length); Assert.Equal(9, list.Count); Assert.Equal(9, span.Length); for (int i = 0; i < 9; i++) { Assert.Equal(i, list[i]); Assert.Equal(i, span[i]); Assert.Equal(i, arr[i]); } list.RemoveAt(0); span = list.AsSpan(); Assert.Equal(8, list.Count); Assert.Equal(8, span.Length); for (int i = 0, j = 1; i < 8; i++, j++) { Assert.Equal(j, list[i]); Assert.Equal(j, span[i]); Assert.Equal(j, arr[i]); } }