コード例 #1
0
        public static void testCopyTo <C>(C c) where C : IList <int>
        {
            c.Clear();
            addAll(ref c, 1, 2, 3, 4, 5);
            // ReSharper disable once AssignNullToNotNullAttribute
            Assert.Throws <ArgumentNullException>(() => c.CopyTo(null, 0));

            var arr = new int[5];

            Assert.Throws <ArgumentOutOfRangeException>(() => c.CopyTo(arr, -1));
            Assert.Throws <ArgumentException>(
                () => c.CopyTo(arr, 1),
                "it should fail if target array is too small"
                );

            c.CopyTo(arr, 0);
            arr.shouldEqual(new [] { 1, 2, 3, 4, 5 });

            arr = F.arrayFill(7, _ => 0);
            c.CopyTo(arr, 2);
            arr.shouldEqual(new[] { 0, 0, 1, 2, 3, 4, 5 });

            arr = F.arrayFill(7, i => - (i + 1));
            c.CopyTo(arr, 1);
            arr.shouldEqual(new[] { -1, 1, 2, 3, 4, 5, -7 });

            arr = F.arrayFill(7, _ => 0);
            IListDefaultImpls.copyTo(c, arr, targetStartIndex: 1, srcCopyFrom: 1);
            arr.shouldEqual(new [] { 0, 2, 3, 4, 5, 0, 0 });

            arr = F.arrayFill(7, _ => 0);
            IListDefaultImpls.copyTo(c, arr, targetStartIndex: 1, srcCopyFrom: 2, srcCopyCount: 3);
            arr.shouldEqual(new [] { 0, 3, 4, 5, 0, 0, 0 });

            Assert.Throws <ArgumentOutOfRangeException>(
                () => IListDefaultImpls.copyTo(c, arr, 0, srcCopyFrom: -1),
                "it should fail if srcCopyFrom is negative"
                );
            Assert.Throws <ArgumentOutOfRangeException>(
                () => IListDefaultImpls.copyTo(c, arr, 0, srcCopyFrom: 5),
                "it should fail if srcCopyFrom is more than length"
                );
            Assert.Throws <ArgumentOutOfRangeException>(
                () => IListDefaultImpls.copyTo(c, arr, 0, srcCopyCount: 6),
                "it should fail if we try to copy more items than there are in collection"
                );

            arr = F.arrayFill(2, _ => 0);
            Assert.Throws <ArgumentException>(
                () => IListDefaultImpls.copyTo(c, arr, 0, srcCopyCount: 3),
                "it should fail if we try to copy into smaller array"
                );
        }
コード例 #2
0
ファイル: SList4.cs プロジェクト: Hengle/Tetris-1
 public void Insert(int index, A item) => IListDefaultImpls.insert(ref this, index, item);
コード例 #3
0
ファイル: SList4.cs プロジェクト: Hengle/Tetris-1
 public void CopyTo(A[] array, int arrayIndex) => IListDefaultImpls.copyTo(this, array, arrayIndex);
コード例 #4
0
ファイル: SList4.cs プロジェクト: Hengle/Tetris-1
 public bool Contains(A item) => IListDefaultImpls.contains(this, item);
コード例 #5
0
ファイル: SList4.cs プロジェクト: Hengle/Tetris-1
 public int IndexOf(A item) => IListDefaultImpls.indexOf(this, item);
コード例 #6
0
ファイル: SList4.cs プロジェクト: Hengle/Tetris-1
 public bool Remove(A item) => IListDefaultImpls.remove(ref this, item);