示例#1
0
        public void TestHashCode()
        {
            RuleBasedBreakIterator bi1 = (RuleBasedBreakIterator)BreakIterator.GetCharacterInstance(CultureInfo.CurrentCulture);
            RuleBasedBreakIterator bi3 = (RuleBasedBreakIterator)BreakIterator.GetCharacterInstance(CultureInfo.CurrentCulture);
            RuleBasedBreakIterator bi2 = (RuleBasedBreakIterator)BreakIterator.GetWordInstance(CultureInfo.CurrentCulture);

            Logln("Testing hashCode()");
            bi1.SetText("Hash code");
            bi2.SetText("Hash code");
            bi3.SetText("Hash code");
            RuleBasedBreakIterator bi1clone = (RuleBasedBreakIterator)bi1.Clone();
            RuleBasedBreakIterator bi2clone = (RuleBasedBreakIterator)bi2.Clone();

            if (bi1.GetHashCode() != bi1clone.GetHashCode() ||
                bi1.GetHashCode() != bi3.GetHashCode() ||
                bi1clone.GetHashCode() != bi3.GetHashCode() ||
                bi2.GetHashCode() != bi2clone.GetHashCode())
            {
                Errln("ERROR: identical objects have different hashcodes");
            }

            if (bi1.GetHashCode() == bi2.GetHashCode() ||
                bi2.GetHashCode() == bi3.GetHashCode() ||
                bi1clone.GetHashCode() == bi2clone.GetHashCode() ||
                bi1clone.GetHashCode() == bi2.GetHashCode())
            {
                Errln("ERROR: different objects have same hashcodes");
            }
        }