using System; using UnitTestSharp; namespace Blacklight.Core.UnitTests { public class ArrayViewTests : TestFixture { public class CtorTests : TestFixture { public void TakesTheCount() { CheckEqual(3, new ArrayView(new int[5], offset: 1, count: 3).Count); } public void EmptyRunAtTheEnd_IsAllowed() { CheckEqual(0, new ArrayView(new int[5], offset: 5, count: 0).Count); } public void NullArray_Throws() { CheckThrow(typeof(ArgumentNullException)); new ArrayView(null, offset: 0, count: 0); } public void NegativeOffset_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new ArrayView(new int[5], offset: -1, count: 0); } public void OffsetPastTheEnd_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new ArrayView(new int[5], offset: 6, count: 0); } public void NegativeCount_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new ArrayView(new int[5], offset: 0, count: -1); } public void RunPastTheEnd_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new ArrayView(new int[5], offset: 2, count: 4); } } public class CountTests : TestFixture { public void Default_IsZero() { CheckEqual(0, default(ArrayView).Count); } } public class IndexerTests : TestFixture { public void ReadsFromTheOffset() { var view = new ArrayView(new[] { 10, 11, 12, 13, 14 }, offset: 1, count: 3); CheckEqual(11, view[0]); CheckEqual(13, view[2]); } public void SeesLaterChangesToTheArray() { int[] array = { 10, 11, 12 }; var view = new ArrayView(array, offset: 0, count: 3); array[1] = 99; CheckEqual(99, view[1]); } public void NegativeIndex_Throws() { var view = new ArrayView(new int[5], offset: 1, count: 3); CheckThrow(typeof(IndexOutOfRangeException)); _ = view[-1]; } public void IndexAtCount_ThrowsEvenWithArrayLeftAfterIt() { var view = new ArrayView(new int[5], offset: 1, count: 3); CheckThrow(typeof(IndexOutOfRangeException)); _ = view[3]; } } } }