Beispiel #1
0
        public void Should_CopyTo_Check_Array_Index()
        {
            //arrange
            var list   = new MyArrayList(new object[] { 1, 2, 3, 4, 5 });
            var result = new int[5];

            //act
            Action actLower    = () => list.CopyTo(result, -1);
            Action actHigher   = () => list.CopyTo(result, 7);
            Action actOverflow = () => list.CopyTo(result, 3);

            //assert
            actLower.ShouldThrow <ArgumentOutOfRangeException>();
            actHigher.ShouldThrow <ArgumentOutOfRangeException>();
            actOverflow.ShouldThrow <ArgumentOutOfRangeException>();
        }
        public void CopyToArray()
        {
            int[]        array = new int[2];
            MyList <int> List  = new MyArrayList <int>();

            List.Add(51);
            List.Add(94);
            List.CopyTo(array, 0);
            Assert.AreEqual(array[0], 51);
            Assert.AreEqual(array[1], 94);
        }
Beispiel #3
0
        public void Should_CopyTo_Check_Null()
        {
            //arrange
            var list = new MyArrayList(new object[] { 1, 2, 3, 4, 5 });

            //act
            Action act = () => list.CopyTo(null, 0);

            //assert
            act.ShouldThrow <ArgumentNullException>();
        }
Beispiel #4
0
        public void CopyToTest()
        {
            list.Add(7);
            list.Add(9);

            int[] array = new int[2];

            list.CopyTo(array, 0);

            Assert.AreEqual(list.Count, array.Length);
            Assert.AreEqual(9, array[1]);
        }
        public void CopyTo_CopyGenericArrayWithBiggerCapacityThanLowerBound_ThrowsArgumentException()
        {
            //arrenge
            MyArrayList <int> arrayList = new MyArrayList <int>(-1, 3);
            var array = new int[] { 1, 1 };

            //act
            Action action = () => { arrayList.CopyTo(array); };

            //assert
            Assert.Throws <ArgumentException>(action);
        }
        public void CopyTo_CopyMyArrayListWithSmallerCapacity_ThrowsArgumentException()
        {
            //arrenge
            MyArrayList <int> array = new MyArrayList <int>(new int[2] {
                1, 1
            });
            MyArrayList <int> newArray = new MyArrayList <int>(0, 3);

            //act
            Action action = () => { newArray.CopyTo(array); };

            //assert
            Assert.Throws <ArgumentException>(action);
        }
        public void CopyTo_CopyMyArrayList_NewArrayEqualToCopied()
        {
            //arrenge
            MyArrayList <int> array = new MyArrayList <int>(new int[3] {
                1, 1, 1
            });
            MyArrayList <int> newArray = new MyArrayList <int>(0, 3);

            //act
            array.CopyTo(newArray);

            //assert
            Assert.Equal(array, newArray);
        }
Beispiel #8
0
        public void Should_CopyTo()
        {
            //arrange
            var result = new int[5];
            var list   = new MyArrayList(new object[] { 1, 2, 3, 4, 5 });

            //act
            list.CopyTo(result, 0);

            //assert
            for (int i = 0; i < result.Length; i++)
            {
                result[i].ShouldBeEquivalentTo(list[i]);
            }
        }
        public void CopyTo_CopyGenericArray_NewArrayEqualToCopied()
        {
            //arrenge
            MyArrayList <int> array = new MyArrayList <int>(new int[3] {
                1, 1, 1
            });

            int[] newArray = new int[3];

            //act
            array.CopyTo(newArray);

            //assert
            Assert.Equal(array, newArray);
        }
        public void InvalidCopyToArray()
        {
            int[]        array = new int[2];
            MyList <int> List  = new MyArrayList <int>();

            List.Add(51);
            List.Add(94);
            try
            {
                List.CopyTo(array, 2);
            }
            catch (IndexOutOfRangeException e)
            {
                StringAssert.Contains(e.Message, "Индекс вне диапазона.");
            }
        }
Beispiel #11
0
        public void Should_copy_to()
        {
            var arrayListTarget = new MyArrayList()
            {
                0, 1, 2, 3, 4
            };

            var arraySource = new object[6]
            {
                5, "test", "test1", 10, 0, 2
            };

            arrayListTarget.CopyTo(arraySource, 2);

            var expected = new MyArrayList()
            {
                5, "test", 0, 1, 2, 3, 4
            };

            Assert.Equal(expected, arrayListTarget);
        }
 public void InvalidCopyToArray()
 {
     int[] array = new int[2];
     MyList<int> List = new MyArrayList<int>();
     List.Add(51);
     List.Add(94);
     try
     {
         List.CopyTo(array, 2);
     }
     catch (IndexOutOfRangeException e)
     {
         StringAssert.Contains(e.Message, "Индекс вне диапазона.");
     }
 }
 public void CopyToArray()
 {
     int[] array = new int[2];
     MyList<int> List = new MyArrayList<int>();
     List.Add(51);
     List.Add(94);
     List.CopyTo(array, 0);
     Assert.AreEqual(array[0], 51);
     Assert.AreEqual(array[1], 94);
 }
Beispiel #14
0
        public void Should_throw_ArgumentOutOfRangeException_when_calling_copy_to_with_null_array()
        {
            var arrayList = new MyArrayList();

            Assert.Throws <ArgumentOutOfRangeException>(() => arrayList.CopyTo(null, 0));
        }
Beispiel #15
0
        public void Should_throw_ArgumentOutOfRangeException_when_calling_copy_to_with_negative_index()
        {
            var arrayList = new MyArrayList();

            Assert.Throws <ArgumentOutOfRangeException>(() => arrayList.CopyTo(new object[0], -1));
        }