Ejemplo n.º 1
0
 @Test
 public void testFloat() {
   for (long seed = 0; seed < 10000; seed++) {
     CopiableRandom myrand = new CopiableRandom(seed);
     Random rand = new Random(seed);
     for (int i = 1; i < 1000; i++) {
       myrand = new CopiableRandom(myrand);
       float a = rand.nextFloat();
       float b = myrand.nextFloat();
       assertTrue(a == b);
     }
   }
 }
Ejemplo n.º 2
0
 @Test
 public void testBytes() {
   for (long seed = 0; seed < 100; seed++) {
     CopiableRandom myrand = new CopiableRandom(seed);
     Random rand = new Random(seed);
     for (int i = 1; i < 100; i++) {
       myrand = new CopiableRandom(myrand);
       byte[] a = new byte[100];
       byte[] b = new byte[100];
       rand.nextBytes(a);
       myrand.nextBytes(b);
       Assert.assertArrayEquals(a, b);
     }
   }
 }
Ejemplo n.º 3
0
  /**
   * Test the use of a Copiable Random and a copy of this one to guarantee they behave the same.
   *
   * @param args
   */
  @Test
  public void testCopyAndCopyOfCopy() {
    long seed = 1234;
    Random rand = new Random(seed);
    CopiableRandom myrand = new CopiableRandom(seed);

    for (int i = 1; i < 1000000; i++) {
      myrand = new CopiableRandom(myrand);
      CopiableRandom other = new CopiableRandom(myrand);
      int a = rand.nextInt(6);
      int b = myrand.nextInt(6);
      int c = other.nextInt(6);
      Assert.assertEquals("Equals    the two  ", a, b);
      Assert.assertEquals("Equals    the two  ", b, c);
    }
  }
Ejemplo n.º 4
0
 @Test
 public void testInt() {
   for (long seed = 0; seed < 10000; seed++) {
     Random rand = new Random(seed);
     CopiableRandom myrand = new CopiableRandom(seed);
     for (int i = 1; i < 1000; i++) {
       // copy constructor
       myrand = new CopiableRandom(myrand);
       assertTrue(rand.nextBoolean() == myrand.nextBoolean());
     }
     myrand = new CopiableRandom(seed);
     rand = new Random(seed);
     for (int i = 1; i < 1000; i++) {
       myrand = new CopiableRandom(myrand);
       int a = rand.nextInt(1000000);
       int b = myrand.nextInt(1000000);
       assertTrue(a == b);
       // System.out.println("Equals    the two  " + (a==b) +" "+a+" "+b);
     }
   }
 }