commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject cvs commit: jakarta-commons/math/src/test/org/apache/commons/math/stat/univariate SummaryStatisticsImplTest.java
Date Thu, 17 Jun 2004 23:16:41 GMT
psteitz     2004/06/17 16:16:41

  Modified:    math/src/test/org/apache/commons/math/stat/univariate
                        SummaryStatisticsImplTest.java
  Log:
  Added tests for serialization, equals and hashcode.
  
  Revision  Changes    Path
  1.2       +63 -1     jakarta-commons/math/src/test/org/apache/commons/math/stat/univariate/SummaryStatisticsImplTest.java
  
  Index: SummaryStatisticsImplTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/stat/univariate/SummaryStatisticsImplTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SummaryStatisticsImplTest.java	16 Jun 2004 03:36:12 -0000	1.1
  +++ SummaryStatisticsImplTest.java	17 Jun 2004 23:16:41 -0000	1.2
  @@ -157,6 +157,68 @@
           verifySummary(summary);     
       }
       
  +    public void testSerialization() {
  +        // Empty test
  +        TestUtils.checkSerializedEquality(u);
  +        SummaryStatistics s = (SummaryStatistics) TestUtils.serializeAndRecover(u);
  +        StatisticalSummary summary = s.getSummary();
  +        verifySummary(summary);
  +        
  +        // Add some data
  +        u.addValue(2d);
  +        u.addValue(1d);
  +        u.addValue(3d);
  +        u.addValue(4d);
  +        u.addValue(5d);
  +        
  +        // Test again
  +        TestUtils.checkSerializedEquality(u);
  +        s = (SummaryStatistics) TestUtils.serializeAndRecover(u);
  +        summary = s.getSummary();
  +        verifySummary(summary);
  +        
  +    }
  +    
  +    public void testEqualsAndHashCode() {
  +        SummaryStatistics t = null;
  +        int emptyHash = u.hashCode();
  +        assertTrue("reflexive", u.equals(u));
  +        assertFalse("non-null compared to null", u.equals(t));
  +        assertFalse("wrong type", u.equals(new Double(0)));
  +        t = SummaryStatistics.newInstance();
  +        assertTrue("empty instances should be equal", t.equals(u));
  +        assertTrue("empty instances should be equal", u.equals(t));
  +        assertEquals("empty hash code", emptyHash, t.hashCode());
  +        
  +        // Add some data to u
  +        u.addValue(2d);
  +        u.addValue(1d);
  +        u.addValue(3d);
  +        u.addValue(4d);
  +        assertFalse("different n's should make instances not equal", t.equals(u));
  +        assertFalse("different n's should make instances not equal", u.equals(t));
  +        assertTrue("different n's should make hashcodes different", 
  +                u.hashCode() != t.hashCode());
  +        
  +        //Add data in different order to t, should not affect identity or hashcode
  +        t.addValue(4d);
  +        t.addValue(2d);
  +        t.addValue(3d);
  +        t.addValue(1d);
  +        assertTrue("summaries based on same data should be equal", t.equals(u));
  +        assertTrue("summaries based on same data should be equal", u.equals(t));
  +        assertEquals("summaries based on same data should have same hashcodes", 
  +                u.hashCode(), t.hashCode());   
  +        
  +        // Clear and make sure summaries are indistinguishable from empty summary
  +        u.clear();
  +        t.clear();
  +        assertTrue("empty instances should be equal", t.equals(u));
  +        assertTrue("empty instances should be equal", u.equals(t));
  +        assertEquals("empty hash code", emptyHash, t.hashCode());
  +        assertEquals("empty hash code", emptyHash, u.hashCode());
  +    }
  +    
       private void verifySummary(StatisticalSummary s) {
           assertEquals("N",s.getN(),u.getN());
           TestUtils.assertEquals("sum",s.getSum(),u.getSum(),tolerance);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message