1 10 package org.jgap.impl; 11 12 import java.util.*; 13 import org.jgap.*; 14 import junit.framework.*; 15 import sun.misc.*; 16 17 23 public class CauchyRandomGeneratorTest 24 extends JGAPTestCase { 25 26 private static final String CVS_REVISION = "$Revision: 1.9 $"; 27 28 public static Test suite() { 29 TestSuite suite = new TestSuite(CauchyRandomGeneratorTest.class); 30 return suite; 31 } 32 33 38 public void testGeneral() { 39 RandomGenerator calc = new CauchyRandomGenerator(); 40 calc.nextInt(); 41 calc.nextBoolean(); 42 calc.nextDouble(); 43 calc.nextFloat(); 44 calc.nextInt(); 45 calc.nextLong(); 46 } 47 48 53 public void testNextCauchy_0() 54 throws Exception { 55 final double stdDev = 0.04d; 56 CauchyRandomGenerator calc = new CauchyRandomGenerator(0.0d, stdDev); 57 calc.nextCauchy(); 58 } 59 60 64 public void testGetCauchyStdDeviation_0() { 65 final double stdDev = 0.04d; 66 CauchyRandomGenerator calc = new CauchyRandomGenerator(0.0d, stdDev); 67 assertEquals(stdDev, calc.getCauchyStandardDeviation(), DELTA); 68 } 69 70 74 public void testNextInt_0() { 75 final double stdDev = 0.04d; 76 CauchyRandomGenerator calc = new CauchyRandomGenerator(0.0d, stdDev); 77 int i = calc.nextInt(2); 78 assertTrue(i < 2 && i >= 0); 79 i = calc.nextInt(1); 80 assertEquals(0, i); 81 } 82 83 91 public void testSerialize_0() throws Exception { 92 95 CauchyRandomGenerator srg = new CauchyRandomGenerator(); 96 Random r1 = (Random)privateAccessor.getField(srg,"m_rn"); 97 AtomicLong seed1 = (AtomicLong)privateAccessor.getField(r1,"seed"); 98 long curr = System.currentTimeMillis(); 99 while (curr == System.currentTimeMillis()); 100 CauchyRandomGenerator srg2 = (CauchyRandomGenerator)doSerialize(srg); 101 Random r2 = (Random)privateAccessor.getField(srg2,"m_rn"); 102 AtomicLong seed2 = (AtomicLong)privateAccessor.getField(r2,"seed"); 103 assertFalse(seed1.get() == seed2.get()); 104 } 105 } 106 | Popular Tags |