private void Fill(ConditionalWeakTableWrapper <object, object> dictionary) { foreach (SmallObject key in keys) { dictionary.Add(key, "value"); } }
public void A_TestBasicOps() { ConditionalWeakTableWrapper <object, object> weakDictionary = TestWeakDictionaryBehavior.CreateDictionary();// new SupportClass.TjWeakHashTable(); Hashtable realHashTable = new Hashtable(); SmallObject[] so = new SmallObject[100]; for (int i = 0; i < 20000; i++) { SmallObject key = new SmallObject(i); SmallObject value = key; so[i / 200] = key; realHashTable.Add(key, value); weakDictionary.Add(key, value); } Assert.AreEqual(weakDictionary.Count, realHashTable.Count); var keys = realHashTable.Keys; foreach (SmallObject key in keys) { Assert.AreEqual(((SmallObject)realHashTable[key]).i, ((SmallObject)weakDictionary[key]).i); Assert.IsTrue(realHashTable[key].Equals(weakDictionary[key])); } var values1 = weakDictionary.Values; var values2 = realHashTable.Values; Assert.AreEqual(values1.Length, values2.Count); realHashTable.Remove(new SmallObject(10000)); weakDictionary.Remove(new SmallObject(10000)); Assert.AreEqual(weakDictionary.Count, 20000); Assert.AreEqual(realHashTable.Count, 20000); for (int i = 0; i < so.Length; i++) { realHashTable.Remove(so[i]); weakDictionary.Remove(so[i]); Assert.AreEqual(weakDictionary.Count, 20000 - i - 1); Assert.AreEqual(realHashTable.Count, 20000 - i - 1); } //After removals, compare the collections again. var keys2 = realHashTable.Keys; foreach (SmallObject o in keys2) { Assert.AreEqual(((SmallObject)realHashTable[o]).i, ((SmallObject)weakDictionary[o]).i); Assert.IsTrue(realHashTable[o].Equals(weakDictionary[o])); } }
public void Setup() { dictionary = TestWeakDictionaryBehavior.CreateDictionary(); }