001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2007, 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: * ValueAxisTests.java
029: * -------------------
030: * (C) Copyright 2003-2007, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: ValueAxisTests.java,v 1.1.2.3 2007/03/22 12:30:30 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 13-Aug-2003 : Version 1 (DG);
040: * 22-Mar-2007 : Extended testEquals() for new field (DG);
041: *
042: */
043:
044: package org.jfree.chart.axis.junit;
045:
046: import java.awt.BasicStroke;
047: import java.awt.Color;
048: import java.awt.Stroke;
049:
050: import junit.framework.Test;
051: import junit.framework.TestCase;
052: import junit.framework.TestSuite;
053:
054: import org.jfree.chart.ChartFactory;
055: import org.jfree.chart.JFreeChart;
056: import org.jfree.chart.axis.NumberAxis;
057: import org.jfree.chart.axis.ValueAxis;
058: import org.jfree.chart.plot.PlotOrientation;
059: import org.jfree.chart.plot.XYPlot;
060: import org.jfree.data.Range;
061: import org.jfree.data.xy.XYSeries;
062: import org.jfree.data.xy.XYSeriesCollection;
063:
064: /**
065: * Tests for the {@link ValueAxis} class.
066: */
067: public class ValueAxisTests extends TestCase {
068:
069: private static final double EPSILON = 0.000000001;
070:
071: /**
072: * Returns the tests as a test suite.
073: *
074: * @return The test suite.
075: */
076: public static Test suite() {
077: return new TestSuite(ValueAxisTests.class);
078: }
079:
080: /**
081: * Constructs a new set of tests.
082: *
083: * @param name the name of the tests.
084: */
085: public ValueAxisTests(String name) {
086: super (name);
087: }
088:
089: /**
090: * Confirm that cloning works.
091: */
092: public void testCloning() {
093: ValueAxis a1 = new NumberAxis("Test");
094: ValueAxis a2 = null;
095: try {
096: a2 = (NumberAxis) a1.clone();
097: } catch (CloneNotSupportedException e) {
098: e.printStackTrace();
099: }
100: assertTrue(a1 != a2);
101: assertTrue(a1.getClass() == a2.getClass());
102: assertTrue(a1.equals(a2));
103: }
104:
105: /**
106: * Confirm that the equals method can distinguish all the required fields.
107: */
108: public void testEquals() {
109:
110: NumberAxis a1 = new NumberAxis("Test");
111: NumberAxis a2 = new NumberAxis("Test");
112: assertTrue(a1.equals(a2));
113:
114: // axis line visible flag...
115: a1.setAxisLineVisible(false);
116: assertFalse(a1.equals(a2));
117: a2.setAxisLineVisible(false);
118: assertTrue(a1.equals(a2));
119:
120: // positiveArrowVisible;
121: a1.setPositiveArrowVisible(true);
122: assertFalse(a1.equals(a2));
123: a2.setPositiveArrowVisible(true);
124: assertTrue(a1.equals(a2));
125:
126: // negativeArrowVisible;
127: a1.setNegativeArrowVisible(true);
128: assertFalse(a1.equals(a2));
129: a2.setNegativeArrowVisible(true);
130: assertTrue(a1.equals(a2));
131:
132: //private Shape upArrow;
133:
134: //private Shape downArrow;
135:
136: //private Shape leftArrow;
137:
138: //private Shape rightArrow;
139:
140: // axisLinePaint
141: a1.setAxisLinePaint(Color.blue);
142: assertFalse(a1.equals(a2));
143: a2.setAxisLinePaint(Color.blue);
144: assertTrue(a1.equals(a2));
145:
146: // axisLineStroke
147: Stroke stroke = new BasicStroke(2.0f);
148: a1.setAxisLineStroke(stroke);
149: assertFalse(a1.equals(a2));
150: a2.setAxisLineStroke(stroke);
151: assertTrue(a1.equals(a2));
152:
153: // inverted
154: a1.setInverted(true);
155: assertFalse(a1.equals(a2));
156: a2.setInverted(true);
157: assertTrue(a1.equals(a2));
158:
159: // range
160: a1.setRange(new Range(50.0, 75.0));
161: assertFalse(a1.equals(a2));
162: a2.setRange(new Range(50.0, 75.0));
163: assertTrue(a1.equals(a2));
164:
165: // autoRange
166: a1.setAutoRange(true);
167: assertFalse(a1.equals(a2));
168: a2.setAutoRange(true);
169: assertTrue(a1.equals(a2));
170:
171: // autoRangeMinimumSize
172: a1.setAutoRangeMinimumSize(3.33);
173: assertFalse(a1.equals(a2));
174: a2.setAutoRangeMinimumSize(3.33);
175: assertTrue(a1.equals(a2));
176:
177: a1.setDefaultAutoRange(new Range(1.2, 3.4));
178: assertFalse(a1.equals(a2));
179: a2.setDefaultAutoRange(new Range(1.2, 3.4));
180: assertTrue(a1.equals(a2));
181:
182: // upperMargin
183: a1.setUpperMargin(0.09);
184: assertFalse(a1.equals(a2));
185: a2.setUpperMargin(0.09);
186: assertTrue(a1.equals(a2));
187:
188: // lowerMargin
189: a1.setLowerMargin(0.09);
190: assertFalse(a1.equals(a2));
191: a2.setLowerMargin(0.09);
192: assertTrue(a1.equals(a2));
193:
194: //private double fixedAutoRange;
195: a1.setFixedAutoRange(50.0);
196: assertFalse(a1.equals(a2));
197: a2.setFixedAutoRange(50.0);
198: assertTrue(a1.equals(a2));
199:
200: //private boolean autoTickUnitSelection;
201: a1.setAutoTickUnitSelection(false);
202: assertFalse(a1.equals(a2));
203: a2.setAutoTickUnitSelection(false);
204: assertTrue(a1.equals(a2));
205:
206: //private TickUnits standardTickUnits;
207: a1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
208: assertFalse(a1.equals(a2));
209: a2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
210: assertTrue(a1.equals(a2));
211:
212: // verticalTickLabels
213: a1.setVerticalTickLabels(true);
214: assertFalse(a1.equals(a2));
215: a2.setVerticalTickLabels(true);
216: assertTrue(a1.equals(a2));
217:
218: //private int autoTickIndex;
219: //protected double reservedForTickLabels;
220: //protected double reservedForAxisLabel;
221:
222: }
223:
224: /**
225: * Tests the the lower and upper margin settings produce the expected
226: * results.
227: */
228: public void testAxisMargins() {
229: XYSeries series = new XYSeries("S1");
230: series.add(100.0, 1.1);
231: series.add(200.0, 2.2);
232: XYSeriesCollection dataset = new XYSeriesCollection(series);
233: dataset.setIntervalWidth(0.0);
234: JFreeChart chart = ChartFactory.createScatterPlot("Title", "X",
235: "Y", dataset, PlotOrientation.VERTICAL, false, false,
236: false);
237: ValueAxis domainAxis = ((XYPlot) chart.getPlot())
238: .getDomainAxis();
239: Range r = domainAxis.getRange();
240: assertEquals(110.0, r.getLength(), EPSILON);
241: domainAxis.setLowerMargin(0.10);
242: domainAxis.setUpperMargin(0.10);
243: r = domainAxis.getRange();
244: assertEquals(120.0, r.getLength(), EPSILON);
245: }
246:
247: }
|