1 42 43 package org.jfree.data.statistics.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.statistics.SimpleHistogramBin; 57 import org.jfree.data.statistics.SimpleHistogramDataset; 58 59 62 public class SimpleHistogramDatasetTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(SimpleHistogramDatasetTests.class); 71 } 72 73 78 public SimpleHistogramDatasetTests(String name) { 79 super(name); 80 } 81 82 85 public void testEquals() { 86 SimpleHistogramDataset d1 = new SimpleHistogramDataset("Dataset 1"); 87 SimpleHistogramDataset d2 = new SimpleHistogramDataset("Dataset 1"); 88 assertTrue(d1.equals(d2)); 89 90 d1.addBin(new SimpleHistogramBin(1.0, 2.0)); 91 assertFalse(d1.equals(d2)); 92 d2.addBin(new SimpleHistogramBin(1.0, 2.0)); 93 assertTrue(d1.equals(d2)); 94 } 95 96 99 public void testCloning() { 100 SimpleHistogramDataset d1 = new SimpleHistogramDataset("Dataset 1"); 101 SimpleHistogramDataset d2 = null; 102 try { 103 d2 = (SimpleHistogramDataset) d1.clone(); 104 } 105 catch (CloneNotSupportedException e) { 106 System.err.println("Failed to clone."); 107 } 108 assertTrue(d1 != d2); 109 assertTrue(d1.getClass() == d2.getClass()); 110 assertTrue(d1.equals(d2)); 111 112 d2.addBin(new SimpleHistogramBin(2.0, 3.0)); 114 d2.addObservation(2.3); 115 assertFalse(d1.equals(d2)); 116 } 117 118 121 public void testSerialization() { 122 123 SimpleHistogramDataset d1 = new SimpleHistogramDataset("D1"); 124 SimpleHistogramDataset d2 = null; 125 try { 126 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 127 ObjectOutput out = new ObjectOutputStream (buffer); 128 out.writeObject(d1); 129 out.close(); 130 ObjectInput in = new ObjectInputStream ( 131 new ByteArrayInputStream (buffer.toByteArray()) 132 ); 133 d2 = (SimpleHistogramDataset) in.readObject(); 134 in.close(); 135 } 136 catch (Exception e) { 137 System.out.println(e.toString()); 138 } 139 assertEquals(d1, d2); 140 } 141 142 } 143 | Popular Tags |