Program: 50484
Project: 50484
Buggy source:
@Test public void testFisherExact() throws MathException {
  final DifferentialExpressionCalculator deCalc=new DifferentialExpressionCalculator();
  final int numReplicates=2;
  deCalc.defineElement("String_Node_Str");
  deCalc.defineElement("String_Node_Str");
  deCalc.defineGroup("String_Node_Str");
  deCalc.defineGroup("String_Node_Str");
  deCalc.reserve(2,numReplicates * 2);
  for (int i=1; i <= numReplicates; i++) {
    deCalc.associateSampleToGroup("String_Node_Str" + i,"String_Node_Str");
    deCalc.associateSampleToGroup("String_Node_Str" + i,"String_Node_Str");
  }
  deCalc.observe("String_Node_Str","String_Node_Str",7);
  deCalc.observe("String_Node_Str","String_Node_Str",3);
  deCalc.observe("String_Node_Str","String_Node_Str",15);
  deCalc.observe("String_Node_Str","String_Node_Str",5);
  deCalc.observe("String_Node_Str","String_Node_Str",15);
  deCalc.observe("String_Node_Str","String_Node_Str",15);
  deCalc.observe("String_Node_Str","String_Node_Str",20);
  deCalc.observe("String_Node_Str","String_Node_Str",20);
  final DifferentialExpressionInfo info=new DifferentialExpressionInfo("String_Node_Str");
  final DifferentialExpressionResults results=new DifferentialExpressionResults();
  final FisherExactRCalculator fisher=new FisherExactRCalculator(results);
  if (fisher.installed()) {
    final NormalizationMethod normalizationMethod=new AlignedCountNormalization();
    fisher.evaluate(deCalc,normalizationMethod,results,info,"String_Node_Str","String_Node_Str");
    assertEquals("String_Node_Str",0.5044757698516504,results.getStatistic(info,fisher.statisticIds.get(0)),0.001);
    final int totalCountInA=1700;
    final int totalCountInB=170;
    final int sumCountInA=90;
    final int sumCountInB=45;
    final int sumCountNotInA=totalCountInA - sumCountInA;
    final int sumCountNotInB=totalCountInB - sumCountInB;
    final FisherExact.Result result=FisherExact.fexact(sumCountInA,sumCountNotInA,sumCountInB,sumCountNotInB);
    final double pValue=result.getPValue();
    final double proportionTotalA=divide(totalCountInA,(totalCountInA + totalCountInB));
    final double proportionTotalB=divide(totalCountInB,(totalCountInA + totalCountInB));
    final ChiSquareTest chisquare=new ChiSquareTestImpl();
    final double nGroups=2;
    final double[] expected={divide(sumCountInA + sumCountInB,nGroups) * proportionTotalA * nGroups,divide(sumCountInA + sumCountInB,nGroups) * proportionTotalB * nGroups};
    final long[] observed={sumCountInA,sumCountInB};
    double chiPValue=0;
    chiPValue=Math.abs(chisquare.chiSquareTest(expected,observed));
    assertTrue("String_Node_Str" + chiPValue,chiPValue < 0.001);
    assertTrue("String_Node_Str" + pValue,pValue < 0.001);
  }
}

Fixed version (ground truth):
@Test public void testFisherExact() throws MathException {
  final DifferentialExpressionCalculator deCalc=new DifferentialExpressionCalculator();
  final int numReplicates=2;
  deCalc.defineElement("String_Node_Str");
  deCalc.defineElement("String_Node_Str");
  deCalc.defineGroup("String_Node_Str");
  deCalc.defineGroup("String_Node_Str");
  deCalc.reserve(2,numReplicates * 2);
  for (int i=1; i <= numReplicates; i++) {
    deCalc.associateSampleToGroup("String_Node_Str" + i,"String_Node_Str");
    deCalc.associateSampleToGroup("String_Node_Str" + i,"String_Node_Str");
  }
  deCalc.observe("String_Node_Str","String_Node_Str",7);
  deCalc.observe("String_Node_Str","String_Node_Str",3);
  deCalc.observe("String_Node_Str","String_Node_Str",15);
  deCalc.observe("String_Node_Str","String_Node_Str",5);
  deCalc.observe("String_Node_Str","String_Node_Str",15);
  deCalc.observe("String_Node_Str","String_Node_Str",15);
  deCalc.observe("String_Node_Str","String_Node_Str",20);
  deCalc.observe("String_Node_Str","String_Node_Str",20);
  final DifferentialExpressionInfo info=new DifferentialExpressionInfo("String_Node_Str");
  final DifferentialExpressionResults results=new DifferentialExpressionResults();
  final FisherExactRCalculator fisher=new FisherExactRCalculator(results);
  if (fisher.installed()) {
    final NormalizationMethod normalizationMethod=new AlignedCountNormalization();
    fisher.evaluate(deCalc,normalizationMethod,results,info,"String_Node_Str","String_Node_Str");
    assertEquals("String_Node_Str",0.5044757698516504,results.getStatistic(info,fisher.statisticIds.get(0)),0.001);
    final int totalCountInA=1700;
    final int totalCountInB=170;
    final int sumCountInA=90;
    final int sumCountInB=45;
    final int sumCountNotInA=totalCountInA - sumCountInA;
    final int sumCountNotInB=totalCountInB - sumCountInB;
    final FisherExact.Result result=FisherExact.fexact(sumCountInA,sumCountNotInA,sumCountInB,sumCountNotInB);
    final double pValue=result.getPValue();
    final double proportionTotalA=divide(totalCountInA,(totalCountInA + totalCountInB));
    final double proportionTotalB=divide(totalCountInB,(totalCountInA + totalCountInB));
    final ChiSquareTest chisquare=new ChiSquareTestImpl();
    final double nGroups=2;
    final double[] expected={divide(sumCountInA + sumCountInB,nGroups) * proportionTotalA * nGroups,divide(sumCountInA + sumCountInB,nGroups) * proportionTotalB * nGroups};
    final long[] observed={sumCountInA,sumCountInB};
    final double chiPValue=Math.abs(chisquare.chiSquareTest(expected,observed));
    assertTrue("String_Node_Str" + chiPValue,chiPValue < 0.001);
    assertTrue("String_Node_Str" + pValue,pValue < 0.001);
  }
}