KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > axis > junit > ValueAxisTests


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 License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * -------------------
27  * ValueAxisTests.java
28  * -------------------
29  * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: ValueAxisTests.java,v 1.4 2005/03/16 12:10:45 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 13-Aug-2003 : Version 1 (DG);
39  *
40  */

41
42 package org.jfree.chart.axis.junit;
43
44 import java.awt.BasicStroke JavaDoc;
45 import java.awt.Color JavaDoc;
46 import java.awt.Stroke JavaDoc;
47
48 import junit.framework.Test;
49 import junit.framework.TestCase;
50 import junit.framework.TestSuite;
51
52 import org.jfree.chart.ChartFactory;
53 import org.jfree.chart.JFreeChart;
54 import org.jfree.chart.axis.NumberAxis;
55 import org.jfree.chart.axis.ValueAxis;
56 import org.jfree.chart.plot.PlotOrientation;
57 import org.jfree.data.Range;
58 import org.jfree.data.xy.XYSeries;
59 import org.jfree.data.xy.XYSeriesCollection;
60
61 /**
62  * Tests for the {@link ValueAxis} class.
63  */

64 public class ValueAxisTests extends TestCase {
65
66     private static final double EPSILON = 0.000000001;
67     
68     /**
69      * Returns the tests as a test suite.
70      *
71      * @return The test suite.
72      */

73     public static Test suite() {
74         return new TestSuite(ValueAxisTests.class);
75     }
76
77     /**
78      * Constructs a new set of tests.
79      *
80      * @param name the name of the tests.
81      */

82     public ValueAxisTests(String JavaDoc name) {
83         super(name);
84     }
85
86     /**
87      * Confirm that cloning works.
88      */

89     public void testCloning() {
90         ValueAxis a1 = new NumberAxis("Test");
91         ValueAxis a2 = null;
92         try {
93             a2 = (NumberAxis) a1.clone();
94         }
95         catch (CloneNotSupportedException JavaDoc e) {
96             System.err.println("ValueAxisTests.testCloning: failed to clone.");
97         }
98         assertTrue(a1 != a2);
99         assertTrue(a1.getClass() == a2.getClass());
100         assertTrue(a1.equals(a2));
101     }
102
103     /**
104      * Confirm that the equals method can distinguish all the required fields.
105      */

106     public void testEquals() {
107         
108         NumberAxis a1 = new NumberAxis("Test");
109         NumberAxis a2 = new NumberAxis("Test");
110         assertTrue(a1.equals(a2));
111         
112         // axis line visible flag...
113
a1.setAxisLineVisible(false);
114         assertFalse(a1.equals(a2));
115         a2.setAxisLineVisible(false);
116         assertTrue(a1.equals(a2));
117     
118         // positiveArrowVisible;
119
a1.setPositiveArrowVisible(true);
120         assertFalse(a1.equals(a2));
121         a2.setPositiveArrowVisible(true);
122         assertTrue(a1.equals(a2));
123     
124         // negativeArrowVisible;
125
a1.setNegativeArrowVisible(true);
126         assertFalse(a1.equals(a2));
127         a2.setNegativeArrowVisible(true);
128         assertTrue(a1.equals(a2));
129     
130         //private Shape upArrow;
131

132         //private Shape downArrow;
133

134         //private Shape leftArrow;
135

136         //private Shape rightArrow;
137

138         // axisLinePaint
139
a1.setAxisLinePaint(Color.blue);
140         assertFalse(a1.equals(a2));
141         a2.setAxisLinePaint(Color.blue);
142         assertTrue(a1.equals(a2));
143         
144         // axisLineStroke
145
Stroke JavaDoc stroke = new BasicStroke JavaDoc(2.0f);
146         a1.setAxisLineStroke(stroke);
147         assertFalse(a1.equals(a2));
148         a2.setAxisLineStroke(stroke);
149         assertTrue(a1.equals(a2));
150     
151         // inverted
152
a1.setInverted(true);
153         assertFalse(a1.equals(a2));
154         a2.setInverted(true);
155         assertTrue(a1.equals(a2));
156         
157         // range
158
a1.setRange(new Range(50.0, 75.0));
159         assertFalse(a1.equals(a2));
160         a2.setRange(new Range(50.0, 75.0));
161         assertTrue(a1.equals(a2));
162
163         // autoRange
164
a1.setAutoRange(true);
165         assertFalse(a1.equals(a2));
166         a2.setAutoRange(true);
167         assertTrue(a1.equals(a2));
168
169         // autoRangeMinimumSize
170
a1.setAutoRangeMinimumSize(3.33);
171         assertFalse(a1.equals(a2));
172         a2.setAutoRangeMinimumSize(3.33);
173         assertTrue(a1.equals(a2));
174
175         // upperMargin
176
a1.setUpperMargin(0.09);
177         assertFalse(a1.equals(a2));
178         a2.setUpperMargin(0.09);
179         assertTrue(a1.equals(a2));
180
181         // lowerMargin
182
a1.setLowerMargin(0.09);
183         assertFalse(a1.equals(a2));
184         a2.setLowerMargin(0.09);
185         assertTrue(a1.equals(a2));
186
187         //private double fixedAutoRange;
188
a1.setFixedAutoRange(50.0);
189         assertFalse(a1.equals(a2));
190         a2.setFixedAutoRange(50.0);
191         assertTrue(a1.equals(a2));
192
193         //private boolean autoTickUnitSelection;
194
a1.setAutoTickUnitSelection(false);
195         assertFalse(a1.equals(a2));
196         a2.setAutoTickUnitSelection(false);
197         assertTrue(a1.equals(a2));
198
199         //private TickUnits standardTickUnits;
200
a1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
201         assertFalse(a1.equals(a2));
202         a2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
203         assertTrue(a1.equals(a2));
204
205         // verticalTickLabels
206
a1.setVerticalTickLabels(true);
207         assertFalse(a1.equals(a2));
208         a2.setVerticalTickLabels(true);
209         assertTrue(a1.equals(a2));
210
211
212         //private int autoTickIndex;
213
//protected double reservedForTickLabels;
214
//protected double reservedForAxisLabel;
215

216     }
217
218     /**
219      * Tests the the lower and upper margin settings produce the expected
220      * results.
221      */

222     public void testAxisMargins() {
223         XYSeries series = new XYSeries("S1");
224         series.add(100.0, 1.1);
225         series.add(200.0, 2.2);
226         XYSeriesCollection dataset = new XYSeriesCollection(series);
227         dataset.setIntervalWidth(0.0);
228         JFreeChart chart = ChartFactory.createScatterPlot(
229             "Title", "X", "Y", dataset, PlotOrientation.VERTICAL,
230             false, false, false
231         );
232         ValueAxis domainAxis = chart.getXYPlot().getDomainAxis();
233         Range r = domainAxis.getRange();
234         assertEquals(110.0, r.getLength(), EPSILON);
235         domainAxis.setLowerMargin(0.10);
236         domainAxis.setUpperMargin(0.10);
237         r = domainAxis.getRange();
238         assertEquals(120.0, r.getLength(), EPSILON);
239     }
240     
241 }
242
Popular Tags