コード例 #1
0
        public void Clone_OK()
        {
            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 clone = (SparseArray <decimal>)sa.Clone();

            Assert.AreEqual(sa.IsReadOnly, clone.IsReadOnly, "Incorrect readonly value after Clone().");
            Assert.AreEqual(sa.Capacity, clone.Capacity, "Incorrect capacity after Clone().");
            Assert.AreEqual(sa.Count, clone.Count, "Incorrect count after Clone().");
            Assert.AreEqual(sa.Sparsity, clone.Sparsity, "Incorrect sparsity after Clone().");
            Assert.AreEqual(sa.SparsityPercent, clone.SparsityPercent, "Incorrect sparsity percent after Clone().");
            Assert.IsTrue(clone.Keys.SequenceEqual(sa.Keys), "Incorrect keys after Clone().");
            Assert.AreSame(sa.Comparer, clone.Comparer, "Incorrect explicit comparer after Clone().");
            Assert.IsTrue(clone.ToArray().SequenceEqual(sa.ToArray()), "Unequal elements in sparse array after Clone()");
        }