package simizer.laws;

import org.junit.*;

/**
 * Basic tests that should be run on all Law subclasses.
 */
@Ignore
public class LawTest {
  protected Law law;

  /**
   * Outputs values from the law to evaluate their distribution.
   */
  @Test
  public void testOutput() {
    for (int i = 0; i < 10000; i++) {
      System.out.println(law.nextValue());
    }
  }
}

package simizer.laws;

import java.lang.reflect.Field;
import org.junit.*;

/**
 * Basic tests that should be run on all Law subclasses.
 */
@Ignore
public class LawTest {
  protected Law law;

  /**
   * Outputs values from the law to evaluate their distribution.
   */
  @Test
  public void testOutput() {
    for (int i = 0; i < 10000; i++) {
      System.out.println(law.nextValue());
    }
  }

  /**
   * Tests whether or not the theoretically maximum value can be achieved.
   *
   * @throws Exception if there is a problem with the reflection
   */
  @Test
  public void testMaximum() throws Exception {
    Field upperBound = Law.class.getDeclaredField("upperBound");
    upperBound.setAccessible(true);
    int bound = (Integer) upperBound.get(law);

    long target = System.currentTimeMillis() + 4*1000;

    boolean found = false;
    while (System.currentTimeMillis() < target) {
      int value = law.nextValue();
      Assert.assertTrue("generated a value that was too large", value < bound);
      Assert.assertTrue("generated a value that was too small", value >= 0);

      if (value == (bound - 1)) {
        found = true;
        break;
      }
    }
    Assert.assertTrue("could not generate the maximum value", found);
  }

  /**
   * Tests whether or not the theoretically minimum value can be achieved.
   */
  @Test
  public void testMinimum() {
    long target = System.currentTimeMillis() + 4*1000;

    boolean found = false;
    while (System.currentTimeMillis() < target) {
      int value = law.nextValue();
      Assert.assertTrue("generated a value that was too small", value >= 0);

      if (value == 0) {
        found = true;
        break;
      }
    }
    Assert.assertTrue("could not generate the minimum value", found);
  }
}

Add unit tests to check the min/max range values.
Add unit tests to check the min/max range values.

The unit tests for the Law subclasses will now check whether or not the minimum
value (0) and maximum value (upperBound - 1) can be generated by the
distribution.

Because of the random nature of the laws, the tests will try to generate the
values for four seconds.  If they cannot generate a value in that time, they
will consider it a failure.
