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()); }
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()); }
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()); }
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()); }
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); } }