Esempio n. 1
0
        public void CopyToTest3()
        {
            int[] innerArr = Enumerable.Range(0, 10).ToArray();
            var   vecSeg   = new VectorSegment <int>(innerArr, 5, 3);

            int[] tgtArr = new int[12];
            vecSeg.CopyTo(tgtArr, 2, 1, 2);

            // Test the segment yields the expected values.
            int[] expectedArr = new int[] { 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0 };
            Compare(expectedArr, tgtArr);
        }
Esempio n. 2
0
        public void CopyToTest_InvalidCopyOperations()
        {
            int[] innerArr = Enumerable.Range(0, 10).ToArray();
            var   vecSeg   = new VectorSegment <int>(innerArr, 5, 3);

            int[] tgtArr = new int[12];

            //--- Two param tests.
            // Copy beyond end of tgtArr.
            Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyTo(tgtArr, 10));

            // Invalid target index.
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => vecSeg.CopyTo(tgtArr, -1));

            //--- Three param tests.
            // Copy length longer then vecSeg length.
            Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyTo(tgtArr, 0, 4));

            // Invalid target index.
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => vecSeg.CopyTo(tgtArr, -1, 1));

            // Invalid length.
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => vecSeg.CopyTo(tgtArr, 0, -1));

            // Copy beyond end of tgtArr.
            Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyTo(tgtArr, 11, 2));
            Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyTo(tgtArr, 12, 1));

            //--- Four param tests.
            // Copy beyond end of vecSeg.
            Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyTo(tgtArr, 0, 1, 3));

            // Copy beyond end of tgtArr.
            Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyTo(tgtArr, 11, 1, 2));
            Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyTo(tgtArr, 12, 1, 1));

            // Invalid source and target indexes.
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => vecSeg.CopyTo(tgtArr, -1, 0, 1));
            Assert.ThrowsException <ArgumentException>(() => vecSeg.CopyTo(tgtArr, 0, -1, 1));

            // Invalid length.
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => vecSeg.CopyTo(tgtArr, 0, 1, -1));
        }