Exemple #1
0
        public void RemoveLeftElementTest()
        {
            var bijective = new Bijective <string, int>();

            try
            {
                bijective.RemoveLeftElement("A");
            }
            catch
            {
                Assert.Fail();
            }

            bijective["A"] = 10;
            bijective["B"] = 20;

            bijective.RemoveLeftElement("A");

            Assert.IsFalse(bijective.LeftElementExists("A"));
            Assert.IsFalse(bijective.RightElementExists(10));

            var allLeftElementsList = new List <string>(bijective.GetAllLeftElements());

            Assert.AreEqual(1, allLeftElementsList.Count);
            Assert.IsTrue(allLeftElementsList.Contains("B"));

            var allRightElementsList = new List <int>(bijective.GetAllRightElements());

            Assert.AreEqual(1, allRightElementsList.Count);
            Assert.IsTrue(allRightElementsList.Contains(20));

            Assert.IsTrue(bijective.CanAddBijection("A", 10));
            Assert.IsTrue(bijective.CanAddReverseBijection(10, "A"));

            Tuple <string, int> bijection;

            Assert.IsFalse(bijective.TryGetBijection("A", out bijection));
            Assert.IsNull(bijection);

            Tuple <int, string> reverseBijection;

            Assert.IsFalse(bijective.TryGetReverseBijection(10, out reverseBijection));
            Assert.IsNull(reverseBijection);

            var allBijectionsList = new List <Tuple <string, int> >(bijective.GetAllBijections());

            Assert.AreEqual(1, allBijectionsList.Count);
            Assert.AreEqual("B", allBijectionsList[0].Item1);
            Assert.AreEqual(20, allBijectionsList[0].Item2);

            var allReverseBijectionsList = new List <Tuple <int, string> >(bijective.GetAllReverseBijections());

            Assert.AreEqual(1, allReverseBijectionsList.Count);
            Assert.AreEqual(20, allReverseBijectionsList[0].Item1);
            Assert.AreEqual("B", allReverseBijectionsList[0].Item2);
        }