1 42 43 package org.jfree.data.xy.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 52 import junit.framework.Test; 53 import junit.framework.TestCase; 54 import junit.framework.TestSuite; 55 56 import org.jfree.data.xy.XYIntervalDataItem; 57 58 61 public class XYIntervalDataItemTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(XYIntervalDataItemTests.class); 70 } 71 72 77 public XYIntervalDataItemTests(String name) { 78 super(name); 79 } 80 81 private static final double EPSILON = 0.000000001; 82 85 public void testConstructor1() { 86 XYIntervalDataItem item1 = new XYIntervalDataItem(1.0, 0.5, 1.5, 2.0, 87 1.9, 2.1); 88 assertEquals(new Double (1.0), item1.getX()); 89 assertEquals(0.5, item1.getXLowValue(), EPSILON); 90 assertEquals(1.5, item1.getXHighValue(), EPSILON); 91 assertEquals(2.0, item1.getYValue(), EPSILON); 92 assertEquals(1.9, item1.getYLowValue(), EPSILON); 93 assertEquals(2.1, item1.getYHighValue(), EPSILON); 94 } 95 96 99 public void testEquals() { 100 XYIntervalDataItem item1 = new XYIntervalDataItem(1.0, 0.5, 1.5, 2.0, 101 1.9, 2.1); 102 XYIntervalDataItem item2 = new XYIntervalDataItem(1.0, 0.5, 1.5, 2.0, 103 1.9, 2.1); 104 assertTrue(item1.equals(item2)); 105 assertTrue(item2.equals(item1)); 106 107 item1 = new XYIntervalDataItem(1.1, 0.5, 1.5, 2.0, 1.9, 2.1); 109 assertFalse(item1.equals(item2)); 110 item2 = new XYIntervalDataItem(1.1, 0.5, 1.5, 2.0, 1.9, 2.1); 111 assertTrue(item1.equals(item2)); 112 113 item1 = new XYIntervalDataItem(1.1, 0.55, 1.5, 2.0, 1.9, 2.1); 115 assertFalse(item1.equals(item2)); 116 item2 = new XYIntervalDataItem(1.1, 0.55, 1.5, 2.0, 1.9, 2.1); 117 assertTrue(item1.equals(item2)); 118 119 item1 = new XYIntervalDataItem(1.1, 0.55, 1.55, 2.0, 1.9, 2.1); 121 assertFalse(item1.equals(item2)); 122 item2 = new XYIntervalDataItem(1.1, 0.55, 1.55, 2.0, 1.9, 2.1); 123 assertTrue(item1.equals(item2)); 124 125 item1 = new XYIntervalDataItem(1.1, 0.55, 1.55, 2.2, 1.9, 2.1); 127 assertFalse(item1.equals(item2)); 128 item2 = new XYIntervalDataItem(1.1, 0.55, 1.55, 2.2, 1.9, 2.1); 129 assertTrue(item1.equals(item2)); 130 131 item1 = new XYIntervalDataItem(1.1, 0.55, 1.55, 2.2, 1.99, 2.1); 133 assertFalse(item1.equals(item2)); 134 item2 = new XYIntervalDataItem(1.1, 0.55, 1.55, 2.2, 1.99, 2.1); 135 assertTrue(item1.equals(item2)); 136 137 item1 = new XYIntervalDataItem(1.1, 0.55, 1.55, 2.2, 1.99, 2.11); 139 assertFalse(item1.equals(item2)); 140 item2 = new XYIntervalDataItem(1.1, 0.55, 1.55, 2.2, 1.99, 2.11); 141 assertTrue(item1.equals(item2)); 142 } 143 144 147 public void testCloning() { 148 XYIntervalDataItem item1 = new XYIntervalDataItem(1.0, 0.5, 1.5, 2.0, 149 1.9, 2.1); 150 XYIntervalDataItem item2 = null; 151 try { 152 item2 = (XYIntervalDataItem) item1.clone(); 153 } 154 catch (CloneNotSupportedException e) { 155 e.printStackTrace(); 156 } 157 assertTrue(item1 != item2); 158 assertTrue(item1.getClass() == item2.getClass()); 159 assertTrue(item1.equals(item2)); 160 } 161 162 165 public void testSerialization() { 166 XYIntervalDataItem item1 = new XYIntervalDataItem(1.0, 0.5, 1.5, 2.0, 167 1.9, 2.1); 168 XYIntervalDataItem item2 = null; 169 try { 170 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 171 ObjectOutput out = new ObjectOutputStream (buffer); 172 out.writeObject(item1); 173 out.close(); 174 175 ObjectInput in = new ObjectInputStream ( 176 new ByteArrayInputStream (buffer.toByteArray())); 177 item2 = (XYIntervalDataItem) in.readObject(); 178 in.close(); 179 } 180 catch (Exception e) { 181 e.printStackTrace(); 182 } 183 assertEquals(item1, item2); 184 } 185 186 } 187 | Popular Tags |