Esempio n. 1
0
        public void GettingNonExistingReturnsNull()
        {
            var array = new SparseArray<string>();

            Assert.IsNull(array.GetValue(10000));

            // We shouldn't have allocated items.

            Assert.AreEqual("Values=20", array.ToString());
        }
Esempio n. 2
0
        public void GetNegativeShouldNotFail()
        {
            var array = new SparseArray<string>();

            Assert.IsNull(array.GetValue(-10));

            // We shouldn't have allocated items.

            Assert.AreEqual("Values=20", array.ToString());
        }
Esempio n. 3
0
        public void InsertAtHighIndex()
        {
            var array = new SparseArray<string>();
            int offset = 1000000;

            // Insert some items.

            for (int i = 0; i < 1000; i++)
            {
                array.SetValue(offset + i, i.ToString());
            }

            // Verify that we can get them back.

            for (int i = 0; i < 1000; i++)
            {
                Assert.AreEqual(i.ToString(), array.GetValue(offset + i));
            }

            // Verify that we've switched to chunks.

            Assert.AreEqual("Chunks=33, ChunkCapacity=37", array.ToString());
        }
Esempio n. 4
0
        public void InsertWithSpaces()
        {
            var array = new SparseArray<string>();

            for (int i = 0; i < 1000; i++)
            {
                if (i % 2 == 0)
                    array.SetValue(i, i.ToString());
            }

            for (int i = 0; i < 1000; i++)
            {
                if (i % 2 == 0)
                {
                    Assert.AreEqual(i.ToString(), array.GetValue(i));
                }
                else
                {
                    Assert.IsNull(array.GetValue(i));
                }
            }

            // Verify that we didn't switch to chunks even though we have
            // sparsely set items.

            Assert.AreEqual("Values=1280", array.ToString());
        }
Esempio n. 5
0
        public void SimpleInserts()
        {
            var array = new SparseArray<string>();

            // Insert some items.

            for (int i = 0; i < 1000; i++)
            {
                array.SetValue(i, i.ToString());
            }

            // Verify that we can get them back.

            for (int i = 0; i < 1000; i++)
            {
                Assert.AreEqual(i.ToString(), array.GetValue(i));
            }

            // Verify that we didn't switch to chunks.

            Assert.AreEqual("Values=1280", array.ToString());
        }
 public T this[int id]
 {
     get { return(byId.GetValue(id) as T); }
 }