コード例 #1
0
        public void Test_getIntegerInstanceLLocale()
        {
            // Test for method java.text.NumberFormat
            // getIntegerInstance(java.util.ILOG.J2CsMapping.Util.Locale)
            ILOG.J2CsMapping.Util.Locale usLocale = ILOG.J2CsMapping.Util.Locale.US;
            ILOG.J2CsMapping.Util.Locale arLocale = new ILOG.J2CsMapping.Util.Locale("ar", "AE");

            IBM.ICU.Text.DecimalFormat format = (IBM.ICU.Text.DecimalFormat)IBM.ICU.Text.NumberFormat
                                                .GetIntegerInstance(usLocale);
            NUnit.Framework.Assert.AreEqual("#,##0", format.ToPattern(), "Test1: NumberFormat.getIntegerInstance().toPattern() returned wrong pattern");
            NUnit.Framework.Assert.AreEqual("-36", format.Format(-35.76d), "Test2: NumberFormat.getIntegerInstance().format(-35.76) returned wrong value");
            NUnit.Framework.Assert.AreEqual((long)(-36), format.Parse("-36"), "Test3: NumberFormat.getIntegerInstance().parse(\"-36\") returned wrong number");
            NUnit.Framework.Assert.AreEqual((long)(-36), format.ParseObject("-36"), "Test4: NumberFormat.getIntegerInstance().parseObject(\"-36\") returned wrong number");
            NUnit.Framework.Assert.AreEqual(0, format.GetMaximumFractionDigits(), "Test5: NumberFormat.getIntegerInstance().getMaximumFractionDigits() returned wrong value");
            NUnit.Framework.Assert.IsTrue(format.IsParseIntegerOnly(), "Test6: NumberFormat.getIntegerInstance().isParseIntegerOnly() returned wrong value");

            // try with a ILOG.J2CsMapping.Util.Locale that has a different integer pattern
            format = (IBM.ICU.Text.DecimalFormat)IBM.ICU.Text.NumberFormat.GetIntegerInstance(arLocale);
            NUnit.Framework.Assert.AreEqual("#,##0;#,##0-", format.ToPattern(), "Test7: NumberFormat.getIntegerInstance(new ILOG.J2CsMapping.Util.Locale(\"ar\", \"AE\")).toPattern() returned wrong pattern");
            //NUnit.Framework.Assert.AreEqual("36-", format.Format(-6), "Test8: NumberFormat.getIntegerInstance(new ILOG.J2CsMapping.Util.Locale(\"ar\", \"AE\")).format(-35.76) returned wrong value");
            NUnit.Framework.Assert.AreEqual((long)(-36), format.Parse("36-"), "Test9: NumberFormat.getIntegerInstance(new ILOG.J2CsMapping.Util.Locale(\"ar\", \"AE\")).parse(\"-36-\") returned wrong number");
            NUnit.Framework.Assert.AreEqual((long)(-36), format.ParseObject("36-"), "Test10: NumberFormat.getIntegerInstance(new ILOG.J2CsMapping.Util.Locale(\"ar\", \"AE\")).parseObject(\"36-\") returned wrong number");

            NUnit.Framework.Assert.AreEqual(0, format.GetMaximumFractionDigits(), "Test11: NumberFormat.getIntegerInstance(new ILOG.J2CsMapping.Util.Locale(\"ar\", \"AE\")).getMaximumFractionDigits() returned wrong value");
            NUnit.Framework.Assert.IsTrue(format.IsParseIntegerOnly(), "Test12: NumberFormat.getIntegerInstance(new ILOG.J2CsMapping.Util.Locale(\"ar\", \"AE\")).isParseIntegerOnly() returned wrong value");
        }
コード例 #2
0
        public void Test_getIntegerInstance()
        {
            // Test for method java.text.NumberFormat getIntegerInstance()
            ILOG.J2CsMapping.Util.Locale origLocale = ILOG.J2CsMapping.Util.Locale.GetDefault();
            ILOG.J2CsMapping.Util.Locale.SetDefault(ILOG.J2CsMapping.Util.Locale.US);

            IBM.ICU.Text.DecimalFormat format = (IBM.ICU.Text.DecimalFormat)IBM.ICU.Text.NumberFormat
                                                .GetIntegerInstance();

            NUnit.Framework.Assert.AreEqual("#,##0", format.ToPattern(), "Test1: NumberFormat.getIntegerInstance().toPattern() returned wrong pattern");
            NUnit.Framework.Assert.AreEqual("36", format.Format(35.76d), "Test2: NumberFormat.getIntegerInstance().format(35.76) returned wrong value");
            NUnit.Framework.Assert.AreEqual((long)(35), format.Parse("35.76"), "Test3: NumberFormat.getIntegerInstance().parse(\"35.76\") returned wrong number");
            NUnit.Framework.Assert.AreEqual((long)(35), format.ParseObject("35.76"), "Test4: NumberFormat.getIntegerInstance().parseObject(\"35.76\") returned wrong number");
            ILOG.J2CsMapping.Util.Locale.SetDefault(origLocale);
        }