1 41 42 package org.jfree.chart.plot.junit; 43 44 import java.awt.BasicStroke ; 45 import java.awt.Color ; 46 import java.awt.Stroke ; 47 import java.io.ByteArrayInputStream ; 48 import java.io.ByteArrayOutputStream ; 49 import java.io.ObjectInput ; 50 import java.io.ObjectInputStream ; 51 import java.io.ObjectOutput ; 52 import java.io.ObjectOutputStream ; 53 54 import junit.framework.Test; 55 import junit.framework.TestCase; 56 import junit.framework.TestSuite; 57 58 import org.jfree.chart.axis.NumberAxis; 59 import org.jfree.chart.axis.ValueAxis; 60 import org.jfree.chart.plot.FastScatterPlot; 61 62 65 public class FastScatterPlotTests extends TestCase { 66 67 72 public static Test suite() { 73 return new TestSuite(FastScatterPlotTests.class); 74 } 75 76 81 public FastScatterPlotTests(String name) { 82 super(name); 83 } 84 85 88 public void testEquals() { 89 90 FastScatterPlot plot1 = new FastScatterPlot(); 91 FastScatterPlot plot2 = new FastScatterPlot(); 92 assertTrue(plot1.equals(plot2)); 93 assertTrue(plot2.equals(plot1)); 94 95 plot1.setPaint(Color.yellow); 96 assertFalse(plot1.equals(plot2)); 97 plot2.setPaint(Color.yellow); 98 assertTrue(plot1.equals(plot2)); 99 100 plot1.setDomainGridlinesVisible(false); 101 assertFalse(plot1.equals(plot2)); 102 plot2.setDomainGridlinesVisible(false); 103 assertTrue(plot1.equals(plot2)); 104 105 plot1.setDomainGridlinePaint(Color.red); 106 assertFalse(plot1.equals(plot2)); 107 plot2.setDomainGridlinePaint(Color.red); 108 assertTrue(plot1.equals(plot2)); 109 110 Stroke s = new BasicStroke (1.5f); 111 plot1.setDomainGridlineStroke(s); 112 assertFalse(plot1.equals(plot2)); 113 plot2.setDomainGridlineStroke(s); 114 assertTrue(plot1.equals(plot2)); 115 116 plot1.setRangeGridlinesVisible(false); 117 assertFalse(plot1.equals(plot2)); 118 plot2.setRangeGridlinesVisible(false); 119 assertTrue(plot1.equals(plot2)); 120 121 plot1.setRangeGridlinePaint(Color.red); 122 assertFalse(plot1.equals(plot2)); 123 plot2.setRangeGridlinePaint(Color.red); 124 assertTrue(plot1.equals(plot2)); 125 126 Stroke s2 = new BasicStroke (1.5f); 127 plot1.setRangeGridlineStroke(s2); 128 assertFalse(plot1.equals(plot2)); 129 plot2.setRangeGridlineStroke(s2); 130 assertTrue(plot1.equals(plot2)); 131 132 } 133 134 137 public void testCloning() { 138 FastScatterPlot p1 = new FastScatterPlot(); 139 FastScatterPlot p2 = null; 140 try { 141 p2 = (FastScatterPlot) p1.clone(); 142 } 143 catch (CloneNotSupportedException e) { 144 e.printStackTrace(); 145 System.err.println("Failed to clone."); 146 } 147 assertTrue(p1 != p2); 148 assertTrue(p1.getClass() == p2.getClass()); 149 assertTrue(p1.equals(p2)); 150 } 151 152 155 public void testSerialization() { 156 157 float[][] data = createData(); 158 159 ValueAxis domainAxis = new NumberAxis("X"); 160 ValueAxis rangeAxis = new NumberAxis("Y"); 161 FastScatterPlot p1 = new FastScatterPlot(data, domainAxis, rangeAxis); 162 FastScatterPlot p2 = null; 163 164 try { 165 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 166 ObjectOutput out = new ObjectOutputStream (buffer); 167 out.writeObject(p1); 168 out.close(); 169 170 ObjectInput in = new ObjectInputStream ( 171 new ByteArrayInputStream (buffer.toByteArray()) 172 ); 173 p2 = (FastScatterPlot) in.readObject(); 174 in.close(); 175 } 176 catch (Exception e) { 177 System.out.println(e.toString()); 178 } 179 assertEquals(p1, p2); 180 181 } 182 183 188 private float[][] createData() { 189 190 float[][] result = new float[2][1000]; 191 for (int i = 0; i < result[0].length; i++) { 192 193 float x = (float) i + 100; 194 result[0][i] = x; 195 result[1][i] = 100 + (float) Math.random() * 1000; 196 } 197 return result; 198 199 } 200 201 } 202 | Popular Tags |