public void CopyFromTest4() { int[] innerArr = Enumerable.Range(0, 10).ToArray(); var vecSeg = new VectorSegment <int>(innerArr, 5, 3); int[] srcArr = Enumerable.Range(100, 10).ToArray(); vecSeg.CopyFrom(srcArr, 5, 1, 2); // Test the segment yields the expected values. int[] expectedInnerArr = new int[] { 0, 1, 2, 3, 4, 5, 105, 106, 8, 9 }; Compare(expectedInnerArr, innerArr); }
public void CopyFromTest1() { int[] innerArr = Enumerable.Range(0, 10).ToArray(); var vecSeg = new VectorSegment <int>(innerArr, 5, 3); int[] srcArr = Enumerable.Range(100, 3).ToArray(); vecSeg.CopyFrom(srcArr, 0); // Test the segment yields the expected values. int[] expectedInnerArr = new int[] { 0, 1, 2, 3, 4, 100, 101, 102, 8, 9 }; Assert.Equal(expectedInnerArr, innerArr); }
public void CopyFromTest_InvalidCopyOperations() { int[] innerArr = Enumerable.Range(0, 10).ToArray(); var vecSeg = new VectorSegment <int>(innerArr, 5, 4); int[] srcArr = Enumerable.Range(100, 3).ToArray(); //--- Two param tests. // Copy beyond end of vecSeg. Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyFrom(srcArr, 2)); // Invalid target index. Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyFrom(srcArr, -1)); //--- Three param tests. // Copy length longer than srcArr. Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyFrom(srcArr, 0, 4)); // Invalid source index. Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyFrom(srcArr, -1, 1)); // Invalid length. Assert.ThrowsException <ArgumentOutOfRangeException>(() => vecSeg.CopyFrom(srcArr, 0, -1)); // Copy beyond the end of vecSeg. Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyFrom(srcArr, 2, 3)); Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyFrom(srcArr, 3, 2)); Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyFrom(srcArr, 4, 1)); // Four param tests. // Copy beyond end of srcArr. Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyFrom(srcArr, 0, 0, 4)); Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyFrom(srcArr, 1, 0, 3)); Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyFrom(srcArr, 2, 0, 2)); Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyFrom(srcArr, 3, 0, 1)); // Copy beyond the end of vecSeg. Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyFrom(srcArr, 0, 3, 2)); Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyFrom(srcArr, 0, 2, 3)); // Invalid source and target indexes. Assert.ThrowsException <ArgumentOutOfRangeException>(() => vecSeg.CopyFrom(srcArr, -1, 0, 1)); Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyFrom(srcArr, 0, -1, 1)); // Invalid length. Assert.ThrowsException <ArgumentOutOfRangeException>(() => vecSeg.CopyFrom(srcArr, 0, 0, -1)); }