public void test_getFormats() { // Test for method java.lang.Object [] // java.text.ChoiceFormat.getFormats() String[] orgFormats = (String[])formats.Clone(); String[] f = (String[])f1.GetFormats(); assertTrue("Wrong formats", f.Equals(formats)); f[0] = "Modified"; assertTrue("Formats copied", !f.Equals(orgFormats)); }
public void test_setChoices_D_Ljava_lang_String() { // Test for method void java.text.ChoiceFormat.setChoices(double [], // java.lang.String []) ChoiceFormat f = (ChoiceFormat)f1.Clone(); double[] l = new double[] { 0, 1 }; String[] fs = new String[] { "0", "1" }; f.SetChoices(l, fs); assertTrue("Limits copied", f.GetLimits() == l); assertTrue("Formats copied", f.GetFormats() == fs); }
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); }