public void GetAndReturnAndGetAgain() { var pool = new Carambolas.Net.Memory.Pool(); var m1 = pool.Get(); pool.Return(m1); var m2 = pool.Get(); pool.Return(m2); Assert.Same(m1, m2); }
public void InitialLength() { var pool = new Carambolas.Net.Memory.Pool(); var m = pool.Get(); Assert.Equal(0, m.Length); }
public void InvalidGetterIndexFails(int index) { var pool = new Carambolas.Net.Memory.Pool(); var m = pool.Get(); Assert.Throws <ArgumentOutOfRangeException>(() => { var x = m[index]; }); }
public void InitialCapacity() { var pool = new Carambolas.Net.Memory.Pool(); var m = pool.Get(); Assert.Equal(0, m.Capacity); }
public void SetLength(int expectedLength, int expectedCapacity) { var pool = new Carambolas.Net.Memory.Pool(); var m = pool.Get(); m.Length = expectedLength; Assert.Equal(expectedLength, m.Length); Assert.Equal(expectedCapacity, m.Capacity); }
public void Disposal() { var pool = new Carambolas.Net.Memory.Pool(); var m = pool.Get(); var version = m.Version; m.Dispose(); Assert.NotEqual(version, m.Version); Assert.Equal(0, m.Capacity); Assert.Equal(0, m.Length); }
public void GetMultiple(int n) { var pool = new Carambolas.Net.Memory.Pool(); var m = new Net.Memory[n]; for (int i = 0; i < n; ++i) { m[i] = pool.Get(); } for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { Assert.NotSame(m[i], m[j]); } } }
public void CopyFromAndTo(int length) { var source = new byte[length]; var destination = new byte[length]; var expected = new byte[length]; for (int i = 0; i < length; ++i) { expected[i] = source[i] = (byte)i; } var pool = new Carambolas.Net.Memory.Pool(); var m = pool.Get(); m.CopyFrom(source); Assert.Equal(expected, source); m.CopyTo(destination); Assert.Equal(new ArraySegment <byte>(expected, 0, length) as IEnumerable <byte>, new ArraySegment <byte>(destination, 0, length) as IEnumerable <byte>); }
public void GetAndReturn() { var pool = new Carambolas.Net.Memory.Pool(); long version; var m = pool.Get(); try { Assert.NotNull(m); version = m.Version; } finally { pool.Return(m); } Assert.NotEqual(version, m.Version); Assert.Equal(0, m.Capacity); Assert.Equal(0, m.Length); }
public void ValidGetterSetterIndexes(int i0, int i1, int i2, int i3, int expectedLength, int expectedCapacity) { var pool = new Carambolas.Net.Memory.Pool(); var m = pool.Get(); m[i0] = (byte)i0; m[i1] = (byte)i1; m[i2] = (byte)i2; Assert.Equal(3, m.Length); Assert.Equal(64, m.Capacity); m[i3] = (byte)i3; Assert.Equal(expectedLength, m.Length); Assert.Equal(expectedCapacity, m.Capacity); Assert.Equal((byte)i0, m[i0]); Assert.Equal((byte)i1, m[i1]); Assert.Equal((byte)i2, m[i2]); Assert.Equal((byte)i3, m[i3]); }