1 17 18 19 20 package org.apache.fop.util; 21 22 import org.apache.fop.pdf.PDFNumber; 23 24 import junit.framework.TestCase; 25 26 29 public class PDFNumberTestCase extends TestCase { 30 31 35 public void testDoubleOut1() throws Exception { 36 assertEquals("0", PDFNumber.doubleOut(0.0f)); 38 assertEquals("0", PDFNumber.doubleOut(0.0000000000000000000123f)); 39 assertEquals("0.1", PDFNumber.doubleOut(0.1f)); 40 assertEquals("100", PDFNumber.doubleOut(100.0f)); 41 assertEquals("100", PDFNumber.doubleOut(99.99999999999999999999999f)); 42 43 assertEquals("100.123459", PDFNumber.doubleOut(100.12345611111111f)); 47 assertEquals("-100.123459", PDFNumber.doubleOut(-100.12345611111111f)); 48 } 49 50 54 public void testDoubleOut2() throws Exception { 55 assertEquals("0", PDFNumber.doubleOut(0.0f, 4)); 57 assertEquals("0", PDFNumber.doubleOut(0.0000000000000000000123f, 4)); 58 assertEquals("0.1", PDFNumber.doubleOut(0.1f, 4)); 59 assertEquals("100", PDFNumber.doubleOut(100.0f, 4)); 60 assertEquals("100", PDFNumber.doubleOut(99.99999999999999999999999f, 4)); 61 assertEquals("100.1234", PDFNumber.doubleOut(100.12341111111111f, 4)); 62 assertEquals("-100.1234", PDFNumber.doubleOut(-100.12341111111111f, 4)); 63 } 64 65 69 public void testDoubleOut3() throws Exception { 70 assertEquals("0", PDFNumber.doubleOut(0.0f, 0)); 72 assertEquals("0", PDFNumber.doubleOut(0.1f, 0)); 73 assertEquals("1", PDFNumber.doubleOut(0.6f, 0)); 74 assertEquals("100", PDFNumber.doubleOut(100.1234f, 0)); 75 assertEquals("-100", PDFNumber.doubleOut(-100.1234f, 0)); 76 } 77 78 82 public void testDoubleOut4() throws Exception { 83 double d = Double.parseDouble("5.7220458984375E-6"); 84 assertEquals("0.000006", PDFNumber.doubleOut(d)); 85 assertEquals("0", PDFNumber.doubleOut(d, 4)); 86 assertEquals("0.00000572", PDFNumber.doubleOut(d, 8)); 87 } 88 89 93 public void testDoubleOutWrongParameters() throws Exception { 94 try { 95 PDFNumber.doubleOut(0.1f, -1); 96 fail("IllegalArgument expected!"); 97 } catch (IllegalArgumentException iae) { 98 } 100 try { 101 PDFNumber.doubleOut(0.1f, 17); fail("IllegalArgument expected!"); 103 } catch (IllegalArgumentException iae) { 104 } 106 try { 107 PDFNumber.doubleOut(0.1f, 98274659); 108 fail("IllegalArgument expected!"); 109 } catch (IllegalArgumentException iae) { 110 } 112 } 113 114 } 115 | Popular Tags |