KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > util > test > SQLFormatTest


1 /*
2  * Copyright 2002 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: SQLFormatTest.java,v 1.3 2002/11/08 05:06:28 jackknifebarber Exp $
9  */

10
11 package com.triactive.jdo.util.test;
12
13 import com.triactive.jdo.util.SQLFormat;
14 import java.math.BigDecimal JavaDoc;
15 import java.math.BigInteger JavaDoc;
16 import java.util.Random JavaDoc;
17 import junit.framework.TestCase;
18
19
20 /**
21  * Tests the functionality of {@link SQLFormat}.
22  *
23  * @author <a HREF="mailto:mmartin5@austin.rr.com">Mike Martin</a>
24  * @version $Revision: 1.3 $
25  */

26
27 public class SQLFormatTest extends TestCase
28 {
29     /**
30      * Used by the JUnit framework to construct tests. Normally, programmers
31      * would never explicitly use this constructor.
32      *
33      * @param name Name of the <tt>TestCase</tt>.
34      */

35
36     public SQLFormatTest(String JavaDoc name)
37     {
38         super(name);
39     }
40
41
42     private static final String JavaDoc[][] 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 JavaDoc
56     {
57         for (int i = 0; i < CUSTOM_CASES.length; ++i)
58             assertEquals(CUSTOM_CASES[i][0], SQLFormat.format(new BigDecimal JavaDoc(CUSTOM_CASES[i][1])));
59     }
60
61
62     private static final int NUM_RANDOM_CASES = 5000;
63
64     public void testRandomValues() throws Throwable JavaDoc
65     {
66         Random JavaDoc rnd = new Random JavaDoc(0L);
67
68         for (int i = 0; i < NUM_RANDOM_CASES; ++i)
69         {
70             BigDecimal JavaDoc bd1 = new BigDecimal JavaDoc(new BigInteger JavaDoc(128, rnd), rnd.nextInt(100));
71             String JavaDoc s = SQLFormat.format(bd1);
72             BigDecimal JavaDoc bd2 = new BigDecimal JavaDoc(SQLFormat.format(bd1));
73
74             assertEquals("Formatting " + bd1 + " yielded " + s + " which doesn't equal", 0, bd1.compareTo(bd2));
75         }
76     }
77 }
78
Popular Tags