public void TryGetBijectionTest() { var bijective = new Bijective <string, int>(); Tuple <string, int> bijection; Assert.IsFalse(bijective.TryGetBijection("A", out bijection)); Assert.IsNull(bijection); bijective["A"] = 10; Assert.IsTrue(bijective.TryGetBijection("A", out bijection)); Assert.IsNotNull(bijection); Assert.AreEqual("A", bijection.Item1); Assert.AreEqual(10, bijection.Item2); }
public void RemoveRightElementTest() { var bijective = new Bijective <string, int>(); try { bijective.RemoveRightElement(10); } catch { Assert.Fail(); } bijective["A"] = 10; bijective["B"] = 20; bijective.RemoveRightElement(10); 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); }
public void TryAddReverseBijectionTest() { var bijective = new Bijective <string, int>(); bijective[10] = "A"; Assert.IsFalse(bijective.TryAddReverseBijection(10, "A")); Assert.IsFalse(bijective.TryAddReverseBijection(10, "B")); Assert.IsFalse(bijective.TryAddReverseBijection(20, "A")); Assert.IsTrue(bijective.TryAddReverseBijection(20, "B")); Assert.IsTrue(bijective.LeftElementExists("B")); Assert.IsTrue(bijective.RightElementExists(20)); var allLeftElementsList = new List <string>(bijective.GetAllLeftElements()); Assert.AreEqual(2, allLeftElementsList.Count); Assert.IsTrue(allLeftElementsList.Contains("B")); var allRightElementsList = new List <int>(bijective.GetAllRightElements()); Assert.AreEqual(2, allRightElementsList.Count); Assert.IsTrue(allRightElementsList.Contains(20)); Assert.IsFalse(bijective.CanAddBijection("B", 20)); Assert.IsFalse(bijective.CanAddReverseBijection(20, "B")); Tuple <string, int> bijection; Assert.IsTrue(bijective.TryGetBijection("B", out bijection)); Assert.AreEqual("B", bijection.Item1); Assert.AreEqual(20, bijection.Item2); Tuple <int, string> reverseBijection; Assert.IsTrue(bijective.TryGetReverseBijection(20, out reverseBijection)); Assert.AreEqual(20, reverseBijection.Item1); Assert.AreEqual("B", reverseBijection.Item2); var allBijectionsList = new List <Tuple <string, int> >(bijective.GetAllBijections()); Assert.AreEqual(2, allBijectionsList.Count); Assert.IsTrue(allBijectionsList.Select(b => b.Item1).Contains("B")); Assert.IsTrue(allBijectionsList.Select(b => b.Item2).Contains(20)); var allReverseBijectionsList = new List <Tuple <int, string> >(bijective.GetAllReverseBijections()); Assert.AreEqual(2, allReverseBijectionsList.Count); Assert.IsTrue(allReverseBijectionsList.Select(b => b.Item1).Contains(20)); Assert.IsTrue(allReverseBijectionsList.Select(b => b.Item2).Contains("B")); }