01: /*
02: * Copyright 2002 (C) TJDO.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the TJDO License version 1.0.
06: * See the terms of the TJDO License in the documentation provided with this software.
07: *
08: * $Id: SQLFormatTest.java,v 1.3 2002/11/08 05:06:28 jackknifebarber Exp $
09: */
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: * Tests the functionality of {@link SQLFormat}.
21: *
22: * @author <a href="mailto:mmartin5@austin.rr.com">Mike Martin</a>
23: * @version $Revision: 1.3 $
24: */
25:
26: public class SQLFormatTest extends TestCase {
27: /**
28: * Used by the JUnit framework to construct tests. Normally, programmers
29: * would never explicitly use this constructor.
30: *
31: * @param name Name of the <tt>TestCase</tt>.
32: */
33:
34: public SQLFormatTest(String name) {
35: super (name);
36: }
37:
38: private static final String[][] CUSTOM_CASES = { { "0", "0" },
39: { "12.34", "12.34" }, { "1.234", "1234e-3" },
40: { ".1234E12", "123400000000" }, { "-.1234", "-1234e-4" },
41: { "1234", ".1234e+4" }, { ".75E10", ".75e+10" },
42: { "-.75E10", "-7.5e+9" }, { ".5E-9", "5e-10" } };
43:
44: public void testCustomValues() throws Throwable {
45: for (int i = 0; i < CUSTOM_CASES.length; ++i)
46: assertEquals(CUSTOM_CASES[i][0], SQLFormat
47: .format(new BigDecimal(CUSTOM_CASES[i][1])));
48: }
49:
50: private static final int NUM_RANDOM_CASES = 5000;
51:
52: public void testRandomValues() throws Throwable {
53: Random rnd = new Random(0L);
54:
55: for (int i = 0; i < NUM_RANDOM_CASES; ++i) {
56: BigDecimal bd1 = new BigDecimal(new BigInteger(128, rnd),
57: rnd.nextInt(100));
58: String s = SQLFormat.format(bd1);
59: BigDecimal bd2 = new BigDecimal(SQLFormat.format(bd1));
60:
61: assertEquals("Formatting " + bd1 + " yielded " + s
62: + " which doesn't equal", 0, bd1.compareTo(bd2));
63: }
64: }
65: }
|