Exemple #1
0
        public void SparseArrayCopyToTest()
        {
            Int32[] result = new Int32[this.values.Length * 2];

            // zero start index
            SparseArray <Int32> array = new SparseArray <Int32>(this.values);

            array.CopyTo(result, 0);

            for (Int32 index = 0; index < array.Count; index++)
            {
                array[index].ShouldBe(result[index]);
            }

            // greater start index
            array.CopyTo(result, this.values.Length);

            for (Int32 index = 0; index < array.Count; index++)
            {
                array[index].ShouldBe(result[this.values.Length + index]);
            }

            // exceptions
            Should.Throw <ArgumentNullException>(() => array.CopyTo(null, 0));
            Should.Throw <ArgumentOutOfRangeException>(() => array.CopyTo(result, -1));
            Should.Throw <ArgumentException>(() => array.CopyTo(result, this.values.Length * 2));
        }
        public void SparseArrayCopyToTest()
        {
            Int32[] result = new Int32[100];

            // zero start index

            SparseArray <Int32> array = new SparseArray <Int32>(_values);

            array.CopyTo(result, 0);

            for (Int32 i = 0; i < array.Count; i++)
            {
                Assert.AreEqual(result[i], array[i]);
            }


            // greater start index

            array.CopyTo(result, 50);

            for (Int32 i = 50; i < array.Count; i++)
            {
                Assert.AreEqual(result[50 + i], array[i]);
            }


            // exceptions

            Assert.Throws <ArgumentNullException>(() => array.CopyTo(null, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() => array.CopyTo(result, -1));
            Assert.Throws <ArgumentException>(() => array.CopyTo(result, 100));
        }
Exemple #3
0
        public void CopyToTest()
        {
            var a = new SparseArray <bool> {
                [5] = true, [90] = false
            };
            var arr = new bool[2];

            a.CopyTo(arr, 0);
            Assert.That(arr, Is.EquivalentTo(new[] { true, false }));
            arr = new bool[3];
            a.CopyTo(arr, 1);
            Assert.That(arr, Is.EquivalentTo(new[] { false, true, false }));
        }
Exemple #4
0
 public void CopyToTest()
 {
     int[] arr = new int[_array.Count + 2];
     _array.CopyTo(arr, 2);
     Assert.Equal(_array[0], arr[2]);
     Assert.Equal(_array[5], arr[7]);
 }
Exemple #5
0
        public void CopyTo_NullArray()
        {
            var sa = new SparseArray <decimal>(2, new Dictionary <int, decimal>()
            {
                { 0, 1M }, { 1, 2M }
            });

            Assert.AreEqual(2, sa.Capacity, "Incorrect capacity.");
            Assert.AreEqual(2, sa.Count, "Incorrect count.");
            Assert.AreEqual(2, sa.Sparsity, "Incorrect sparsity.");
            Assert.AreEqual(1.0M, sa.SparsityPercent, "Incorrect sparsity percent.");
            Assert.IsTrue(sa.Keys.SequenceEqual(new List <int> {
                0, 1
            }), "Incorrect keys.");
            Assert.IsTrue(sa.ToArray().SequenceEqual(new[] { 1M, 2M }), "Unequal elements in sparse array");
            Assert.ThrowsException <ArgumentNullException>(() => sa.CopyTo(null, 0));
        }
Exemple #6
0
        public void CopyTo_Array_CorrectSize_ArrayIndex_TooLarge()
        {
            var sa = new SparseArray <decimal>(2, new Dictionary <int, decimal>()
            {
                { 0, 1M }, { 1, 2M }
            });

            Assert.AreEqual(2, sa.Capacity, "Incorrect capacity.");
            Assert.AreEqual(2, sa.Count, "Incorrect count.");
            Assert.AreEqual(2, sa.Sparsity, "Incorrect sparsity.");
            Assert.AreEqual(1.0M, sa.SparsityPercent, "Incorrect sparsity percent.");
            Assert.IsTrue(sa.Keys.SequenceEqual(new List <int> {
                0, 1
            }), "Incorrect keys.");
            Assert.IsTrue(sa.ToArray().SequenceEqual(new[] { 1M, 2M }), "Unequal elements in sparse array");
            Assert.ThrowsException <InvalidOperationException>(() => sa.CopyTo(new decimal[2], 1));
        }
Exemple #7
0
        public void CopyTo_OK_Array_Larger_Offset()
        {
            var sa = new SparseArray <decimal>(2, new Dictionary <int, decimal>()
            {
                { 0, 1M }, { 1, 2M }
            });

            Assert.AreEqual(2, sa.Capacity, "Incorrect capacity.");
            Assert.AreEqual(2, sa.Count, "Incorrect count.");
            Assert.AreEqual(2, sa.Sparsity, "Incorrect sparsity.");
            Assert.AreEqual(1.0M, sa.SparsityPercent, "Incorrect sparsity percent.");
            Assert.IsTrue(sa.Keys.SequenceEqual(new List <int> {
                0, 1
            }), "Incorrect keys.");
            Assert.IsTrue(sa.ToArray().SequenceEqual(new[] { 1M, 2M }), "Unequal elements in sparse array");

            var ar = new decimal[4];

            sa.CopyTo(ar, 1);

            Assert.IsTrue(ar.SequenceEqual(new[] { decimal.Zero, 1M, 2M, decimal.Zero }), "Unequal elements in sparse array");
        }