001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * -----------------------
028: * DataUtilitiesTests.java
029: * -----------------------
030: * (C) Copyright 2005, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: DataUtilitiesTests.java,v 1.1.2.1 2006/10/03 15:41:42 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 03-Mar-2005 : Version 1 (DG);
040: *
041: */
042:
043: package org.jfree.data.junit;
044:
045: import junit.framework.TestCase;
046:
047: import org.jfree.data.DataUtilities;
048: import org.jfree.data.DefaultKeyedValues2D;
049:
050: /**
051: * Some tests for the {@link DataUtilities} class.
052: */
053: public class DataUtilitiesTests extends TestCase {
054:
055: /**
056: * Tests the createNumberArray2D() method.
057: */
058: public void testCreateNumberArray2D() {
059: double[][] d = new double[2][];
060: d[0] = new double[] { 1.1, 2.2, 3.3, 4.4 };
061: d[1] = new double[] { 1.1, 2.2, 3.3, 4.4, 5.5 };
062: Number[][] n = DataUtilities.createNumberArray2D(d);
063: assertEquals(2, n.length);
064: assertEquals(4, n[0].length);
065: assertEquals(5, n[1].length);
066: }
067:
068: private static final double EPSILON = 0.000000001;
069:
070: /**
071: * Some checks for the calculateColumnTotal() method.
072: */
073: public void testCalculateColumnTotal() {
074: DefaultKeyedValues2D table = new DefaultKeyedValues2D();
075: table.addValue(new Double(1.0), "R0", "C0");
076: table.addValue(new Double(2.0), "R0", "C1");
077: table.addValue(new Double(3.0), "R1", "C0");
078: table.addValue(new Double(4.0), "R1", "C1");
079: assertEquals(4.0, DataUtilities.calculateColumnTotal(table, 0),
080: EPSILON);
081: assertEquals(6.0, DataUtilities.calculateColumnTotal(table, 1),
082: EPSILON);
083: table.setValue(null, "R1", "C1");
084: assertEquals(2.0, DataUtilities.calculateColumnTotal(table, 1),
085: EPSILON);
086: }
087:
088: /**
089: * Some checks for the calculateRowTotal() method.
090: */
091: public void testCalculateRowTotal() {
092: DefaultKeyedValues2D table = new DefaultKeyedValues2D();
093: table.addValue(new Double(1.0), "R0", "C0");
094: table.addValue(new Double(2.0), "R0", "C1");
095: table.addValue(new Double(3.0), "R1", "C0");
096: table.addValue(new Double(4.0), "R1", "C1");
097: assertEquals(3.0, DataUtilities.calculateRowTotal(table, 0),
098: EPSILON);
099: assertEquals(7.0, DataUtilities.calculateRowTotal(table, 1),
100: EPSILON);
101: table.setValue(null, "R1", "C1");
102: assertEquals(3.0, DataUtilities.calculateRowTotal(table, 1),
103: EPSILON);
104: }
105: }
|