Code example for ChoiceFormat

Methods: format

0
        // []) 
        String formattedString;
        double[] appleLimits = { 1, 2, 3, 4, 5 };
        String[] appleFormats = { "Tiny Apple", "Small Apple", "Medium Apple",
                "Large Apple", "Huge Apple" }; 
        ChoiceFormat cf = new ChoiceFormat(appleLimits, appleFormats);
 
        formattedString = cf.format(Double.NEGATIVE_INFINITY);
        assertTrue("a) Incorrect format returned: " + formattedString,
                formattedString.equals("Tiny Apple"));
        formattedString = cf.format(0.5d);
        assertTrue("b) Incorrect format returned: " + formattedString,
                formattedString.equals("Tiny Apple"));
        formattedString = cf.format(1d);
        assertTrue("c) Incorrect format returned: " + formattedString,
                formattedString.equals("Tiny Apple"));
        formattedString = cf.format(1.5d);
        assertTrue("d) Incorrect format returned: " + formattedString,
                formattedString.equals("Tiny Apple"));
        formattedString = cf.format(2d);
        assertTrue("e) Incorrect format returned: " + formattedString,
                formattedString.equals("Small Apple"));
        formattedString = cf.format(2.5d);
        assertTrue("f) Incorrect format returned: " + formattedString,
                formattedString.equals("Small Apple"));
        formattedString = cf.format(3d);
        assertTrue("g) Incorrect format returned: " + formattedString,
                formattedString.equals("Medium Apple"));
        formattedString = cf.format(4d);
        assertTrue("h) Incorrect format returned: " + formattedString,
                formattedString.equals("Large Apple"));
        formattedString = cf.format(5d);
        assertTrue("i) Incorrect format returned: " + formattedString,
                formattedString.equals("Huge Apple"));
        formattedString = cf.format(5.5d);
        assertTrue("j) Incorrect format returned: " + formattedString,
                formattedString.equals("Huge Apple"));
        formattedString = cf.format(6.0d);
        assertTrue("k) Incorrect format returned: " + formattedString,
                formattedString.equals("Huge Apple"));
        formattedString = cf.format(Double.POSITIVE_INFINITY);
        assertTrue("l) Incorrect format returned: " + formattedString,
                formattedString.equals("Huge Apple"));
    } 
 
    /**