public void Dictionary_Generic_RemoveKey_ValidKeyNotContainedInDictionary(int count) { SegmentedDictionary <TKey, TValue> dictionary = (SegmentedDictionary <TKey, TValue>)GenericIDictionaryFactory(count); TValue value; TKey missingKey = GetNewKey(dictionary); Assert.False(dictionary.Remove(missingKey, out value)); Assert.Equal(count, dictionary.Count); Assert.Equal(default(TValue), value); }
public void Dictionary_Generic_RemoveKey_DefaultKeyContainedInDictionary(int count) { if (DefaultValueAllowed) { SegmentedDictionary <TKey, TValue> dictionary = (SegmentedDictionary <TKey, TValue>)(GenericIDictionaryFactory(count)); TKey missingKey = default(TKey); TValue value; dictionary.TryAdd(missingKey, default(TValue)); Assert.True(dictionary.Remove(missingKey, out value)); } }
public void Dictionary_Generic_Remove_RemoveCurrentEnumerationContinues() { SegmentedDictionary <TKey, TValue> dict = (SegmentedDictionary <TKey, TValue>)GenericIDictionaryFactory(3); using (var enumerator = dict.GetEnumerator()) { enumerator.MoveNext(); enumerator.MoveNext(); dict.Remove(enumerator.Current.Key); Assert.True(enumerator.MoveNext()); Assert.False(enumerator.MoveNext()); } }
public void Dictionary_Generic_RemoveKey_ValidKeyContainedInDictionary(int count) { SegmentedDictionary <TKey, TValue> dictionary = (SegmentedDictionary <TKey, TValue>)GenericIDictionaryFactory(count); TKey missingKey = GetNewKey(dictionary); TValue outValue; TValue inValue = CreateTValue(count); dictionary.Add(missingKey, inValue); Assert.True(dictionary.Remove(missingKey, out outValue)); Assert.Equal(count, dictionary.Count); Assert.Equal(inValue, outValue); Assert.False(dictionary.TryGetValue(missingKey, out outValue)); }
public void Dictionary_Generic_RemoveKey_DefaultKeyNotContainedInDictionary(int count) { SegmentedDictionary <TKey, TValue> dictionary = (SegmentedDictionary <TKey, TValue>)GenericIDictionaryFactory(count); TValue outValue; if (DefaultValueAllowed) { TKey missingKey = default(TKey); while (dictionary.ContainsKey(missingKey)) { dictionary.Remove(missingKey); } Assert.False(dictionary.Remove(missingKey, out outValue)); Assert.Equal(default(TValue), outValue); } else { TValue initValue = CreateTValue(count); outValue = initValue; Assert.Throws <ArgumentNullException>(() => dictionary.Remove(default(TKey), out outValue)); Assert.Equal(initValue, outValue); } }
public void Dictionary_Generic_Remove_RemoveLastEnumerationFinishes() { SegmentedDictionary <TKey, TValue> dict = (SegmentedDictionary <TKey, TValue>)GenericIDictionaryFactory(3); TKey key = default; using (var enumerator = dict.GetEnumerator()) { while (enumerator.MoveNext()) { key = enumerator.Current.Key; } } using (var enumerator = dict.GetEnumerator()) { enumerator.MoveNext(); enumerator.MoveNext(); dict.Remove(key); Assert.False(enumerator.MoveNext()); } }