public void Test_nextDoubleDZ() { // Test for method double java.text.ChoiceFormat.nextDouble(double, // boolean) NUnit.Framework.Assert.IsTrue(ChoiceFormat.NextDouble(0, true) > 0, "Not greater 0"); NUnit.Framework.Assert.IsTrue(ChoiceFormat.NextDouble(0, false) < 0, "Not less 0"); }
public void Test_equalsLjava_lang_Object() { // Test for method boolean // java.text.ChoiceFormat.equals(java.lang.Object) String patternString = "-2#Inverted Orange| 0#No Orange| 0<Almost No Orange| 1#Normal Orange| 2#Expensive Orange"; double[] appleLimits = { 1, 2, 3, 4, 5 }; String[] appleFormats = { "Tiny Apple", "Small Apple", "Medium Apple", "Large Apple", "Huge Apple" }; double[] orangeLimits = { -2, 0, ChoiceFormat.NextDouble(0), 1, 2 }; String[] orangeFormats = { "Inverted Orange", "No Orange", "Almost No Orange", "Normal Orange", "Expensive Orange" }; ChoiceFormat appleChoiceFormat = new ChoiceFormat(appleLimits, appleFormats); ChoiceFormat orangeChoiceFormat = new ChoiceFormat(orangeLimits, orangeFormats); ChoiceFormat orangeChoiceFormat2 = new ChoiceFormat(patternString); ChoiceFormat hybridChoiceFormat = new ChoiceFormat(appleLimits, orangeFormats); NUnit.Framework.Assert.IsTrue(!appleChoiceFormat.Equals(orangeChoiceFormat), "Apples should not equal oranges"); NUnit.Framework.Assert.IsTrue(!orangeChoiceFormat.Equals(hybridChoiceFormat), "Different limit list--should not appear as equal"); NUnit.Framework.Assert.IsTrue(!appleChoiceFormat.Equals(hybridChoiceFormat), "Different format list--should not appear as equal"); NUnit.Framework.Assert.IsTrue(appleChoiceFormat.Equals(appleChoiceFormat), "Should be equal--identical format"); NUnit.Framework.Assert.IsTrue(orangeChoiceFormat.Equals(orangeChoiceFormat2), "Should be equals--same limits, same formats"); ChoiceFormat f2 = new ChoiceFormat( "0#Less than one|1#one|1<Between one and two|2<Greater than two"); NUnit.Framework.Assert.IsTrue(f1.Equals(f2), "Not equal"); }
public ChoiceFormatTest() { this.limits = new double[] { 0, 1, ChoiceFormat.NextDouble(1), ChoiceFormat.NextDouble(2) }; this.formats = new String[] { "Less than one", "one", "Between one and two", "Greater than two" }; this.f1 = new ChoiceFormat(limits, formats); }
public void Test_nextDoubleD() { // Test for method double java.text.ChoiceFormat.nextDouble(double) NUnit.Framework.Assert.IsTrue(ChoiceFormat.NextDouble(5) > 5, "Not greater 5"); NUnit.Framework.Assert.IsTrue(ChoiceFormat.NextDouble(0) > 0, "Not greater 0"); NUnit.Framework.Assert.IsTrue(ChoiceFormat.NextDouble(-5) > -5, "Not greater -5"); NUnit.Framework.Assert.IsTrue(Double.IsNaN(ChoiceFormat.NextDouble(System.Double.NaN)), "Not NaN"); }
public void Test_applyPatternLjava_lang_String() { // Test for method void // java.text.ChoiceFormat.applyPattern(java.lang.String) ChoiceFormat f = (ChoiceFormat)f1.Clone(); f.ApplyPattern("0#0|1#1"); NUnit.Framework.Assert.IsTrue(ILOG.J2CsMapping.Collections.Arrays.Equals(f.GetLimits(), new double[] { 0, 1 }), "Incorrect limits"); NUnit.Framework.Assert.IsTrue(ILOG.J2CsMapping.Collections.Arrays.Equals(f.GetFormats(), new String[] { "0", "1" }), "Incorrect formats"); // Regression for Harmony 540 double[] choiceLimits = { -1, 0, 1, ChoiceFormat.NextDouble(1) }; String[] choiceFormats = { "is negative", "is zero or fraction", "is one", "is more than 1" }; f = new ChoiceFormat(""); f.ApplyPattern("-1#is negative|0#is zero or fraction|1#is one|1<is more than 1"); NUnit.Framework.Assert.IsTrue(ILOG.J2CsMapping.Collections.Arrays.Equals(f.GetLimits(), choiceLimits), "Incorrect limits"); NUnit.Framework.Assert.IsTrue(ILOG.J2CsMapping.Collections.Arrays.Equals(f.GetFormats(), choiceFormats), "Incorrect formats"); f = new ChoiceFormat(""); try { f.ApplyPattern("-1#is negative|0#is zero or fraction|-1#is one|1<is more than 1"); NUnit.Framework.Assert.Fail("Expected IllegalArgumentException"); } catch (ArgumentException e) { // Expected } f = new ChoiceFormat(""); try { f.ApplyPattern("-1is negative|0#is zero or fraction|1#is one|1<is more than 1"); NUnit.Framework.Assert.Fail("Expected IllegalArgumentException"); } catch (ArgumentException e_0) { // Expected } f = new ChoiceFormat(""); f.ApplyPattern("-1<is negative|0#is zero or fraction|1#is one|1<is more than 1"); choiceLimits[0] = ChoiceFormat.NextDouble(-1); NUnit.Framework.Assert.IsTrue(ILOG.J2CsMapping.Collections.Arrays.Equals(f.GetLimits(), choiceLimits), "Incorrect limits"); NUnit.Framework.Assert.IsTrue(ILOG.J2CsMapping.Collections.Arrays.Equals(f.GetFormats(), choiceFormats), "Incorrect formats"); f = new ChoiceFormat(""); f.ApplyPattern("-1#is negative|0#is zero or fraction|1#is one|1<is more than 1"); String str = "org.apache.harmony.tests.java.text.ChoiceFormat"; f.ApplyPattern(str); String ptrn = f.ToPattern(); NUnit.Framework.Assert.AreEqual(0, ptrn.Length, "Return value should be empty string for invalid pattern"); }
public void Test_parseLjava_lang_StringLjava_text_ParsePosition() { // Test for method java.lang.Number // java.text.ChoiceFormat.parse(java.lang.String, // java.text.ParsePosition) ChoiceFormat format = new ChoiceFormat("1#one|2#two|3#three"); NUnit.Framework.Assert.AreEqual(Double.NaN, System.Convert.ToDouble(format.Parse("One", new ParsePosition(0))), "Case insensitive"); ParsePosition pos = new ParsePosition(0); object result = f1.Parse("Greater than two", pos); NUnit.Framework.Assert.IsTrue(result is Double, "Not a Double1"); NUnit.Framework.Assert.IsTrue(Convert.ToDouble(result) == ChoiceFormat.NextDouble(2), "Wrong value ~>2"); NUnit.Framework.Assert.AreEqual(16, pos.GetIndex(), "Wrong position ~16"); pos = new ParsePosition(0); NUnit.Framework.Assert.IsTrue(Double.IsNaN(Convert.ToDouble(f1.Parse("12one", pos))), "Incorrect result"); NUnit.Framework.Assert.AreEqual(0, pos.GetIndex(), "Wrong position ~0"); pos = new ParsePosition(2); result = f1.Parse("12one and two", pos); NUnit.Framework.Assert.IsTrue(result is Double, "Not a Double2"); NUnit.Framework.Assert.AreEqual(1.0D, Convert.ToDouble(result), 0.0D, "Ignored parse position"); NUnit.Framework.Assert.AreEqual(5, pos.GetIndex(), "Wrong position ~5"); }