Exemplo n.º 1
0
        public void Constructor_Capacity_OK_WithComparer()
        {
            var comparer = new MockComparer <decimal>();
            var sa       = new SparseArray <decimal>(3, comparer);

            Assert.IsFalse(sa.IsReadOnly, "Incorrect readonly value.");
            Assert.AreEqual(3, sa.Capacity, "Incorrect capacity.");
            Assert.AreEqual(3, sa.Count, "Incorrect count.");
            Assert.AreEqual(0, sa.Sparsity, "Incorrect sparsity.");
            Assert.AreEqual(0, sa.SparsityPercent, "Incorrect sparsity percent.");
            Assert.AreSame(comparer, sa.Comparer, "Incorrect explicit comparer.");
            Assert.IsTrue(sa.ToArray().SequenceEqual(new[] { 0M, 0M, 0M }), "Unequal elements in sparse array");
        }
Exemplo n.º 2
0
        public void Constructor_Enumerable_OK_WithComparer()
        {
            var comparer = new MockComparer <decimal>();
            var sa       = new SparseArray <decimal>(new List <decimal> {
                0M, 1M, 0M, 2M
            }, comparer);

            Assert.IsFalse(sa.IsReadOnly, "Incorrect readonly value.");
            Assert.AreEqual(4, sa.Capacity, "Incorrect capacity.");
            Assert.AreEqual(4, sa.Count, "Incorrect count.");
            Assert.AreEqual(2, sa.Sparsity, "Incorrect sparsity.");
            Assert.AreEqual(0.5M, sa.SparsityPercent, "Incorrect sparsity percent.");
            Assert.IsTrue(sa.Keys.SequenceEqual(new List <int> {
                1, 3
            }), "Incorrect keys.");
            Assert.AreSame(comparer, sa.Comparer, "Incorrect explicit comparer.");
            Assert.IsTrue(sa.ToArray().SequenceEqual(new[] { 0M, 1M, 0M, 2M }), "Unequal elements in sparse array");
        }