1 42 43 package org.jfree.data.time.junit; 44 45 import java.io.ByteArrayInputStream ; 46 import java.io.ByteArrayOutputStream ; 47 import java.io.ObjectInput ; 48 import java.io.ObjectInputStream ; 49 import java.io.ObjectOutput ; 50 import java.io.ObjectOutputStream ; 51 import java.util.TimeZone ; 52 53 import junit.framework.Test; 54 import junit.framework.TestCase; 55 import junit.framework.TestSuite; 56 57 import org.jfree.data.time.TimeTableXYDataset; 58 import org.jfree.data.time.Year; 59 60 63 public class TimeTableXYDatasetTests extends TestCase { 64 65 70 public static Test suite() { 71 return new TestSuite(TimeTableXYDatasetTests.class); 72 } 73 74 79 public TimeTableXYDatasetTests(String name) { 80 super(name); 81 } 82 83 private static final double DELTA = 0.0000000001; 84 85 88 public void testStandard() { 89 TimeTableXYDataset d = new TimeTableXYDataset(); 90 d.add(new Year(1999), 1.0, "Series 1"); 91 assertEquals(d.getItemCount(), 1); 92 assertEquals(d.getSeriesCount(), 1); 93 d.add(new Year(2000), 2.0, "Series 2"); 94 assertEquals(d.getItemCount(), 2); 95 assertEquals(d.getSeriesCount(), 2); 96 assertEquals(d.getYValue(0, 0), 1.0, DELTA); 97 assertTrue(Double.isNaN(d.getYValue(0, 1))); 98 assertTrue(Double.isNaN(d.getYValue(1, 0))); 99 assertEquals(d.getYValue(1, 1), 2.0, DELTA); 100 } 101 102 105 public void testGetTimePeriod() { 106 TimeTableXYDataset d = new TimeTableXYDataset(); 107 d.add(new Year(1999), 1.0, "Series 1"); 108 d.add(new Year(1998), 2.0, "Series 1"); 109 d.add(new Year(1996), 3.0, "Series 1"); 110 assertEquals(d.getTimePeriod(0), new Year(1996)); 111 assertEquals(d.getTimePeriod(1), new Year(1998)); 112 assertEquals(d.getTimePeriod(2), new Year(1999)); 113 } 114 115 118 public void testEquals() { 119 TimeTableXYDataset d1 = new TimeTableXYDataset(); 120 TimeTableXYDataset d2 = new TimeTableXYDataset(); 121 assertTrue(d1.equals(d2)); 122 assertTrue(d2.equals(d1)); 123 124 d1.add(new Year(1999), 123.4, "S1"); 125 assertFalse(d1.equals(d2)); 126 d2.add(new Year(1999), 123.4, "S1"); 127 assertTrue(d1.equals(d2)); 128 129 d1.setDomainIsPointsInTime(!d1.getDomainIsPointsInTime()); 130 assertFalse(d1.equals(d2)); 131 d2.setDomainIsPointsInTime(!d2.getDomainIsPointsInTime()); 132 assertTrue(d1.equals(d2)); 133 134 d1 = new TimeTableXYDataset(TimeZone.getTimeZone("GMT")); 135 d2 = new TimeTableXYDataset( 136 TimeZone.getTimeZone("America/Los_Angeles") 137 ); 138 assertFalse(d1.equals(d2)); 139 } 140 141 144 public void testClone() { 145 146 TimeTableXYDataset d = new TimeTableXYDataset(); 147 d.add(new Year(1999), 25.0, "Series"); 148 149 TimeTableXYDataset clone = null; 150 try { 151 clone = (TimeTableXYDataset) d.clone(); 152 } 153 catch (CloneNotSupportedException e) { 154 assertTrue(false); 155 } 156 assertTrue(clone.equals(d)); 157 158 clone.add(new Year(2004), 1.2, "SS"); 160 assertFalse(clone.equals(d)); 161 } 162 163 166 public void testSerialization() { 167 168 TimeTableXYDataset d1 = new TimeTableXYDataset(); 169 d1.add(new Year(1999), 123.4, "S1"); 170 TimeTableXYDataset d2 = null; 171 172 try { 173 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 174 ObjectOutput out = new ObjectOutputStream (buffer); 175 out.writeObject(d1); 176 out.close(); 177 178 ObjectInput in = new ObjectInputStream ( 179 new ByteArrayInputStream (buffer.toByteArray()) 180 ); 181 d2 = (TimeTableXYDataset) in.readObject(); 182 in.close(); 183 } 184 catch (Exception e) { 185 System.out.println(e.toString()); 186 } 187 assertTrue(d1.equals(d2)); 188 189 } 190 191 } 192 | Popular Tags |