KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * --------------------------
23  * DatasetUtilitiesTests.java
24  * --------------------------
25  * (C) Copyright 2003 by Object Refinery Limited and Contributors.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): -;
29  *
30  * $Id: DatasetUtilitiesTests.java,v 1.2 2003/10/21 10:51:25 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 18-Sep-2003 : Version 1 (DG);
35  *
36  */

37
38 package org.jfree.data.junit;
39
40 import junit.framework.Test;
41 import junit.framework.TestCase;
42 import junit.framework.TestSuite;
43
44 import org.jfree.data.DatasetUtilities;
45 import org.jfree.data.DefaultCategoryDataset;
46 import org.jfree.data.Range;
47 import org.jfree.util.NumberUtils;
48
49 /**
50  * Tests for the {@link DatasetUtilities} class.
51  *
52  * @author David Gilbert
53  */

54 public class DatasetUtilitiesTests extends TestCase {
55
56     /**
57      * Returns the tests as a test suite.
58      *
59      * @return the test suite.
60      */

61     public static Test suite() {
62         return new TestSuite(DatasetUtilitiesTests.class);
63     }
64
65     /**
66      * Constructs a new set of tests.
67      *
68      * @param name the name of the tests.
69      */

70     public DatasetUtilitiesTests(String JavaDoc name) {
71         super(name);
72     }
73
74     /**
75      * A quick test of the min and max range value methods.
76      */

77     public void testMinMaxRange() {
78         DefaultCategoryDataset dataset = new DefaultCategoryDataset();
79         dataset.addValue(100.0, "Series 1", "Type 1");
80         dataset.addValue(101.1, "Series 1", "Type 2");
81         Number JavaDoc min = DatasetUtilities.getMinimumRangeValue(dataset);
82         assertTrue(min.doubleValue() < 100.1);
83         Number JavaDoc max = DatasetUtilities.getMaximumRangeValue(dataset);
84         assertTrue(max.doubleValue() > 101.0);
85     }
86
87     /**
88      * A test to reproduce bug report 803660.
89      */

90     public void test803660() {
91         DefaultCategoryDataset dataset = new DefaultCategoryDataset();
92         dataset.addValue(100.0, "Series 1", "Type 1");
93         dataset.addValue(101.1, "Series 1", "Type 2");
94         Number JavaDoc n = DatasetUtilities.getMaximumRangeValue(dataset);
95         assertTrue(n.doubleValue() > 101.0);
96         
97     }
98     
99     /**
100      * A simple test for the cumulative range calculation. The sequence of "cumulative" values
101      * are considered to be { 0.0, 10.0, 25.0, 18.0 } so the range should be 0.0 -> 25.0.
102      */

103     public void testCumulativeRange1() {
104         DefaultCategoryDataset dataset = new DefaultCategoryDataset();
105         dataset.addValue(10.0, "Series 1", "Start");
106         dataset.addValue(15.0, "Series 1", "Delta 1");
107         dataset.addValue(-7.0, "Series 1", "Delta 2");
108         Range range = DatasetUtilities.getCumulativeRangeExtent(dataset);
109         assertTrue(NumberUtils.equal(range.getLowerBound(), 0.0));
110         assertTrue(NumberUtils.equal(range.getUpperBound(), 25.0));
111     }
112     
113     /**
114      * A further test for the cumulative range calculation.
115      */

116     public void testCumulativeRange2() {
117         DefaultCategoryDataset dataset = new DefaultCategoryDataset();
118         dataset.addValue(-21.4, "Series 1", "Start Value");
119         dataset.addValue(11.57, "Series 1", "Delta 1");
120         dataset.addValue(3.51, "Series 1", "Delta 2");
121         dataset.addValue(-12.36, "Series 1", "Delta 3");
122         dataset.addValue(3.39, "Series 1", "Delta 4");
123         dataset.addValue(38.68, "Series 1", "Delta 5");
124         dataset.addValue(-43.31, "Series 1", "Delta 6");
125         dataset.addValue(-29.59, "Series 1", "Delta 7");
126         dataset.addValue(35.30, "Series 1", "Delta 8");
127         dataset.addValue(5.0, "Series 1", "Delta 9");
128         Range range = DatasetUtilities.getCumulativeRangeExtent(dataset);
129         assertTrue(NumberUtils.equal(range.getLowerBound(), -49.51));
130         assertTrue(NumberUtils.equal(range.getUpperBound(), 23.39));
131     }
132
133 }
134
Popular Tags