public static void assertChiSquareAccept(String[] valueLabels,double[] expected,long[] observed,double alpha){
  if (chiSquareTest(expected,observed) <= alpha) {
    StringBuilder msgBuffer=new StringBuilder();
    DecimalFormat df=new DecimalFormat("#.##");
    msgBuffer.append("Chisquare test failed");
    msgBuffer.append(" p-value = ");
    msgBuffer.append(chiSquareTest(expected,observed));
    msgBuffer.append(" chisquare statistic = ");
    msgBuffer.append(chiSquare(expected,observed));
    msgBuffer.append(". \n");
    msgBuffer.append("value\texpected\tobserved\n");
    for (int i=0; i < expected.length; i++) {
      msgBuffer.append(valueLabels[i]);
      msgBuffer.append("\t");
      msgBuffer.append(df.format(expected[i]));
      msgBuffer.append("\t\t");
      msgBuffer.append(observed[i]);
      msgBuffer.append("\n");
    }
    msgBuffer.append("This test can fail randomly due to sampling error with probability ");
    msgBuffer.append(alpha);
    msgBuffer.append(".");
    Assert.fail(msgBuffer.toString());
  }
}

public static void assertChiSquareAccept ( String [ ] valueLabels , double [ ] expected , long [ ] observed , double alpha ) { if ( chiSquareTest ( expected , observed ) <= alpha ) { StringBuilder msgBuffer = new StringBuilder ( ) ; DecimalFormat df = new DecimalFormat ( "#.##" ) ; msgBuffer . append ( "Chisquare test failed" ) ; msgBuffer . append ( " p-value = " ) ; msgBuffer . append ( chiSquareTest ( expected , observed ) ) ; msgBuffer . append ( " chisquare statistic = " ) ; msgBuffer . append ( chiSquare ( expected , observed ) ) ; msgBuffer . append ( ". \n" ) ; msgBuffer . append ( "value\texpected\tobserved\n" ) ; for ( int i = 0 ; i < expected . length ; i ++ ) { msgBuffer . append ( valueLabels [ i ] ) ; msgBuffer . append ( "\t" ) ; msgBuffer . append ( df . format ( expected [ i ] ) ) ; msgBuffer . append ( "\t\t" ) ; msgBuffer . append ( observed [ i ] ) ; msgBuffer . append ( "\n" ) ; } msgBuffer . append ( "This test can fail randomly due to sampling error with probability " ) ; msgBuffer . append ( alpha ) ; msgBuffer . append ( "." ) ; Assert . fail ( msgBuffer . toString ( ) ) ; } }
asserts the null hypothesis for a chisquare test . fails and dumps arguments and test statistics if the null hypothesis can be rejected with confidence 100 * ( 1 - alpha ) %
