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"); }
public void Test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() { FieldPosition pos; StringBuilder xout; IBM.ICU.Text.DecimalFormat format = (IBM.ICU.Text.DecimalFormat)IBM.ICU.Text.NumberFormat .GetInstance(ILOG.J2CsMapping.Util.Locale.US); pos = new FieldPosition(0); xout = format.Format((long)(Int64.MaxValue), new StringBuilder(), pos); NUnit.Framework.Assert.AreEqual("9,223,372,036,854,775,807", xout.ToString(), "Wrong result L1: " + xout); pos = new FieldPosition(0); xout = format.Format((long)(Int64.MinValue), new StringBuilder(), pos); NUnit.Framework.Assert.AreEqual("-9,223,372,036,854,775,808", xout.ToString(), "Wrong result L2: " + xout); pos = new FieldPosition(0); xout = format.Format( Int64.Parse(Int64.MaxValue.ToString()), new StringBuilder(), pos); NUnit.Framework.Assert.AreEqual("9,223,372,036,854,775,807", xout.ToString(), "Wrong result BI1: " + xout); pos = new FieldPosition(0); xout = format.Format( Int64.Parse(Int64.MinValue.ToString()), new StringBuilder(), pos); NUnit.Framework.Assert.AreEqual("-9,223,372,036,854,775,808", xout.ToString(), "Wrong result BI2: " + xout); Int64 big; pos = new FieldPosition(0); big = Int64.Parse(Int64.MaxValue.ToString()) + Int64.Parse("1"); xout = format.Format(big, new StringBuilder(), pos); //NUnit.Framework.Assert.AreEqual("9,223,372,036,854,775,808", xout.ToString(), "Wrong result BI3: " + xout); pos = new FieldPosition(0); big = Int64.Parse(Int64.MinValue.ToString()) + Int64.Parse("-1"); xout = format.Format(big, new StringBuilder(), pos); //NUnit.Framework.Assert.AreEqual("-9,223,372,036,854,775,809", xout.ToString(), "Wrong result BI4: " + xout); pos = new FieldPosition(0); xout = format.Format(Decimal.Parse("51.348"), new StringBuilder(), pos); NUnit.Framework.Assert.AreEqual("51.348", xout.ToString(), "Wrong result BD1: " + xout); pos = new FieldPosition(0); xout = format.Format(Decimal.Parse("51"), new StringBuilder(), pos); NUnit.Framework.Assert.AreEqual("51", xout.ToString(), "Wrong result BD2: " + xout); }
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); }