示例#1
0
            /*
             * @see com.ibm.icu.dev.test.TestBoilerplate#_createTestObject()
             */
            protected internal override bool _addTestObject(IList list)
            {
                if (list.Count > 30)
                {
                    return(false);
                }
                UnicodeMap result = new UnicodeMap();

                for (int i = 0; i < 50; ++i)
                {
                    int    start     = IBM.ICU.Charset.TestUtilities.random.Next(25);
                    String value_ren = IBM.ICU.Charset.TestUtilities.TEST_VALUES[IBM.ICU.Charset.TestUtilities.random.Next(TEST_VALUES.Length)];
                    result.Put(start, value_ren);
                }
                ILOG.J2CsMapping.Collections.Generics.Collections.Add(list, result);
                return(true);
            }
示例#2
0
        internal double _checkSetTime(int iterations, int type)
        {
            map1 = new UnicodeMap();
            map2 = new Hashtable();
            System.Console.Gc();
            double start = DateTime.Now.Millisecond;

            for (int j = 0; j < iterations; ++j)
            {
                for (int cp = 0; cp <= SET_LIMIT; ++cp)
                {
                    int enumValue = IBM.ICU.Lang.UCharacter.GetIntPropertyValue(cp, propEnum);
                    if (enumValue <= 0)
                    {
                        continue;     // for smaller set
                    }
                    String value_ren = IBM.ICU.Lang.UCharacter.GetPropertyValueName(propEnum,
                                                                                    enumValue, IBM.ICU.Lang.UProperty.NameChoice.LONG);
                    switch (type)
                    {
                    case 0:
                        map1.Put(cp, value_ren);
                        break;

                    case 1:
                        ILOG.J2CsMapping.Collections.Collections.Put(map2, ((int)(cp)), value_ren);
                        break;

                    case 3:
                        ILOG.J2CsMapping.Collections.Collections.Put(map3, ((int)(cp)), value_ren);
                        break;
                    }
                }
            }
            double end = DateTime.Now.Millisecond;

            return((end - start) / 1000 / iterations);
        }
示例#3
0
        public void TestUnicodeMap()
        {
            random.SetSeed(12345);
            // do random change to both, then compare
            Logln("Comparing against HashMap");
            for (int counter = 0; counter < ITERATIONS; ++counter)
            {
                int    start     = random.Next(LIMIT);
                String value_ren = TEST_VALUES[random.Next(TEST_VALUES.Length)];
                String logline   = IBM.ICU.Impl.Utility.Hex(start) + "\t" + value_ren;
                if (SHOW_PROGRESS)
                {
                    Logln(counter + "\t" + logline);
                }
                ILOG.J2CsMapping.Collections.Generics.Collections.Add(log, logline);
                if (DEBUG && counter == 144)
                {
                    System.Console.Out.WriteLine(" debug");
                }
                map1.Put(start, value_ren);
                ILOG.J2CsMapping.Collections.Collections.Put(map2, ((int)(start)), value_ren);
                Check(counter);
            }
            CheckNext(LIMIT);

            Logln("Setting General Category");
            map1 = new UnicodeMap();
            map2 = new SortedList();
            for (int cp = 0; cp <= SET_LIMIT; ++cp)
            {
                int enumValue = IBM.ICU.Lang.UCharacter.GetIntPropertyValue(cp, propEnum);
                // if (enumValue <= 0) continue; // for smaller set
                String value_0 = IBM.ICU.Lang.UCharacter.GetPropertyValueName(propEnum, enumValue,
                                                                              IBM.ICU.Lang.UProperty_Constants.NameChoice.LONG);
                map1.Put(cp, value_0);
                ILOG.J2CsMapping.Collections.Collections.Put(map2, ((int)(cp)), value_0);
            }
            CheckNext(Int32.MaxValue);

            Logln("Comparing General Category");
            Check(-1);
            Logln("Comparing Values");
            ILOG.J2CsMapping.Collections.ISet values1 = (ISet)map1.GetAvailableValues(new SortedSet());
            ILOG.J2CsMapping.Collections.ISet values2 = new SortedSet(map2.Values);
            if (!IBM.ICU.Charset.TestBoilerplate.VerifySetsIdentical(this, values1, values2))
            {
                throw new ArgumentException("Halting");
            }
            Logln("Comparing Sets");
            for (IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(values1.GetEnumerator()); it.HasNext();)
            {
                Object value_1 = it.Next();
                Logln((value_1 == null) ? "null" : value_1.ToString());
                UnicodeSet set1 = map1.GetSet(value_1);
                UnicodeSet set2 = IBM.ICU.Charset.TestBoilerplate.GetSet(map2, value_1);
                if (!IBM.ICU.Charset.TestBoilerplate.VerifySetsIdentical(this, set1, set2))
                {
                    throw new ArgumentException("Halting");
                }
            }

            Logln("Getting Scripts");
            UnicodeMap scripts = IBM.ICU.Charset.ICUPropertyFactory.Make().GetProperty("script")
                                 .GetUnicodeMap_internal();

            UnicodeMap.Composer composer = new TestUtilities.Anonymous_C1();

            Logln("Trying Compose");
            UnicodeMap composed = ((UnicodeMap)scripts.CloneAsThawed())
                                  .ComposeWith(map1, composer);
            Object last = "";

            for (int i = 0; i < 0x10FFFF; ++i)
            {
                Object comp = composed.GetValue(i);
                Object gc   = map1.GetValue(i);
                Object sc   = scripts.GetValue(i);
                if (!comp.Equals(composer.Compose(i, gc, sc)))
                {
                    Errln("Failed compose at: " + i);
                }
                if (!last.Equals(comp))
                {
                    Logln(IBM.ICU.Impl.Utility.Hex(i) + "\t" + comp);
                    last = comp;
                }
            }

            // check boilerplate
            IList argList = new ArrayList();

            ILOG.J2CsMapping.Collections.Generics.Collections.Add(argList, "TestMain");
            if (paras.nothrow)
            {
                ILOG.J2CsMapping.Collections.Generics.Collections.Add(argList, "-nothrow");
            }
            if (paras.verbose)
            {
                ILOG.J2CsMapping.Collections.Generics.Collections.Add(argList, "-verbose");
            }
            String[] args = new String[argList.Count];
            ILOG.J2CsMapping.Collections.Collections.ToArray(argList, args);
            new TestUtilities.UnicodeMapBoilerplate().Run(args);
            // TODO: the following is not being reached
            new TestUtilities.UnicodeSetBoilerplate().Run(args);
        }