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.MeanAndStandardDeviation; 57 58 61 public class MeanAndStandardDeviationTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(MeanAndStandardDeviationTests.class); 70 } 71 72 77 public MeanAndStandardDeviationTests(String name) { 78 super(name); 79 } 80 81 84 public void testEquals() { 85 MeanAndStandardDeviation m1 = new MeanAndStandardDeviation(1.2, 3.4); 86 MeanAndStandardDeviation m2 = new MeanAndStandardDeviation(1.2, 3.4); 87 assertTrue(m1.equals(m2)); 88 assertTrue(m2.equals(m1)); 89 90 m1 = new MeanAndStandardDeviation(1.0, 3.4); 91 assertFalse(m1.equals(m2)); 92 m2 = new MeanAndStandardDeviation(1.0, 3.4); 93 assertTrue(m1.equals(m2)); 94 95 m1 = new MeanAndStandardDeviation(1.0, 3.0); 96 assertFalse(m1.equals(m2)); 97 m2 = new MeanAndStandardDeviation(1.0, 3.0); 98 assertTrue(m1.equals(m2)); 99 } 100 101 104 public void testCloning() { 105 MeanAndStandardDeviation m1 = new MeanAndStandardDeviation(1.2, 3.4); 106 assertFalse(m1 instanceof Cloneable ); 107 } 108 109 112 public void testSerialization() { 113 MeanAndStandardDeviation m1 = new MeanAndStandardDeviation(1.2, 3.4); 114 MeanAndStandardDeviation m2 = null; 115 116 try { 117 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 118 ObjectOutput out = new ObjectOutputStream (buffer); 119 out.writeObject(m1); 120 out.close(); 121 122 ObjectInput in = new ObjectInputStream ( 123 new ByteArrayInputStream (buffer.toByteArray()) 124 ); 125 m2 = (MeanAndStandardDeviation) in.readObject(); 126 in.close(); 127 } 128 catch (Exception e) { 129 System.out.println(e.toString()); 130 } 131 assertEquals(m1, m2); 132 133 } 134 } 135 | Popular Tags |