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 TestToString()
        {
            var set = new J2N.Collections.Generic.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 setExpected = "[{1=one, 2=two, 3=three}, {4=four, 5=five, 6=six}, {7=seven, 8=eight, 9=nine}]";

            Assert.AreEqual(setExpected, CollectionUtil.ToString(set, StringFormatter.InvariantCulture));


            var set2 = new J2N.Collections.Generic.HashSet <ISet <string> >
            {
                new J2N.Collections.Generic.HashSet <string> {
                    "1", "2", "3"
                },
                new J2N.Collections.Generic.HashSet <string> {
                    "4", "5", "6"
                },
                new System.Collections.Generic.HashSet <string> {
                    "7", "8", "9"
                },
            };
            var set2Expected = "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]";

            Assert.AreEqual(set2Expected, CollectionUtil.ToString(set2, StringFormatter.InvariantCulture));


            var map = new SCG.Dictionary <string, IDictionary <int, double> >
            {
                { "first", new SCG.Dictionary <int, double> {
                      { 1, 1.23 }, { 2, 2.23 }, { 3, 3.23 }
                  } },
                { "second", new SCG.Dictionary <int, double> {
                      { 4, 1.24 }, { 5, 2.24 }, { 6, 3.24 }
                  } },
                { "third", new SCG.Dictionary <int, double> {
                      { 7, 1.25 }, { 8, 2.25 }, { 9, 3.25 }
                  } },
            };
            var mapExpectedPortuguese = "{first={1=1,23, 2=2,23, 3=3,23}, second={4=1,24, 5=2,24, 6=3,24}, third={7=1,25, 8=2,25, 9=3,25}}";
            var mapExpectedUSEnglish  = "{first={1=1.23, 2=2.23, 3=3.23}, second={4=1.24, 5=2.24, 6=3.24}, third={7=1.25, 8=2.25, 9=3.25}}";

            Assert.AreEqual(mapExpectedPortuguese, CollectionUtil.ToString(map, new StringFormatter(new CultureInfo("pt"))));
            Assert.AreEqual(mapExpectedUSEnglish, CollectionUtil.ToString(map, new StringFormatter(new CultureInfo("en-US"))));

            var array = new SCG.List <SCG.Dictionary <string, string> >[]
            {
                new SCG.List <SCG.Dictionary <string, string> > {
                    new SCG.Dictionary <string, string> {
                        { "foo", "bar" }, { "foobar", "barfoo" }
                    }
                },
                new SCG.List <SCG.Dictionary <string, string> > {
                    new SCG.Dictionary <string, string> {
                        { "orange", "yellow" }, { "red", "black" }
                    },
                    new SCG.Dictionary <string, string> {
                        { "rain", "snow" }, { "sleet", "sunshine" }
                    }
                },
            };
            var arrayExpected = "[[{foo=bar, foobar=barfoo}], [{orange=yellow, red=black}, {rain=snow, sleet=sunshine}]]";

            Assert.AreEqual(arrayExpected, CollectionUtil.ToString(array, StringFormatter.InvariantCulture));
        }
        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));
        }