public void TestDeleteRemovesElement() { var collection = new RandomAccessDictionary<string, int>(10000, new Random()); collection.Put("key", 100); collection.Delete("key"); Assert.IsFalse(collection._data.ContainsKey("key")); }
public void TestGetRandomUsesRandomIndex() { var mockRandom = new Mock<Random>(); var collection = new RandomAccessDictionary<string, int>(10000, mockRandom.Object); mockRandom.Setup((random) => random.Next(It.IsAny<int>())).Returns(0); collection.Put("item1", 0); collection.Put("item2", 1); collection.Put("item3", 2); Assert.AreEqual(0, collection.GetRandom()); Assert.AreEqual(1, collection.GetRandom()); Assert.AreEqual(2, collection.GetRandom()); Assert.AreEqual(0, collection.GetRandom()); Assert.AreEqual(1, collection.GetRandom()); Assert.AreEqual(2, collection.GetRandom()); collection.Delete("item1"); Assert.AreEqual(1, collection.GetRandom()); Assert.AreEqual(1, collection.GetRandom()); Assert.AreEqual(2, collection.GetRandom()); Assert.AreEqual(1, collection.GetRandom()); collection.Delete("item2"); Assert.AreEqual(2, collection.GetRandom()); Assert.AreEqual(2, collection.GetRandom()); Assert.AreEqual(2, collection.GetRandom()); Assert.AreEqual(2, collection.GetRandom()); }
private static RandomAccessDictionary<string, int> CreateTestCollection() { var collection = new RandomAccessDictionary<string, int>(10000, new Random()); for (int i = 0; i < 100000; i++) { collection.Put(i.ToString(), i); } return collection; }
public void TestGetReturnsElement() { var collection = new RandomAccessDictionary<string, int>(10000, new Random()); var key = "sample_key"; var item = 12345; collection.Put(key, item); Assert.AreEqual(item, collection.Get(key)); }
public void TestGetMissingKeyThrowsException() { var collection = new RandomAccessDictionary<string, int>(10000, new Random()); collection.Get("missing_key"); }
public void TestDeleteReturnsTrueOnRemove() { var collection = new RandomAccessDictionary<string, int>(10000, new Random()); collection.Put("key", 100); Assert.IsTrue(collection.Delete("key")); }
public void TestDeleteReturnsFalseIfNothingRemoved() { var collection = new RandomAccessDictionary<string, int>(10000, new Random()); Assert.IsFalse(collection.Delete("missing_key")); }
public void TestStartCapacityMustBe_10000_OrMore() { var collection = new RandomAccessDictionary<string, int>(100, new Random()); }
public void TestPutThrowsArgumentExceptionForDuplicateKeys() { var collection = new RandomAccessDictionary<string, int>(10000, new Random()); collection.Put("key", 10); collection.Put("key", 123); }