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 StorelessUnivariateStatisticAbstractTest.java
Date Thu, 17 Jun 2004 22:33:23 GMT
psteitz     2004/06/17 15:33:23

  Modified:    math/src/test/org/apache/commons/math/stat/univariate
                        StorelessUnivariateStatisticAbstractTest.java
  Log:
  Added tests for equals and hashcode.
  
  Revision  Changes    Path
  1.13      +55 -1     jakarta-commons/math/src/test/org/apache/commons/math/stat/univariate/StorelessUnivariateStatisticAbstractTest.java
  
  Index: StorelessUnivariateStatisticAbstractTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/stat/univariate/StorelessUnivariateStatisticAbstractTest.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- StorelessUnivariateStatisticAbstractTest.java	27 Apr 2004 16:42:32 -0000	1.12
  +++ StorelessUnivariateStatisticAbstractTest.java	17 Jun 2004 22:33:23 -0000	1.13
  @@ -28,10 +28,13 @@
           super(name);
       }
   
  +    /** Return a new instance of the statistic */
       public abstract UnivariateStatistic getUnivariateStatistic();
   
  +    /**Expected value for  the testArray defined in UnivariateStatisticAbstractTest */
       public abstract double expectedValue();
       
  +    /** Verify that calling increment() in a loop over testArray results in correct state
*/
       public void testIncrementation() throws Exception {
   
           StorelessUnivariateStatistic statistic =
  @@ -44,6 +47,7 @@
           }
   
           assertEquals(expectedValue(), statistic.getResult(), getTolerance());
  +        //TODO:  add test for getN() once type is fixed
   
           statistic.clear();
   
  @@ -55,6 +59,8 @@
   
           StorelessUnivariateStatistic statistic =
               (StorelessUnivariateStatistic) getUnivariateStatistic();
  +        
  +        TestUtils.checkSerializedEquality(statistic);
   
           statistic.clear();
   
  @@ -64,12 +70,60 @@
                   statistic = (StorelessUnivariateStatistic)TestUtils.serializeAndRecover(statistic);

           }
           
  +        TestUtils.checkSerializedEquality(statistic);
  +        
           assertEquals(expectedValue(), statistic.getResult(), getTolerance());
   
           statistic.clear();
   
           assertTrue(Double.isNaN(statistic.getResult()));
   
  +    }
  +    
  +    public void testEqualsAndHashCode() {
  +        StorelessUnivariateStatistic statistic =
  +            (StorelessUnivariateStatistic) getUnivariateStatistic();
  +        StorelessUnivariateStatistic statistic2 = null;
  +        
  +        assertTrue("non-null, compared to null", !statistic.equals(statistic2));
  +        assertTrue("reflexive, non-null", statistic.equals(statistic));
  +        
  +        int emptyHash = statistic.hashCode();
  +        statistic2 = (StorelessUnivariateStatistic) getUnivariateStatistic();
  +        assertTrue("empty stats should be equal", statistic.equals(statistic2));
  +        assertEquals("empty stats should have the same hashcode", 
  +                emptyHash, statistic2.hashCode());
  +        
  +        statistic.increment(1d);
  +        assertTrue("reflexive, non-empty", statistic.equals(statistic));
  +        assertTrue("non-empty, compared to empty", !statistic.equals(statistic2));
  +        assertTrue("non-empty, compared to empty", !statistic2.equals(statistic));
  +        assertTrue("non-empty stat should have different hashcode from empty stat",
  +                statistic.hashCode() != emptyHash);
  +        
  +        statistic2.increment(1d);
  +        assertTrue("stats with same data should be equal", statistic.equals(statistic2));
  +        assertEquals("stats with same data should have the same hashcode", 
  +                statistic.hashCode(), statistic2.hashCode());
  +        
  +        statistic.increment(Double.POSITIVE_INFINITY);
  +        assertTrue("stats with different n's should not be equal", !statistic2.equals(statistic));
  +        assertTrue("stats with different n's should have different hashcodes",
  +                statistic.hashCode() != statistic2.hashCode());
  +        
  +        statistic2.increment(Double.POSITIVE_INFINITY);
  +        assertTrue("stats with same data should be equal", statistic.equals(statistic2));
  +        assertEquals("stats with same data should have the same hashcode", 
  +                statistic.hashCode(), statistic2.hashCode()); 
  +        
  +        statistic.clear();
  +        statistic2.clear();
  +        assertTrue("cleared stats should be equal", statistic.equals(statistic2));
  +        assertEquals("cleared stats should have thashcode of empty stat", 
  +                emptyHash, statistic2.hashCode());
  +        assertEquals("cleared stats should have thashcode of empty stat", 
  +                emptyHash, statistic.hashCode());
  +        
       }
   
   }
  
  
  

---------------------------------------------------------------------
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