private void AssertOriginalAndReversedVersionsMatchExactly <TKey, TValue>(IBijectionDictionary <TKey, TValue> dictionary)
        {
            foreach (TKey key in dictionary.Keys)
            {
                TValue value       = dictionary[key];
                TKey   reversedKey = dictionary.Reverse[value];

                Assert.AreEqual(key, reversedKey, "Mismatch between original and reversed dictionaries for key " + key.ToString());
            }
        }
        public void TestGivenUniqueKeyValuePairsWhenAddedToTwoWayDictionaryThenCanBeAccessed()
        {
            int maxCount  = 10;
            int lastIndex = maxCount - 1;
            IBijectionDictionary <int, string> dict = GenerateNewTestDictionary(maxCount);

            Assert.AreEqual(maxCount, dict.Count);
            Assert.AreEqual(GetTestStringBasedOnIndex(0), dict[0]);
            Assert.AreEqual(GetTestStringBasedOnIndex(lastIndex), dict[lastIndex]);
        }
        public void TestGivenTwoWayDictionaryWhenGettingReverseOfReverseThenReverseOfReverseIsTheSameObjectAsOriginal()
        {
            int maxCount = 10;
            IBijectionDictionary <int, string> dict = GenerateNewTestDictionary(maxCount);

            Assert.AreEqual(maxCount, dict.Count);
            Assert.AreEqual(maxCount, dict.Reverse.Count);
            Assert.AreEqual(maxCount, dict.Reverse.Reverse.Count);

            Assert.AreSame(dict, dict.Reverse.Reverse);
        }
        public void TestGivenTwoWayDictionaryWhenAllItemsClearedThenReverseVersionIsAlsoEmpty()
        {
            int maxCount = 10;
            IBijectionDictionary <int, string> dict = GenerateNewTestDictionary(maxCount);

            Assert.AreEqual(maxCount, dict.Count, "GIVEN: Dictionary not setup correctly");
            Assert.AreEqual(maxCount, dict.Reverse.Count, "GIVEN: Dictionary not setup correctly");

            dict.Clear();

            Assert.AreEqual(0, dict.Count);
            Assert.AreEqual(0, dict.Reverse.Count);
        }
        public void TestGivenTwoWayDictionaryWhenRemoveItemsFromReversedVersionThenItemsAlsoRemovedFromOriginalVersion()
        {
            int maxCount = 10;
            IBijectionDictionary <int, string> dict = GenerateNewTestDictionary(maxCount);

            int    indexToRemove = 5;
            string valueToRemove = GetTestStringBasedOnIndex(indexToRemove);

            Assert.AreEqual(valueToRemove, dict[indexToRemove], "GIVEN: Dictionary is not setup correctly");
            Assert.AreEqual(indexToRemove, dict.Reverse[valueToRemove], "GIVEN: Dictionary is not setup correctly");

            dict.Reverse.Remove(valueToRemove);

            Assert.IsFalse(dict.ContainsKey(indexToRemove));
            Assert.IsFalse(dict.Reverse.ContainsKey(valueToRemove));
            Assert.AreEqual(dict.Count, dict.Reverse.Count);
        }
 private BijectionDictionaryImpl(IDictionary <TKey, TValue> dictionary, BijectionDictionaryImpl <TValue, TKey> reverseDictionary)
 {
     _delegate        = dictionary;
     _reverse         = reverseDictionary;
     _reverseDelegate = reverseDictionary._delegate;
 }