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"); assertEquals("Case insensitive", 0, (int)format .Parse("One", new ParsePosition(0))); ParsePosition pos = new ParsePosition(0); //Number result = f1.Parse("Greater than two", pos); double result = f1.Parse("Greater than two", pos); //assertTrue("Not a Double1", result is Double); // In .NET, double is a value type assertTrue("Wrong value ~>2", result == ChoiceFormat .NextDouble(2)); assertEquals("Wrong position ~16", 16, pos.Index); pos = new ParsePosition(0); assertTrue("Incorrect result", double.IsNaN(f1.Parse("12one", pos))); assertEquals("Wrong position ~0", 0, pos.Index); pos = new ParsePosition(2); result = f1.Parse("12one and two", pos); //assertTrue("Not a Double2", result is Double); // In .NET, double is a value type assertEquals("Ignored parse position", 1.0D, result, 0.0D); assertEquals("Wrong position ~5", 5, pos.Index); }
public void test_nextDoubleDZ() { // Test for method double java.text.ChoiceFormat.nextDouble(double, // boolean) assertTrue("Not greater 0", ChoiceFormat.NextDouble(0, true) > 0); assertTrue("Not less 0", ChoiceFormat.NextDouble(0, false) < 0); }
public void test_nextDoubleD() { // Test for method double java.text.ChoiceFormat.nextDouble(double) assertTrue("Not greater 5", ChoiceFormat.NextDouble(5) > 5); assertTrue("Not greater 0", ChoiceFormat.NextDouble(0) > 0); assertTrue("Not greater -5", ChoiceFormat.NextDouble(-5) > -5); assertTrue("Not NaN", double.IsNaN(ChoiceFormat.NextDouble(double.NaN))); }
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); assertTrue("Apples should not equal oranges", !appleChoiceFormat .Equals(orangeChoiceFormat)); assertTrue("Different limit list--should not appear as equal", !orangeChoiceFormat.Equals(hybridChoiceFormat)); assertTrue("Different format list--should not appear as equal", !appleChoiceFormat.Equals(hybridChoiceFormat)); assertTrue("Should be equal--identical format", appleChoiceFormat .Equals(appleChoiceFormat)); assertTrue("Should be equals--same limits, same formats", orangeChoiceFormat.Equals(orangeChoiceFormat2)); ChoiceFormat f2 = new ChoiceFormat( "0#Less than one|1#one|1<Between one and two|2<Greater than two"); assertTrue("Not equal", f1.Equals(f2)); }
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"); assertTrue("Incorrect limits", Array.Equals(f.GetLimits(), new double[] { 0, 1 })); assertTrue("Incorrect formats", Array.Equals(f.GetFormats(), new string[] { "0", "1" })); //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"); assertTrue("Incorrect limits", Array.Equals(f.GetLimits(), choiceLimits)); assertTrue("Incorrect formats", Array.Equals(f.GetFormats(), choiceFormats)); f = new ChoiceFormat(""); try { f.ApplyPattern("-1#is negative|0#is zero or fraction|-1#is one|1<is more than 1"); 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"); fail("Expected IllegalArgumentException"); } catch (ArgumentException e) { // 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); assertTrue("Incorrect limits", Array.Equals(f.GetLimits(), choiceLimits)); assertTrue("Incorrect formats", Array.Equals(f.GetFormats(), choiceFormats)); 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(); assertEquals("Return value should be empty string for invalid pattern", 0, ptrn.Length); }