public void NonGenericNoExceptionOnKeyOrValueOfWrongType() { IReversibleDictionary rdict = (IReversibleDictionary)this.createAndInit(); Assert.DoesNotThrow(() => rdict.Remove(new CustomPrivateType())); Assert.DoesNotThrow(() => { bool result = rdict.Contains(new CustomPrivateType()); }); }
public void NonGenericCopyTo() { IReversibleDictionary <TKey, TValue> rdict = this.createAndInit(); Array copyHereUntyped = new KeyValuePair <TKey, TValue> [rdict.Count]; ((IReversibleDictionary)rdict).CopyTo(copyHereUntyped, 0); Assert.That(copyHereUntyped, Is.EqualTo(rdict)); }
private static void CheckRemovedNonGeneric( IReversibleDictionary rdict, DictionaryEntry entry, int initialCount) { Assert.IsFalse(rdict.Contains(entry.Key)); Assert.IsFalse(rdict.Reverse.Contains(entry.Value)); Assert.AreEqual(rdict.Reverse.Count, rdict.Count); Assert.AreEqual(initialCount, rdict.Count); }
private static void CheckAddedGeneric( IReversibleDictionary <TKey, TValue> rdict, KeyValuePair <TKey, TValue> pair, int initialCount) { DictionaryAssert.Contains(rdict, pair); DictionaryAssert.Contains(rdict.Reverse, new KeyValuePair <TValue, TKey>(pair.Value, pair.Key)); Assert.AreEqual(rdict.Reverse.Count, rdict.Count); Assert.AreEqual(initialCount + 1, rdict.Count); }
private static void EnsureNewValuesInAndOldValuesOut(IReversibleDictionary <TKey, TValue> dict, TKey key, TValue val, TKey oldKey, TValue oldVal) { DictionaryAssert.Contains(dict, new KeyValuePair <TKey, TValue>(key, val)); DictionaryAssert.Contains(dict.Reverse, new KeyValuePair <TValue, TKey>(val, key)); DictionaryAssert.DoesNotContainKey(dict, oldKey); DictionaryAssert.DoesNotContainKey(dict.Reverse, oldVal); DictionaryAssert.DoesNotContain(dict, new KeyValuePair <TKey, TValue>(oldKey, val)); DictionaryAssert.DoesNotContain(dict.Reverse, new KeyValuePair <TValue, TKey>(val, oldKey)); }
private static void CheckRemovedGeneric( IReversibleDictionary <TKey, TValue> rdict, KeyValuePair <TKey, TValue> pair, int initialCount) { DictionaryAssert.DoesNotContainKey(rdict, pair.Key); DictionaryAssert.DoesNotContainKey(rdict.Reverse, pair.Value); Assert.AreEqual(rdict.Reverse.Count, rdict.Count); Assert.AreEqual(initialCount, rdict.Count); Assert.IsFalse(rdict.Remove(pair)); }
public void ExceptionOnAddPresentKeyOrValue() { IReversibleDictionary <TKey, TValue> rdict = this.createAndInit(); foreach (var pair in rdict.Take(2).ToList()) { var reversePair = new KeyValuePair <TValue, TKey>(pair.Value, pair.Key); DictionaryAssert.ThrowsOnAdd(rdict, pair); DictionaryAssert.ThrowsOnAdd(rdict.Reverse, reversePair); } }
public void ExceptionOnGetAbsentKeyOrValue() { IReversibleDictionary <TKey, TValue> rdict = this.createAndInit(); foreach (var pair in this.TestData.Take(2)) { var reversePair = new KeyValuePair <TValue, TKey>(pair.Value, pair.Key); DictionaryAssert.ThrowsOnGetItem(rdict, pair.Key); DictionaryAssert.ThrowsOnGetItem(rdict.Reverse, reversePair.Key); } }
public void Clear() { IReversibleDictionary <TKey, TValue> rdict = this.createAndInit(); Assert.IsNotEmpty(rdict); rdict.Clear(); Assert.AreEqual(0, rdict.Count); Assert.AreEqual(0, rdict.Reverse.Count); Assert.IsEmpty(rdict); Assert.DoesNotThrow(rdict.Clear); }
public void Indexer() { IReversibleDictionary <TKey, TValue> rdict = this.createAndInit(); KeyValuePair <TKey, TValue> pair = this.TestData.First(); KeyValuePair <TKey, TValue> oldpair = this.TestData.Skip(1).First(); TKey key1 = pair.Key, key2 = oldpair.Key; TValue val1 = pair.Value, val2 = oldpair.Value; // key1, key2 and val1, val2 are not in the dictionary rdict[key1] = val1; EnsureNewValuesInAndOldValuesOut(rdict, key1, val1, key2, val2); // (key1, val1) pair is in the dictionary rdict[key1] = val2; EnsureNewValuesInAndOldValuesOut(rdict, key1, val2, key2, val1); // (key1, val2) pair is in the dictionary rdict.Reverse[val2] = key2; EnsureNewValuesInAndOldValuesOut(rdict, key2, val2, key1, val1); }
/// <summary> /// Initializes a new instance of <see cref="ReversibleDictionary{TKey, TValue}"/> /// </summary> public ReversibleDictionary() { ReversedDictionary = new ReversedDictionaryImplementation(this); }