public void CopyFromTest4()
    {
        int[] innerArr   = Enumerable.Range(0, 10).ToArray();
        int[] map        = new int[] { 5, 3, 8, 0, 9 };
        var   mappingVec = new MappingVector <int>(innerArr, map);

        int[] srcArr = Enumerable.Range(100, 10).ToArray();
        mappingVec.CopyFrom(srcArr, 5, 1, 2);

        // Test the segment yields the expected values.
        int[] expectedInnerArr = new int[] { 0, 1, 2, 105, 4, 5, 6, 7, 106, 9 };
        Assert.Equal(expectedInnerArr, innerArr);
    }
Example #2
0
        public void CopyFromTest2()
        {
            int[] innerArr   = Enumerable.Range(0, 10).ToArray();
            int[] map        = new int[] { 5, 3, 8, 0, 9 };
            var   mappingVec = new MappingVector <int>(innerArr, map);

            int[] srcArr = Enumerable.Range(100, 3).ToArray();
            mappingVec.CopyFrom(srcArr, 1);

            // Test the segment yields the expected values.
            int[] expectedInnerArr = new int[] { 102, 1, 2, 100, 4, 5, 6, 7, 101, 9 };
            Compare(expectedInnerArr, innerArr);
        }
    public void CopyFromTest_InvalidCopyOperations()
    {
        int[] innerArr   = Enumerable.Range(0, 10).ToArray();
        int[] map        = new int[] { 5, 3, 8, 0 };
        var   mappingVec = new MappingVector <int>(innerArr, map);

        int[] srcArr = Enumerable.Range(100, 3).ToArray();

        //--- Two param tests.
        // Copy beyond end of vecSeg.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 2));

        // Invalid target index.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, -1));

        //--- Three param tests.

        // Copy length longer than srcArr.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 0, 4));

        // Invalid source index.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, -1, 1));

        // Invalid length.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 0, -1));

        // Copy beyond the end of vecSeg.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 2, 3));
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 3, 2));
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 4, 1));

        // Four param tests.

        // Copy beyond end of srcArr.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 0, 0, 4));
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 1, 0, 3));
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 2, 0, 2));
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 3, 0, 1));

        // Copy beyond the end of vecSeg.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 0, 3, 2));
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 0, 2, 3));

        // Invalid source and target indexes.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, -1, 0, 1));
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 0, -1, 1));

        // Invalid length.
        Assert.Throws <ArgumentException>(() => mappingVec.CopyFrom(srcArr, 0, 0, -1));
    }