public void TestEqualsTypeMismatch() { var list = new SCG.List <int> { 1, 2, 3, 4, 5 }; var set = new SCG.HashSet <int> { 1, 2, 3, 4, 5 }; var dictionary = new SCG.Dictionary <int, int> { { 1, 0 }, { 2, 0 }, { 3, 0 }, { 4, 0 }, { 5, 0 } }; var array = new int[] { 1, 2, 3, 4, 5 }; Assert.IsFalse(CollectionUtil.Equals(list, set)); Assert.IsFalse(CollectionUtil.Equals(list, dictionary)); Assert.IsTrue(CollectionUtil.Equals(list, array)); // Types are compatible - array implements IList<T> Assert.IsFalse(CollectionUtil.Equals(set, dictionary)); Assert.IsFalse(CollectionUtil.Equals(set, array)); }
public void TestEqualityDictionary() { var control = new SCG.Dictionary <string, IDictionary <HashMap <long, double>, string> > { { "a", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 123, 9.87 }, { 80, 88 } }, "qwerty" } } }, { "z", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 456, 9.86 }, { 81, 88 } }, "hexagon" } } }, { "r", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 789, 9.85 }, { 82, 88 } }, "parasite" } } }, { "t", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 101, 9.84 }, { 83, 88 } }, "octopus" } } }, }; var equal = new SCG.Dictionary <string, IDictionary <HashMap <long, double>, string> > { { "a", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 123, 9.87 }, { 80, 88 } }, "qwerty" } } }, { "z", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 456, 9.86 }, { 81, 88 } }, "hexagon" } } }, { "r", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 789, 9.85 }, { 82, 88 } }, "parasite" } } }, { "t", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 101, 9.84 }, { 83, 88 } }, "octopus" } } }, }; var equalDifferentType = new HashMap <string, IDictionary <HashMap <long, double>, string> > { { "a", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 123, 9.87 }, { 80, 88 } }, "qwerty" } } }, { "z", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 456, 9.86 }, { 81, 88 } }, "hexagon" } } }, { "r", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 789, 9.85 }, { 82, 88 } }, "parasite" } } }, { "t", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 101, 9.84 }, { 83, 88 } }, "octopus" } } }, }; var equalDifferentOrder = new SCG.Dictionary <string, IDictionary <HashMap <long, double>, string> > { { "r", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 789, 9.85 }, { 82, 88 } }, "parasite" } } }, { "t", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 101, 9.84 }, { 83, 88 } }, "octopus" } } }, { "a", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 123, 9.87 }, { 80, 88 } }, "qwerty" } } }, { "z", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 456, 9.86 }, { 81, 88 } }, "hexagon" } } }, }; var level1EqualLevel2EqualLevel3Unequal = new SCG.Dictionary <string, IDictionary <HashMap <long, double>, string> > { { "a", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 123, 9.87 }, { 80, 88.1 } }, "qwerty" } } }, { "z", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 456, 9.86 }, { 81, 88 } }, "hexagon" } } }, { "r", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 789, 9.85 }, { 82, 88 } }, "parasite" } } }, { "t", new SCG.Dictionary <HashMap <long, double>, string> { { new HashMap <long, double> { { 101, 9.84 }, { 83, 88 } }, "octopus" } } }, }; Assert.AreEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(control)); Assert.IsTrue(CollectionUtil.Equals(control, control)); Assert.AreEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(equal)); Assert.IsTrue(CollectionUtil.Equals(control, equal)); Assert.AreEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(equalDifferentType)); Assert.IsTrue(CollectionUtil.Equals(control, equalDifferentType)); Assert.AreEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(equalDifferentOrder)); Assert.IsTrue(CollectionUtil.Equals(control, equalDifferentOrder)); Assert.AreNotEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(level1EqualLevel2EqualLevel3Unequal)); Assert.IsFalse(CollectionUtil.Equals(control, level1EqualLevel2EqualLevel3Unequal)); }
public void TestEqualitySet() { var control = new SCG.HashSet <IDictionary <string, string> > { new SCG.Dictionary <string, string> { { "1", "one" }, { "2", "two" }, { "3", "three" } }, new SCG.Dictionary <string, string> { { "4", "four" }, { "5", "five" }, { "6", "six" } }, new SCG.Dictionary <string, string> { { "7", "seven" }, { "8", "eight" }, { "9", "nine" } }, }; var equal = new SCG.HashSet <IDictionary <string, string> > { new SCG.Dictionary <string, string> { { "1", "one" }, { "2", "two" }, { "3", "three" } }, new SCG.Dictionary <string, string> { { "4", "four" }, { "5", "five" }, { "6", "six" } }, new SCG.Dictionary <string, string> { { "7", "seven" }, { "8", "eight" }, { "9", "nine" } }, }; var equalDifferentType = new MockHashSet <IDictionary <string, string> > { new SCG.Dictionary <string, string> { { "1", "one" }, { "2", "two" }, { "3", "three" } }, new SCG.Dictionary <string, string> { { "4", "four" }, { "5", "five" }, { "6", "six" } }, new SCG.Dictionary <string, string> { { "7", "seven" }, { "8", "eight" }, { "9", "nine" } }, }; var equalDifferentOrder = new SCG.HashSet <IDictionary <string, string> > { new SCG.Dictionary <string, string> { { "7", "seven" }, { "8", "eight" }, { "9", "nine" } }, new SCG.Dictionary <string, string> { { "1", "one" }, { "2", "two" }, { "3", "three" } }, new SCG.Dictionary <string, string> { { "4", "four" }, { "5", "five" }, { "6", "six" } }, }; var level1EqualLevel2Unequal = new SCG.HashSet <IDictionary <string, string> > { new SCG.Dictionary <string, string> { { "1", "one" }, { "2", "two" }, { "3", "three" } }, new SCG.Dictionary <string, string> { { "4", "four" }, { "5", "five" }, { "6", "six" } }, new SCG.Dictionary <string, string> { { "7", "seven" }, { "8", "eight" }, { "9", "nine99" } }, }; Assert.AreEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(control)); Assert.IsTrue(CollectionUtil.Equals(control, control)); Assert.AreEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(equal)); Assert.IsTrue(CollectionUtil.Equals(control, equal)); Assert.AreEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(equalDifferentType)); Assert.IsTrue(CollectionUtil.Equals(control, equalDifferentType)); // Sets are not order-sensitive Assert.AreEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(equalDifferentOrder)); Assert.IsTrue(CollectionUtil.Equals(control, equalDifferentOrder)); Assert.AreNotEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(level1EqualLevel2Unequal)); Assert.IsFalse(CollectionUtil.Equals(control, level1EqualLevel2Unequal)); }
public void TestEqualityListSimple() { var control = new SCG.List <IList <string> > { new SCG.List <string> { "one", "two", "three" }, new SCG.List <string> { "four", "five", "six" }, new SCG.List <string> { "seven", "eight", "nine" }, }; var equal = new SCG.List <IList <string> > { new SCG.List <string> { "one", "two", "three" }, new SCG.List <string> { "four", "five", "six" }, new SCG.List <string> { "seven", "eight", "nine" }, }; var equalDifferentType = new IList <string>[] { new SCG.List <string> { "one", "two", "three" }, new SCG.List <string> { "four", "five", "six" }, new SCG.List <string> { "seven", "eight", "nine" }, }; var equalDifferentOrder = new SCG.List <IList <string> > { new SCG.List <string> { "four", "five", "six" }, new SCG.List <string> { "seven", "eight", "nine" }, new SCG.List <string> { "one", "two", "three" }, }; var level1EqualLevel2Unequal = new SCG.List <IList <string> > { new SCG.List <string> { "one", "two", "three" }, new SCG.List <string> { "four", "five", "six" }, new SCG.List <string> { "seven", "eight", "nine-nine" }, }; Assert.AreEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(control)); Assert.IsTrue(CollectionUtil.Equals(control, control)); Assert.AreEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(equal)); Assert.IsTrue(CollectionUtil.Equals(control, equal)); Assert.AreEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(equalDifferentType)); Assert.IsTrue(CollectionUtil.Equals(control, equalDifferentType)); // Lists and arrays are order - sensitive Assert.AreNotEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(equalDifferentOrder)); Assert.IsFalse(CollectionUtil.Equals(control, equalDifferentOrder)); Assert.AreNotEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(level1EqualLevel2Unequal)); Assert.IsFalse(CollectionUtil.Equals(control, level1EqualLevel2Unequal)); }