1 41 42 package org.jfree.chart.axis.junit; 43 44 import java.awt.BasicStroke ; 45 import java.awt.Color ; 46 import java.awt.Stroke ; 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 64 public class ValueAxisTests extends TestCase { 65 66 private static final double EPSILON = 0.000000001; 67 68 73 public static Test suite() { 74 return new TestSuite(ValueAxisTests.class); 75 } 76 77 82 public ValueAxisTests(String name) { 83 super(name); 84 } 85 86 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 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 106 public void testEquals() { 107 108 NumberAxis a1 = new NumberAxis("Test"); 109 NumberAxis a2 = new NumberAxis("Test"); 110 assertTrue(a1.equals(a2)); 111 112 a1.setAxisLineVisible(false); 114 assertFalse(a1.equals(a2)); 115 a2.setAxisLineVisible(false); 116 assertTrue(a1.equals(a2)); 117 118 a1.setPositiveArrowVisible(true); 120 assertFalse(a1.equals(a2)); 121 a2.setPositiveArrowVisible(true); 122 assertTrue(a1.equals(a2)); 123 124 a1.setNegativeArrowVisible(true); 126 assertFalse(a1.equals(a2)); 127 a2.setNegativeArrowVisible(true); 128 assertTrue(a1.equals(a2)); 129 130 132 134 136 138 a1.setAxisLinePaint(Color.blue); 140 assertFalse(a1.equals(a2)); 141 a2.setAxisLinePaint(Color.blue); 142 assertTrue(a1.equals(a2)); 143 144 Stroke stroke = new BasicStroke (2.0f); 146 a1.setAxisLineStroke(stroke); 147 assertFalse(a1.equals(a2)); 148 a2.setAxisLineStroke(stroke); 149 assertTrue(a1.equals(a2)); 150 151 a1.setInverted(true); 153 assertFalse(a1.equals(a2)); 154 a2.setInverted(true); 155 assertTrue(a1.equals(a2)); 156 157 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 a1.setAutoRange(true); 165 assertFalse(a1.equals(a2)); 166 a2.setAutoRange(true); 167 assertTrue(a1.equals(a2)); 168 169 a1.setAutoRangeMinimumSize(3.33); 171 assertFalse(a1.equals(a2)); 172 a2.setAutoRangeMinimumSize(3.33); 173 assertTrue(a1.equals(a2)); 174 175 a1.setUpperMargin(0.09); 177 assertFalse(a1.equals(a2)); 178 a2.setUpperMargin(0.09); 179 assertTrue(a1.equals(a2)); 180 181 a1.setLowerMargin(0.09); 183 assertFalse(a1.equals(a2)); 184 a2.setLowerMargin(0.09); 185 assertTrue(a1.equals(a2)); 186 187 a1.setFixedAutoRange(50.0); 189 assertFalse(a1.equals(a2)); 190 a2.setFixedAutoRange(50.0); 191 assertTrue(a1.equals(a2)); 192 193 a1.setAutoTickUnitSelection(false); 195 assertFalse(a1.equals(a2)); 196 a2.setAutoTickUnitSelection(false); 197 assertTrue(a1.equals(a2)); 198 199 a1.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); 201 assertFalse(a1.equals(a2)); 202 a2.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); 203 assertTrue(a1.equals(a2)); 204 205 a1.setVerticalTickLabels(true); 207 assertFalse(a1.equals(a2)); 208 a2.setVerticalTickLabels(true); 209 assertTrue(a1.equals(a2)); 210 211 212 216 } 217 218 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 |