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/random EmpiricalDistributionTest.java
Date Thu, 17 Jun 2004 23:51:33 GMT
psteitz     2004/06/17 16:51:33

  Modified:    math/src/test/org/apache/commons/math/random
                        EmpiricalDistributionTest.java
  Log:
  Added serialization tests.
  
  Revision  Changes    Path
  1.18      +26 -1     jakarta-commons/math/src/test/org/apache/commons/math/random/EmpiricalDistributionTest.java
  
  Index: EmpiricalDistributionTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/random/EmpiricalDistributionTest.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- EmpiricalDistributionTest.java	23 May 2004 00:30:01 -0000	1.17
  +++ EmpiricalDistributionTest.java	17 Jun 2004 23:51:33 -0000	1.18
  @@ -27,6 +27,7 @@
   import java.util.Iterator;
   
   import org.apache.commons.math.RetryTestCase;
  +import org.apache.commons.math.TestUtils;
   import org.apache.commons.math.stat.univariate.SummaryStatistics;
   
   /**
  @@ -157,6 +158,30 @@
                      // really just checking to make sure we do not bomb
           empiricalDistribution2 = new EmpiricalDistributionImpl(1);           
           tstDoubleGen(5);           
  +    }
  +    
  +    public void testSerialization() {
  +        // Empty
  +        EmpiricalDistribution dist = new EmpiricalDistributionImpl();
  +        EmpiricalDistribution dist2 = (EmpiricalDistribution) TestUtils.serializeAndRecover(dist);
  +        verifySame(dist, dist2);
  +        
  +        // Loaded
  +        empiricalDistribution2.load(dataArray);   
  +        dist2 = (EmpiricalDistribution) TestUtils.serializeAndRecover(empiricalDistribution2);
  +        verifySame(empiricalDistribution2, dist2);
  +    }
  +    
  +    private void verifySame(EmpiricalDistribution d1, EmpiricalDistribution d2) {
  +        assertEquals(d1.isLoaded(), d2.isLoaded());
  +        assertEquals(d1.getBinCount(), d2.getBinCount());
  +        assertEquals(d1.getSampleStats(), d2.getSampleStats());
  +        if (d1.isLoaded()) {
  +            for (int i = 0;  i < d1.getUpperBounds().length; i++) {
  +                assertEquals(d1.getUpperBounds()[i], d2.getUpperBounds()[i], 0);
  +            }
  +            assertEquals(d1.getBinStats(), d2.getBinStats());
  +        }
       }
       
       private void tstGen(double tolerance)throws Exception {
  
  
  

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