public void testVersusHashMap() { FastByIDMap <String> actual = new FastByIDMap <String>(); IDictionary <long, string> expected = new Dictionary <long, string>(1000000); var r = RandomUtils.getRandom(); for (int i = 0; i < 1000000; i++) { double d = r.nextDouble(); long key = (long)r.nextInt(100); if (d < 0.4) { Assert.AreEqual(expected.ContainsKey(key)?expected[key]:null, actual.Get(key)); } else { if (d < 0.7) { var expectedOldVal = expected.ContainsKey(key) ? expected[key] : null; expected[key] = "bang"; Assert.AreEqual(expectedOldVal, actual.Put(key, "bang")); } else { var expectedOldVal = expected.ContainsKey(key) ? expected[key] : null; expected.Remove(key); Assert.AreEqual(expectedOldVal, actual.Remove(key)); } Assert.AreEqual(expected.Count, actual.Count()); Assert.AreEqual(expected.Count == 0, actual.IsEmpty()); } } }
public void testRehash() { FastByIDMap <String> map = buildTestFastMap(); map.Remove(500000L); map.Rehash(); Assert.IsNull(map.Get(500000L)); Assert.AreEqual("bang", map.Get(47L)); }
public void testRemove() { FastByIDMap <long?> map = new FastByIDMap <long?>(); map.Put(500000L, 2L); map.Remove(500000L); Assert.AreEqual(0, map.Count()); Assert.True(map.IsEmpty()); Assert.IsNull(map.Get(500000L)); }
public void testSizeEmpty() { FastByIDMap <long> map = new FastByIDMap <long>(); Assert.AreEqual(0, map.Count()); Assert.True(map.IsEmpty()); map.Put(500000L, 2L); Assert.AreEqual(1, map.Count()); Assert.False(map.IsEmpty()); map.Remove(500000L); Assert.AreEqual(0, map.Count()); Assert.True(map.IsEmpty()); }