public void CorrectKeysWithInsertsWithSpaces() { var array = new SparseArray<string>(); for (int i = 0; i < 1000; i++) { if (i % 2 == 0) array.SetValue(i, i.ToString()); } int offset = 0; foreach (int key in array.GetKeys()) { Assert.AreEqual(offset, key); offset += 2; } // Verify that we didn't switch to chunks even though we have // sparsely set items. Assert.AreEqual("Values=1280", array.ToString()); }
public void VerifyKeysInOrderFromReverseInserts() { var array = new SparseArray<string>(); for (int i = 1000; i > 0; i--) { array.SetValue(i, ""); } int offset = 1; foreach (int key in array.GetKeys()) { Assert.AreEqual(offset++, key); } // Verify the allocations. Assert.AreEqual("Chunks=32, ChunkCapacity=37", array.ToString()); }
public void VerifyKeysInOrderFromRandomInserts() { var array = new SparseArray<string>(); var random = new Random(); for (int i = 0; i < 1000; i++) { array.SetValue(random.Next(), ""); } int lastKey = int.MinValue; foreach (int key in array.GetKeys()) { Assert.Greater(key, lastKey); lastKey = key; } }