示例#1
0
        public void InsertTest()
        {
            var a = new SparseArray <bool> {
                [5] = true, [90] = false
            };

            a.Insert(5, false);
            Assert.That(a[1], Is.False);
            Assert.That(a[5], Is.False);
            Assert.That(a.Count, Is.EqualTo(2));
            a.Insert(10, false);
            Assert.That(a[10], Is.False);
            Assert.That(a.Count, Is.EqualTo(3));
        }
示例#2
0
        public void InsertTest()
        {
            SparseArray <int> test = new SparseArray <int>();

            test.Insert(0, 1);
            test.Insert(0, 0);
            test.Insert(1, 5);

            Assert.Equal(3, test.Count);
            Assert.Equal(0, test[0]);
            Assert.Equal(5, test[1]);
            Assert.Equal(1, test[2]);

            Assert.Throws <ArgumentOutOfRangeException>(() => test.Insert(5, 2));
        }
示例#3
0
        public void Insert_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");

            sa.Insert(1, 3);

            Assert.AreEqual(2, sa.Capacity, "Incorrect capacity after insert.");
            Assert.AreEqual(2, sa.Count, "Incorrect count after insert.");
            Assert.AreEqual(2, sa.Sparsity, "Incorrect sparsity after insert.");
            Assert.AreEqual(1.0M, sa.SparsityPercent, "Incorrect sparsity percent after insert.");
            Assert.IsTrue(sa.Keys.SequenceEqual(new List <int> {
                0, 1
            }), "Incorrect keys after insert.");
            Assert.IsTrue(sa.ToArray().SequenceEqual(new[] { 1M, 3M }), "Unequal elements in sparse array after insert");
        }
示例#4
0
        public void SparseArrayInsertTest()
        {
            SparseArray <Int32> array = new SparseArray <Int32>(this.values);

            array.Insert(1, -1);
            array.Insert(3, -2);

            array.Length.ShouldBe(this.values.Length + 2);

            array[0].ShouldBe(0);
            array[1].ShouldBe(-1);
            array[2].ShouldBe(5);
            array[3].ShouldBe(-2);
            array[4].ShouldBe(10);
            array[5].ShouldBe(15);

            // exceptions
            Should.Throw <ArgumentOutOfRangeException>(() => array.Insert(-1, 1));
            Should.Throw <ArgumentOutOfRangeException>(() => array.Insert(array.Length, 1));
        }
        public void SparseArrayInsertTest()
        {
            SparseArray <Int32> array = new SparseArray <Int32>(_values);

            array.Insert(1, -1);
            array.Insert(3, 0);
            array.Insert(8, -2);

            Assert.AreEqual(_values.Length + 3, array.Length);

            Assert.AreEqual(-1, array[1]);
            Assert.AreEqual(1, array[2]);
            Assert.AreEqual(0, array[3]);
            Assert.AreEqual(0, array[4]);
            Assert.AreEqual(2, array[5]);


            // exceptions

            Assert.Throws <ArgumentOutOfRangeException>(() => array.Insert(-1, 1));
            Assert.Throws <ArgumentOutOfRangeException>(() => array.Insert(array.Length, 1));
        }