@@ -0,0 +1,2098 @@
+/**%0A * %0A */%0Apackage test;%0A%0Aimport static org.junit.Assert.assertEquals;%0A%0Aimport java.util.LinkedList;%0Aimport java.util.List;%0A%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.junit.runners.JUnit4;%0A%0Aimport blog.distrib.Geometric;%0A%0A/**%0A * Unit tests for Geometric Distribution%0A * src.blog.distrib.Geometric.java%0A */%0A@RunWith(JUnit4.class)%0Apublic class TestGeometric %7B%0A  private final double ERROR_BOUND = 1e-6;%0A%0A  @Test%0A  public void testCorrect() %7B%0A    testGeometric(0.1, 0, 0.1);%0A    testGeometric(0.1, 1, 0.09);%0A    testGeometric(0.1, 2, 0.081);%0A    testGeometric(0.6, 10, 6.291456e-5);%0A    testGeometric(0.05, 20, 0.017924296);%0A    testGeometric(0.1, -1, 0);%0A  %7D%0A%0A  @Test(expected = IllegalArgumentException.class)%0A  public void testMissingArguments() %7B%0A    List%3CNumber%3E params = new LinkedList%3CNumber%3E();%0A    Geometric distribution = new Geometric(params);%0A  %7D%0A%0A  @Test(expected = IllegalArgumentException.class)%0A  public void testNumberNotGivenAsProb() %7B%0A    List%3CObject%3E params = new LinkedList%3CObject%3E();%0A    params.add(%22foo%22);%0A    Geometric distribution = new Geometric(params);%0A  %7D%0A%0A  @Test(expected = IllegalArgumentException.class)%0A  public void testProbabilityNotGiven() %7B%0A    testGeometric(10, 0, 0.5);%0A  %7D%0A%0A  @Test(expected = IllegalArgumentException.class)%0A  public void testMoreThanOneArgument() %7B%0A    List%3CNumber%3E params = new LinkedList%3CNumber%3E();%0A    params.add(0.5);%0A    params.add(0.6);%0A    Geometric distribution = new Geometric(params);%0A  %7D%0A%0A  /**%0A   * For a Geometric Distribution with prob success = p%0A   * Asserts P(#failures until first success = k) = prob%0A   * No precondition on p, k, or prob%0A   */%0A  public void testGeometric(Number p, Integer k, Number prob) %7B%0A    List%3CNumber%3E params = new LinkedList%3CNumber%3E();%0A    params.add(p);%0A    Geometric distribution = new Geometric(params);%0A    List%3CNumber%3E emptyArgs = new LinkedList%3CNumber%3E();%0A    assertEquals(prob.doubleValue(), distribution.getProb(emptyArgs, k),%0A        ERROR_BOUND);%0A    assertEquals(Math.log(prob.doubleValue()),%0A        distribution.getLogProb(emptyArgs, k), ERROR_BOUND);%0A%0A  %7D%0A%0A%7D%0A

Test for Geometric Distribution