Esempio n. 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");
            }
        }
Esempio n. 2
0
        public void TestCloneEquals()
        {
            RuleBasedBreakIterator bi1     = (RuleBasedBreakIterator)BreakIterator.GetCharacterInstance(CultureInfo.CurrentCulture);
            RuleBasedBreakIterator biequal = (RuleBasedBreakIterator)BreakIterator.GetCharacterInstance(CultureInfo.CurrentCulture);
            RuleBasedBreakIterator bi3     = (RuleBasedBreakIterator)BreakIterator.GetCharacterInstance(CultureInfo.CurrentCulture);
            RuleBasedBreakIterator bi2     = (RuleBasedBreakIterator)BreakIterator.GetWordInstance(CultureInfo.CurrentCulture);

            string testString = "Testing word break iterators's clone() and equals()";

            bi1.SetText(testString);
            bi2.SetText(testString);
            biequal.SetText(testString);

            bi3.SetText("hello");
            Logln("Testing equals()");
            Logln("Testing == and !=");
            if (!bi1.Equals(biequal) || bi1.Equals(bi2) || bi1.Equals(bi3))
            {
                Errln("ERROR:1 RBBI's == and !- operator failed.");
            }
            if (bi2.Equals(biequal) || bi2.Equals(bi1) || biequal.Equals(bi3))
            {
                Errln("ERROR:2 RBBI's == and != operator  failed.");
            }
            Logln("Testing clone()");
            RuleBasedBreakIterator bi1clone = (RuleBasedBreakIterator)bi1.Clone();
            RuleBasedBreakIterator bi2clone = (RuleBasedBreakIterator)bi2.Clone();

            if (!bi1clone.Equals(bi1) ||
                !bi1clone.Equals(biequal) ||
                bi1clone.Equals(bi3) ||
                bi1clone.Equals(bi2))
            {
                Errln("ERROR:1 RBBI's clone() method failed");
            }

            if (bi2clone.Equals(bi1) ||
                bi2clone.Equals(biequal) ||
                bi2clone.Equals(bi3) ||
                !bi2clone.Equals(bi2))
            {
                Errln("ERROR:2 RBBI's clone() method failed");
            }

            if (!bi1.Text.Equals(bi1clone.Text) ||
                !bi2clone.Text.Equals(bi2.Text) ||
                bi2clone.Equals(bi1clone))
            {
                Errln("ERROR: RBBI's clone() method failed");
            }
        }
Esempio n. 3
0
        public void TestToString()
        {
            RuleBasedBreakIterator bi1 = (RuleBasedBreakIterator)BreakIterator.GetCharacterInstance(CultureInfo.CurrentCulture);
            RuleBasedBreakIterator bi2 = (RuleBasedBreakIterator)BreakIterator.GetWordInstance(CultureInfo.CurrentCulture);

            Logln("Testing toString()");
            bi1.SetText("Hello there");
            RuleBasedBreakIterator bi3 = (RuleBasedBreakIterator)bi1.Clone();
            String temp  = bi1.ToString();
            String temp2 = bi2.ToString();
            String temp3 = bi3.ToString();

            if (temp2.Equals(temp3) || temp.Equals(temp2) || !temp.Equals(temp3))
            {
                Errln("ERROR: error in toString() method");
            }
        }
Esempio n. 4
0
        public void TestClone()
        {
            RuleBasedBreakIterator rbbi = new RuleBasedBreakIterator(".;");

            try
            {
                rbbi.SetText((CharacterIterator)null);
                if (((RuleBasedBreakIterator)rbbi.Clone()).Text != null)
                {
                    Errln("RuleBasedBreakIterator.clone() was suppose to return "
                          + "the same object because fText is set to null.");
                }
            }
            catch (Exception e)
            {
                Errln("RuleBasedBreakIterator.clone() was not suppose to return " + "an exception.");
            }
        }
Esempio n. 5
0
        public void TestBug12519()
        {
            RuleBasedBreakIterator biEn = (RuleBasedBreakIterator)BreakIterator.GetWordInstance(ULocale.ENGLISH);
            RuleBasedBreakIterator biFr = (RuleBasedBreakIterator)BreakIterator.GetWordInstance(ULocale.FRANCE);

            assertEquals("", ULocale.ENGLISH, biEn.GetLocale(ULocale.VALID_LOCALE));
            assertEquals("", ULocale.FRENCH, biFr.GetLocale(ULocale.VALID_LOCALE));
            assertEquals("Locales do not participate in BreakIterator equality.", biEn, biFr);

            RuleBasedBreakIterator cloneEn = (RuleBasedBreakIterator)biEn.Clone();

            assertEquals("", biEn, cloneEn);
            assertEquals("", ULocale.ENGLISH, cloneEn.GetLocale(ULocale.VALID_LOCALE));

            RuleBasedBreakIterator cloneFr = (RuleBasedBreakIterator)biFr.Clone();

            assertEquals("", biFr, cloneFr);
            assertEquals("", ULocale.FRENCH, cloneFr.GetLocale(ULocale.VALID_LOCALE));
        }
Esempio n. 6
0
        public void TestBug12519()
        {
            RuleBasedBreakIterator biEn = (RuleBasedBreakIterator)BreakIterator.GetWordInstance(new UCultureInfo("en"));
            RuleBasedBreakIterator biFr = (RuleBasedBreakIterator)BreakIterator.GetWordInstance(new UCultureInfo("fr_FR"));

            assertEquals("", new UCultureInfo("en"), biEn.ValidCulture);
            assertEquals("", new UCultureInfo("fr"), biFr.ValidCulture);
            assertEquals("Locales do not participate in BreakIterator equality.", biEn, biFr);

            RuleBasedBreakIterator cloneEn = (RuleBasedBreakIterator)biEn.Clone();

            assertEquals("", biEn, cloneEn);
            assertEquals("", new UCultureInfo("en"), cloneEn.ValidCulture);

            RuleBasedBreakIterator cloneFr = (RuleBasedBreakIterator)biFr.Clone();

            assertEquals("", biFr, cloneFr);
            assertEquals("", new UCultureInfo("fr"), cloneFr.ValidCulture);
        }
Esempio n. 7
0
 public override void Run()
 {
     try
     {
         RuleBasedBreakIterator localBI = (RuleBasedBreakIterator)bi.Clone();
         localBI.SetText(dataToBreak);
         for (int loop = 0; loop < 100; loop++)
         {
             int nextExpectedBreak = 0;
             for (int actualBreak = localBI.First(); actualBreak != BreakIterator.Done;
                  actualBreak = localBI.Next(), nextExpectedBreak += 4)
             {
                 assertEquals("", nextExpectedBreak, actualBreak);
             }
             assertEquals("", dataToBreak.Length + 4, nextExpectedBreak);
         }
     }
     catch (AssertionException e)
     {
         assertErr[0] = e;
     }
 }