private void checkConvergence(final GenericRiskStatistics stat, final String name) {
final ConvergenceStatistics stats = new ConvergenceStatistics();
stats.add(1.0);
stats.add(2.0);
stats.add(3.0);
stats.add(4.0);
stats.add(5.0);
stats.add(6.0);
stats.add(7.0);
stats.add(8.0);
final /*@Size*/ int expectedSize1 = 3;
/*@Size*/ int calculatedSize = stats.convergenceTable().size();
if (calculatedSize != expectedSize1)
fail("ConvergenceStatistics<" + name + ">: "
+ "\nwrong convergence-table size"
+ "\n calculated: " + calculatedSize
+ "\n expected: " + expectedSize1);
final /*@Real*/ double tolerance = 1.0e-9;
{
final /*@Real*/ double expectedValue1 = 4.0;
final List<Pair<Integer, Double>> table = stats.convergenceTable();
/*@Real*/ double calculatedValue = table.get(table.size()-1).second();
if (Math.abs(calculatedValue-expectedValue1) > tolerance)
fail("wrong last value in convergence table"
+ "\n calculated: " + calculatedValue
+ "\n expected: " + expectedValue1);
}
{
final /*@Size*/ int expectedSampleSize1 = 7;
final List<Pair<Integer, Double>> table = stats.convergenceTable();
/*@Size*/ int calculatedSamples = table.get(table.size()-1).first();
if (calculatedSamples != expectedSampleSize1)
fail("wrong number of samples in convergence table"
+ "\n calculated: " + calculatedSamples
+ "\n expected: " + expectedSampleSize1);
}
stats.reset();
stats.add(1.0);
stats.add(2.0);
stats.add(3.0);
stats.add(4.0);
final /*@Size*/ int expectedSize2 = 2;
calculatedSize = stats.convergenceTable().size();
if (calculatedSize != expectedSize2)
fail("wrong convergence-table size"
+ "\n calculated: " + calculatedSize
+ "\n expected: " + expectedSize2);
{
final /*@Real*/ double expectedValue2 = 2.0;
final List<Pair<Integer, Double>> table = stats.convergenceTable();
/*@Real*/ double calculatedValue = table.get(table.size()-1).second();
if (Math.abs(calculatedValue-expectedValue2) > tolerance)
fail("wrong last value in convergence table"
+ "\n calculated: " + calculatedValue
+ "\n expected: " + expectedValue2);
}
{
final /*@Size*/ int expectedSampleSize2 = 3;
final List<Pair<Integer, Double>> table = stats.convergenceTable();
/*@Size*/ int calculatedSamples = table.get(table.size()-1).first();
if (calculatedSamples != expectedSampleSize2)
fail("wrong number of samples in convergence table"
+ "\n calculated: " + calculatedSamples
+ "\n expected: " + expectedSampleSize2);