1 10 11 package com.triactive.jdo.util.test; 12 13 import com.triactive.jdo.util.SQLFormat; 14 import java.math.BigDecimal ; 15 import java.math.BigInteger ; 16 import java.util.Random ; 17 import junit.framework.TestCase; 18 19 20 26 27 public class SQLFormatTest extends TestCase 28 { 29 35 36 public SQLFormatTest(String name) 37 { 38 super(name); 39 } 40 41 42 private static final String [][] CUSTOM_CASES = 43 { 44 { "0", "0" }, 45 { "12.34", "12.34" }, 46 { "1.234", "1234e-3" }, 47 { ".1234E12", "123400000000" }, 48 { "-.1234", "-1234e-4" }, 49 { "1234", ".1234e+4" }, 50 { ".75E10", ".75e+10" }, 51 { "-.75E10", "-7.5e+9" }, 52 { ".5E-9", "5e-10" } 53 }; 54 55 public void testCustomValues() throws Throwable 56 { 57 for (int i = 0; i < CUSTOM_CASES.length; ++i) 58 assertEquals(CUSTOM_CASES[i][0], SQLFormat.format(new BigDecimal (CUSTOM_CASES[i][1]))); 59 } 60 61 62 private static final int NUM_RANDOM_CASES = 5000; 63 64 public void testRandomValues() throws Throwable 65 { 66 Random rnd = new Random (0L); 67 68 for (int i = 0; i < NUM_RANDOM_CASES; ++i) 69 { 70 BigDecimal bd1 = new BigDecimal (new BigInteger (128, rnd), rnd.nextInt(100)); 71 String s = SQLFormat.format(bd1); 72 BigDecimal bd2 = new BigDecimal (SQLFormat.format(bd1)); 73 74 assertEquals("Formatting " + bd1 + " yielded " + s + " which doesn't equal", 0, bd1.compareTo(bd2)); 75 } 76 } 77 } 78 | Popular Tags |