View | Details | Raw Unified | Return to bug 53327
Collapse All | Expand All

(-)test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java (+17 lines)
Lines 260-265 Link Here
260
     * whereas DecimalFormat may have some formating errors regarding the last digit.
260
     * whereas DecimalFormat may have some formating errors regarding the last digit.
261
     */
261
     */
262
    private String refFormat(double value, int decimals, int precision) {
262
    private String refFormat(double value, int decimals, int precision) {
263
        if (Double.isNaN(value) || Double.isInfinite(value)) {
264
            return Double.toString(value);
265
        }
263
        buf.setLength(0);
266
        buf.setLength(0);
264
        BigDecimal bg = new BigDecimal(Double.toString(value));
267
        BigDecimal bg = new BigDecimal(Double.toString(value));
265
        int scale = Math.abs(value) < 1.0 ? precision : decimals;
268
        int scale = Math.abs(value) < 1.0 ? precision : decimals;
Lines 515-518 Link Here
515
        long toStringDuration = System.currentTimeMillis() - start;
518
        long toStringDuration = System.currentTimeMillis() - start;
516
        System.out.println("toString duration: " + toStringDuration + "ms to format " + (3 * nbTest) + " doubles");
519
        System.out.println("toString duration: " + toStringDuration + "ms to format " + (3 * nbTest) + " doubles");
517
    }
520
    }
521
522
    public void testAllDoubleRanges() {
523
        Random r = new Random();
524
        double value;
525
        String expected, actual;
526
        for (int i = -330; i <= 315; i++) {
527
            value = r.nextDouble() * Math.pow(10.0, i);
528
            for (int scale = 1; scale <= 350; scale++) {
529
                expected = refFormat(value, scale, scale);
530
                actual = format(value, scale, scale);
531
                assertEquals(value, scale, scale, expected, actual);
532
            }
533
        }
534
    }
518
}
535
}

Return to bug 53327