コード例 #1
0
        public void Remove_ValueDoesNotExist()
        {
            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.AreEqual(-1, sa.IndexOf(3M), "Incorrect index for non-existent value.");

            Assert.IsFalse(sa.Remove(3M), "Incorrect return result for removing existing value.");

            Assert.AreEqual(2, sa.Capacity, "Incorrect capacity after Remove(...).");
            Assert.AreEqual(2, sa.Count, "Incorrect count after Remove(...).");
            Assert.AreEqual(2, sa.Sparsity, "Incorrect sparsity after Remove(...).");
            Assert.AreEqual(1.0M, sa.SparsityPercent, "Incorrect sparsity percent after Remove(...).");
            Assert.IsTrue(sa.Keys.SequenceEqual(new List <int> {
                0, 1
            }), "Incorrect keys after Remove(...).");
            Assert.IsTrue(sa.ToArray().SequenceEqual(new[] { 1M, 2M }), "Unequal elements in sparse array after Remove(...)");
            Assert.AreEqual(-1, sa.IndexOf(3M), "Incorrect index for non-existent value after Remove(...).");
        }
コード例 #2
0
ファイル: SparseArrayTest.cs プロジェクト: gisdevelope/aegis
        public void SparseArrayIndexOfTest()
        {
            SparseArray <Int32> array = new SparseArray <Int32>(this.values);

            array.IndexOf(0).ShouldBe(0);
            array.IndexOf(5).ShouldBe(1);
            array.IndexOf(100).ShouldBe(20);
            array.IndexOf(-1).ShouldBe(-1);
        }
コード例 #3
0
        public void SparseArrayIndexOfTest()
        {
            SparseArray <Int32> array = new SparseArray <Int32>(_values);

            Assert.AreEqual(0, array.IndexOf(0));
            Assert.AreEqual(-1, array.IndexOf(-1));
            Assert.AreEqual(1, array.IndexOf(1));
            Assert.AreEqual(3, array.IndexOf(2));
        }
コード例 #4
0
        public void IndexOfTest()
        {
            var a = new SparseArray <int> {
                [5] = -5, [90] = -90
            };

            Assert.That(a.IndexOf(-5), Is.EqualTo(5));
            Assert.That(a.IndexOf(-90), Is.EqualTo(90));
            Assert.That(a.IndexOf(0), Is.EqualTo(-1));
        }
コード例 #5
0
        public void IndexOfTest()
        {
            SparseArray <int> test = new SparseArray <int>();

            test.Add(100);
            test.Add(200);

            Assert.Equal(1, test.IndexOf(200));
            Assert.Equal(-1, test.IndexOf(300));
        }
コード例 #6
0
        public void RemoveTest()
        {
            int  count     = _array.Count;
            bool isRemoved = _array.Remove(80);

            Assert.True(isRemoved);
            Assert.Equal(count - 1, _array.Count);
            Assert.DoesNotContain(80, _array);
            Assert.Equal(-1, _array.IndexOf(80));

            Assert.False(_array.Remove(100));
        }
コード例 #7
0
        public void IndexOf_ValueExists()
        {
            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.AreEqual(1, sa.IndexOf(2M), "Incorrect index for existing value.");
        }