KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > data > junit > DataUtilitiesTests


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * -----------------------
28  * DataUtilitiesTests.java
29  * -----------------------
30  * (C) Copyright 2005, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: DataUtilitiesTests.java,v 1.1.2.1 2006/10/03 15:41:42 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 03-Mar-2005 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.data.junit;
44
45 import junit.framework.TestCase;
46
47 import org.jfree.data.DataUtilities;
48 import org.jfree.data.DefaultKeyedValues2D;
49
50 /**
51  * Some tests for the {@link DataUtilities} class.
52  */

53 public class DataUtilitiesTests extends TestCase {
54     
55     /**
56      * Tests the createNumberArray2D() method.
57      */

58     public void testCreateNumberArray2D() {
59         double[][] d = new double[2][];
60         d[0] = new double[] {1.1, 2.2, 3.3, 4.4};
61         d[1] = new double[] {1.1, 2.2, 3.3, 4.4, 5.5};
62         Number JavaDoc[][] n = DataUtilities.createNumberArray2D(d);
63         assertEquals(2, n.length);
64         assertEquals(4, n[0].length);
65         assertEquals(5, n[1].length);
66     }
67
68     private static final double EPSILON = 0.000000001;
69     
70     /**
71      * Some checks for the calculateColumnTotal() method.
72      */

73     public void testCalculateColumnTotal() {
74         DefaultKeyedValues2D table = new DefaultKeyedValues2D();
75         table.addValue(new Double JavaDoc(1.0), "R0", "C0");
76         table.addValue(new Double JavaDoc(2.0), "R0", "C1");
77         table.addValue(new Double JavaDoc(3.0), "R1", "C0");
78         table.addValue(new Double JavaDoc(4.0), "R1", "C1");
79         assertEquals(4.0, DataUtilities.calculateColumnTotal(table, 0), EPSILON);
80         assertEquals(6.0, DataUtilities.calculateColumnTotal(table, 1), EPSILON);
81         table.setValue(null, "R1", "C1");
82         assertEquals(2.0, DataUtilities.calculateColumnTotal(table, 1), EPSILON);
83     }
84     
85     /**
86      * Some checks for the calculateRowTotal() method.
87      */

88     public void testCalculateRowTotal() {
89         DefaultKeyedValues2D table = new DefaultKeyedValues2D();
90         table.addValue(new Double JavaDoc(1.0), "R0", "C0");
91         table.addValue(new Double JavaDoc(2.0), "R0", "C1");
92         table.addValue(new Double JavaDoc(3.0), "R1", "C0");
93         table.addValue(new Double JavaDoc(4.0), "R1", "C1");
94         assertEquals(3.0, DataUtilities.calculateRowTotal(table, 0), EPSILON);
95         assertEquals(7.0, DataUtilities.calculateRowTotal(table, 1), EPSILON);
96         table.setValue(null, "R1", "C1");
97         assertEquals(3.0, DataUtilities.calculateRowTotal(table, 1), EPSILON);
98     }
99 }
100
Popular Tags