Code example for ChoiceFormat

Methods: applyPattern, getFormats, getLimits

0
        //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", java.util.Arrays.equals(f.getLimits(),
                choiceLimits));
        assertTrue("Incorrect formats", java.util.Arrays.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 (IllegalArgumentException e) {
            // Expected 
        } 
         
        f = new ChoiceFormat("");