示例#1
0
        private void DoTestRanges(IndexSearcher @is, String startPoint, String endPoint, Query query, Collator collator)
        {
            QueryUtils.Check(query);

            // positive test
            TopDocs docs = @is.Search(query, @is.IndexReader.MaxDoc);

            foreach (ScoreDoc doc in docs.ScoreDocs)
            {
                String value = @is.Doc(doc.Doc).Get("field");
                assertTrue(collator.Compare(value, startPoint) >= 0);
                assertTrue(collator.Compare(value, endPoint) <= 0);
            }

            // negative test
            BooleanQuery bq = new BooleanQuery();

            bq.Add(new MatchAllDocsQuery(), Occur.SHOULD);
            bq.Add(query, Occur.MUST_NOT);
            docs = @is.Search(bq, @is.IndexReader.MaxDoc);
            foreach (ScoreDoc doc in docs.ScoreDocs)
            {
                String value = @is.Doc(doc.Doc).Get("field");
                assertTrue(collator.Compare(value, startPoint) < 0 || collator.Compare(value, endPoint) > 0);
            }
        }
示例#2
0
        public static int CompareStringsUnicode(string a, string b)
        {
            Collator c   = Collator.GetInstance();
            int      res = c.Compare(a, b);

            return(res);
        }
示例#3
0
        /// @tests java.text.Collator#getAvailableLocales()
        // FIXME This test fails on Harmony ClassLibrary
        public void Failing_test_getAvailableLocales()
        {
            Locale[] locales = ILOG.J2CsMapping.Text.Collator.GetAvailableLocales();
            NUnit.Framework.Assert.IsTrue(locales.Length > 0, "No locales");
            bool english = false, german = false;

            for (int i = locales.Length; --i >= 0;)
            {
                if (locales[i].Equals(Locale.ENGLISH))
                {
                    english = true;
                }
                if (locales[i].Equals(Locale.GERMAN))
                {
                    german = true;
                }
                // Output the working locale to help diagnose a hang
                Collator c1 = ILOG.J2CsMapping.Text.Collator.GetInstance(locales[i]);
                NUnit.Framework.Assert.IsTrue(c1.Compare("a", "b") < 0, "Doesn't work");
                NUnit.Framework.Assert.IsTrue(c1.GetDecomposition() == ILOG.J2CsMapping.Text.Collator.NO_DECOMPOSITION, "Wrong decomposition");
                NUnit.Framework.Assert.IsTrue(c1.GetStrength() == ILOG.J2CsMapping.Text.Collator.TERTIARY, "Wrong strength");
                if (c1  is  RuleBasedCollator)
                {
                    try {
                        new RuleBasedCollator(((RuleBasedCollator)c1).GetRules());
                    } catch (ParseException e) {
                        NUnit.Framework.Assert.Fail("ParseException");
                    }
                    // assertTrue("Can't recreate: " + locales[i], temp.equals(c1));
                }
            }
            NUnit.Framework.Assert.IsTrue(english && german, "Missing locales");
        }
示例#4
0
        public override int Compare(ISqlObject x, ISqlObject y)
        {
            if (x == null)
            {
                throw new ArgumentNullException("x");
            }

            if (!(x is ISqlString) ||
                !(y is ISqlString))
            {
                throw new ArgumentException("Cannot compare objects that are not strings.");
            }

            if (x.IsNull && y.IsNull)
            {
                return(0);
            }
            if (x.IsNull && !y.IsNull)
            {
                return(1);
            }
            if (!x.IsNull && y.IsNull)
            {
                return(-1);
            }

            // If lexicographical ordering,
            if (Locale == null)
            {
                return(LexicographicalOrder((ISqlString)x, (ISqlString)y));
            }

            return(Collator.Compare(x.ToString(), y.ToString()));
        }
示例#5
0
        public void TestJB581()
        {
            String   source = "THISISATEST.";
            String   target = "Thisisatest.";
            Collator coll   = null;

            try
            {
                coll = Collator.GetInstance(new CultureInfo("en") /*Locale.ENGLISH*/);
            }
            catch (Exception e)
            {
                Errln("ERROR: Failed to create the collator for : en_US\n");
                return;
            }

            int result = coll.Compare(source, target);

            // result is 1, secondary differences only for ignorable space characters
            if (result != 1)
            {
                Errln("Comparing two strings with only secondary differences in C failed.\n");
                return;
            }

            // To compare them with just primary differences
            coll.Strength = (Collator.PRIMARY);
            result        = coll.Compare(source, target);
            // result is 0
            if (result != 0)
            {
                Errln("Comparing two strings with no differences in C failed.\n");
                return;
            }

            // Now, do the same comparison with keys
            CollationKey sourceKeyOut, targetKeyOut;

            sourceKeyOut = coll.GetCollationKey(source);
            targetKeyOut = coll.GetCollationKey(target);
            result       = sourceKeyOut.CompareTo(targetKeyOut);
            if (result != 0)
            {
                Errln("Comparing two strings with sort keys in C failed.\n");
                return;
            }
        }
