01: /*
02: * The terms of the JPOX License are distributed with the software documentation.
03: */
04:
05: package org.jpox.util;
06:
07: import java.math.BigDecimal;
08: import java.math.BigInteger;
09: import java.util.Random;
10:
11: import org.jpox.util.SQLFormat;
12: import junit.framework.TestCase;
13:
14: /**
15: * Tests the functionality of {@link SQLFormat}.
16: *
17: * @author <a href="mailto:mmartin5@austin.rr.com">Mike Martin</a>
18: *
19: */
20:
21: public class SQLFormatTest extends TestCase {
22: /**
23: * Used by the JUnit framework to construct tests. Normally, programmers
24: * would never explicitly use this constructor.
25: *
26: * @param name Name of the <tt>TestCase</tt>.
27: */
28:
29: public SQLFormatTest(String name) {
30: super (name);
31: }
32:
33: private static final String[][] CUSTOM_CASES = { { "0", "0" },
34: { "12.34", "12.34" }, { "1.234", "1234e-3" },
35: { ".1234E12", "123400000000" }, { "-.1234", "-1234e-4" },
36: { "1234", ".1234e+4" }, { ".75E10", ".75e+10" },
37: { "-.75E10", "-7.5e+9" }, { ".5E-9", "5e-10" } };
38:
39: public void testCustomValues() throws Throwable {
40: for (int i = 0; i < CUSTOM_CASES.length; ++i)
41: assertEquals(CUSTOM_CASES[i][0], SQLFormat
42: .format(new BigDecimal(CUSTOM_CASES[i][1])));
43: }
44:
45: private static final int NUM_RANDOM_CASES = 5000;
46:
47: public void testRandomValues() throws Throwable {
48: Random rnd = new Random(0L);
49:
50: for (int i = 0; i < NUM_RANDOM_CASES; ++i) {
51: BigDecimal bd1 = new BigDecimal(new BigInteger(128, rnd),
52: rnd.nextInt(100));
53: String s = SQLFormat.format(bd1);
54: BigDecimal bd2 = new BigDecimal(SQLFormat.format(bd1));
55:
56: assertEquals("Formatting " + bd1 + " yielded " + s
57: + " which doesn't equal", 0, bd1.compareTo(bd2));
58: }
59: }
60: }
|