package net.thingly.dice;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 * Unit test for Dice.
 */
public class DiceTest extends TestCase {

	private int iter = 100000;

	/**
	 * Create the test case
	 *
	 * @param testName
	 *            name of the test case
	 */
	public DiceTest(String testName) {
		super(testName);
	}

	/**
	 * @return the suite of tests being tested
	 */
	public static Test suite() {
		return new TestSuite(DiceTest.class);
	}

	/**
	 * Rigourous Test :-)
	 */
	public void testRoll() {
		// Hashtable<Integer, Double> probs = Prob.prob(1, 6);
		int[] results = new int[6];
		for (int i = 0; i < iter; i++) {
			int r = Dice.roll();
			assertTrue(r >= 1 && r <= 6);
			results[r-1]++;
		}
		double chisq = 0;
		double expected = ((double)iter)/6.0; 
		for(int i = 0; i < results.length; i++) {
			System.out.println(i+1 + ": " + results[i]);
			chisq += Math.pow(((double)results[i])-expected, 2)/expected;
		}
		System.out.println("chi squared: " + chisq);
	}

	/**
	 * Rigourous Test :-)
	 */
	public void testRollN() {
		assertTrue(true);
	}

	/**
	 * Rigourous Test :-)
	 */
	public void testRollND() {
		assertTrue(true);
	}
}

@@ -752,17 +752,19 @@
 esults%5Br
--
+ - 
 1%5D++;%0A%09%09
@@ -769,27 +769,8 @@
 %09%09%7D%0A
-%09%09double chisq = 0;
 %0A%09%09d
@@ -799,25 +799,28 @@
 ble)
+ 
 iter)
-/
+ / 
 6.0;
- 
 %0A%09%09for
+ 
 (int
@@ -861,168 +861,234 @@
 %0A%09%09%09
-System.out.println(i+1 + %22: %22 + results%5Bi%5D);%0A%09%09%09chisq += Math.pow(((double)results%5Bi%5D)-expected, 2)/expected;%0A%09%09%7D%0A%09%09System.out.println(%22chi squared: %22 + chisq);
+double pct = ((double) results%5Bi%5D) / iter;%0A%09%09%09// not super-scientific, but i'm satisfied if we're within a half a%0A%09%09%09// percent for each possible outcome%0A%09%09%09assertTrue(Math.abs(pct - (expected / ((double) iter))) %3C= .005);%0A%09%09%7D
 %0A%09%7D%0A

complete test for roll()