示例#6
0
        public static EcmaValue StringPrototypeLocaleCompare([This] EcmaValue thisValue, EcmaValue thatValue, EcmaValue locales, EcmaValue options)
        {
            Guard.RequireObjectCoercible(thisValue);
            string   thisString = thisValue.ToStringOrThrow();
            string   thatString = thatValue.ToStringOrThrow();
            Collator collator   = new Collator();

            CollatorConstructor.Collator(collator, locales, options);
            return(collator.Compare(thisString, thatString));
        }
        public void TestCollator_GetInstance()
        {
            Collator coll = ILOG.J2CsMapping.Text.Collator.GetInstance();
            Object   obj1 = "a";
            Object   obj2 = "b";

            NUnit.Framework.Assert.AreEqual(-1, coll.Compare(obj1, obj2));

            ILOG.J2CsMapping.Text.Collator.GetInstance();
            NUnit.Framework.Assert.IsFalse(coll.Equals("A", "\uFF21"));
        }
        // main test routine, tests rules specific to "Korean" locale
        private void DoTest(char[] source, char[] target, int result)
        {
            String       s = new String(source);
            String       t = new String(target);
            int          compareResult = myCollation.Compare(s, t);
            CollationKey sortKey1, sortKey2;

            sortKey1 = myCollation.GetCollationKey(s);
            sortKey2 = myCollation.GetCollationKey(t);
            int keyResult = sortKey1.CompareTo(sortKey2);

            ReportCResult(s, t, sortKey1, sortKey2, compareResult, keyResult, compareResult, result);
        }
示例#9
0
        // main test routine, tests comparisons for a set of strings against sets of expected results
        private void DoTest(Collator myCollation, String source, String target,
                            int result)
        {
            int          compareResult = myCollation.Compare(source, target);
            CollationKey sortKey1, sortKey2;

            sortKey1 = myCollation.GetCollationKey(source);
            sortKey2 = myCollation.GetCollationKey(target);
            int keyResult = sortKey1.CompareTo(sortKey2);

            ReportCResult(source, target, sortKey1, sortKey2, compareResult,
                          keyResult, compareResult, result);
        }
示例#10
0
        private void DoTestVariant(Collator collation, String source, String target, int result)
        {
            int          compareResult = collation.Compare(source, target);
            CollationKey srckey, tgtkey;

            srckey = collation.GetCollationKey(source);
            tgtkey = collation.GetCollationKey(target);
            int keyResult = srckey.CompareTo(tgtkey);

            if (compareResult != result)
            {
                Errln("String comparison failed in variant test\n");
            }
            if (keyResult != result)
            {
                Errln("Collation key comparison failed in variant test\n");
            }
        }
示例#11
0
        public void Test_compareLjava_lang_ObjectLjava_lang_Object()
        {
            Collator c = ILOG.J2CsMapping.Text.Collator.GetInstance(Locale.FRENCH);
            Object   o, o2;

            c.SetStrength(ILOG.J2CsMapping.Text.Collator.IDENTICAL);
            o  = "E";
            o2 = "F";
            NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "a) Failed on primary difference");
            o  = "e";
            o2 = "\u00e9";
            NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "a) Failed on secondary difference");
            o  = "e";
            o2 = "E";
            NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "a) Failed on tertiary difference");
            o  = "\u0001";
            o2 = "\u0002";
            NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "a) Failed on identical");
            o  = "e";
            o2 = "e";
            NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "a) Failed on equivalence");
            NUnit.Framework.Assert.IsTrue(c.Compare("\u01db", "v") < 0, "a) Failed on primary expansion");

            c.SetStrength(ILOG.J2CsMapping.Text.Collator.TERTIARY);
            o  = "E";
            o2 = "F";
            NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "b) Failed on primary difference");
            o  = "e";
            o2 = "\u00e9";
            NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "b) Failed on secondary difference");
            o  = "e";
            o2 = "E";
            NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "b) Failed on tertiary difference");
            o  = "\u0001";
            o2 = "\u0002";
            NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "b) Failed on identical");
            o  = "e";
            o2 = "e";
            NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "b) Failed on equivalence");

            c.SetStrength(ILOG.J2CsMapping.Text.Collator.SECONDARY);
            o  = "E";
            o2 = "F";
            NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "c) Failed on primary difference");
            o  = "e";
            o2 = "\u00e9";
            NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "c) Failed on secondary difference");
            o  = "e";
            o2 = "E";
            NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "c) Failed on tertiary difference");
            o  = "\u0001";
            o2 = "\u0002";
            NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "c) Failed on identical");
            o  = "e";
            o2 = "e";
            NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "c) Failed on equivalence");

            c.SetStrength(ILOG.J2CsMapping.Text.Collator.PRIMARY);
            o  = "E";
            o2 = "F";
            NUnit.Framework.Assert.IsTrue(c.Compare(o, o2) < 0, "d) Failed on primary difference");
            o  = "e";
            o2 = "\u00e9";
            NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "d) Failed on secondary difference");
            o  = "e";
            o2 = "E";
            NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "d) Failed on tertiary difference");
            o  = "\u0001";
            o2 = "\u0002";
            NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "d) Failed on identical");
            o  = "e";
            o2 = "e";
            NUnit.Framework.Assert.AreEqual(0, c.Compare(o, o2), "d) Failed on equivalence");

            try {
                c.Compare("e", new StringBuilder("Blah"));
            } catch (InvalidCastException e) {
                // correct
                return;
            }
            NUnit.Framework.Assert.Fail("Failed to throw ClassCastException");
        }
示例#12
0
 public int Compare(IMap <string, object> map1, IMap <string, object> map2)
 {
     return(collator.Compare(map1.Get("title"), map2.Get("title")));
 }
示例#13
0
 public int Compare(AppEntry object1, AppEntry object2)
 {
     return(sCollator.Compare(object1.GetLabel(), object2.GetLabel()));
 }
 public int Compare(string o1, string o2)
 {
     return(Collator.Compare(o1, o2));
 }