QuantileCalculationMethod { abstract double quantileFromSorted(double level, double[] sortedSample);  double quantileFromUnsorted(double level, double[] sample);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void discrete_wrong_quantile_large() { QUANTILE_INDEX_ABOVE.quantileFromSorted(1.01, SAMPLE_SORTED_100); }
@Test(expectedExceptions = IllegalArgumentException.class) public void discrete_wrong_quantile_0() { QUANTILE_INDEX_ABOVE.quantileFromSorted(0.0, SAMPLE_SORTED_100); }
@Test(expectedExceptions = IllegalArgumentException.class) public void interpolation_wrong_quantile_1() { QUANTILE_SAMPLE_INTERPOLATION.quantileFromSorted(1.01, SAMPLE_SORTED_100); }
@Test(expectedExceptions = IllegalArgumentException.class) public void interpolation_wrong_quantile_0() { QUANTILE_SAMPLE_INTERPOLATION.quantileFromSorted(0.0, SAMPLE_SORTED_100); }
@Test(expectedExceptions = IllegalArgumentException.class) public void interpolation_wrong_quantile_small() { QUANTILE_SAMPLE_INTERPOLATION.quantileFromSorted(1.0E-4, SAMPLE_SORTED_100); }
@Test(expectedExceptions = IllegalArgumentException.class) public void interpolation_wrong_quantile_large() { QUANTILE_MIDWAY_INTERPOLATION.quantileFromSorted(1.0 - 1.0E-4, SAMPLE_SORTED_100); }
@Test public void index_above_095_100() { double indexDouble = LEVEL * SAMPLE_SIZE_100; int indexCeil = (int) Math.ceil(indexDouble); double quantileExpected = SAMPLE_SORTED_100[indexCeil - 1]; double quantileComputed = QUANTILE_INDEX_ABOVE.quantileFromSorted(LEVEL, SAMPLE_SORTED_100); assertEquals(quantileComputed, quantileExpected, TOLERANCE_QUANTILE); }
@Test public void index_above_095_123() { double indexDouble = LEVEL * SAMPLE_SIZE_100; int indexCeil = (int) Math.ceil(indexDouble); double quantileExpected = SAMPLE_SORTED_100[indexCeil - 1]; double quantileComputed = QUANTILE_INDEX_ABOVE.quantileFromSorted(LEVEL, SAMPLE_SORTED_100); assertEquals(quantileComputed, quantileExpected); }
@Test public void index_nearest_095_100() { double quantileExpected = QUANTILE_INDEX_ABOVE.quantileFromSorted(LEVEL, SAMPLE_SORTED_100); double quantileComputed = QUANTILE_NEAREST_INDEX.quantileFromSorted(LEVEL, SAMPLE_SORTED_100); assertEquals(quantileComputed, quantileExpected, TOLERANCE_QUANTILE); }
@Test public void index_nearest_0951_100() { double indexDouble = (LEVEL+0.001) * SAMPLE_SIZE_100; int indexRound = (int) Math.round(indexDouble); double quantileExpected = SAMPLE_SORTED_100[indexRound - 1]; double quantileComputed = QUANTILE_NEAREST_INDEX.quantileFromSorted(LEVEL, SAMPLE_SORTED_100); assertEquals(quantileComputed, quantileExpected, TOLERANCE_QUANTILE); }
@Test public void index_nearest_001_100() { double quantileExpected = SAMPLE_SORTED_100[0]; double quantileComputed = QUANTILE_NEAREST_INDEX.quantileFromSorted(0.001, SAMPLE_SORTED_100); assertEquals(quantileComputed, quantileExpected, TOLERANCE_QUANTILE); }
@Test public void interpolation_sample_095_100() { double quantileExpected = QUANTILE_NEAREST_INDEX.quantileFromSorted(LEVEL, SAMPLE_SORTED_100); double quantileComputed = QUANTILE_SAMPLE_INTERPOLATION.quantileFromSorted(LEVEL, SAMPLE_SORTED_100); assertEquals(quantileComputed, quantileExpected, TOLERANCE_QUANTILE); }
@Test public void interpolation_sample_095_123() { double indexDouble = LEVEL * SAMPLE_SIZE_123; int indexCeil = (int) Math.ceil(indexDouble); int indexFloor = (int) Math.floor(indexDouble); double quantileCeil = SAMPLE_SORTED_123[indexCeil - 1]; double quantileFloor = SAMPLE_SORTED_123[indexFloor - 1]; double pi = (double) indexFloor / (double) SAMPLE_SIZE_123; double pi1 = (double) indexCeil / (double) SAMPLE_SIZE_123; double quantileExpected = quantileFloor + (LEVEL - pi) / (pi1 - pi) * (quantileCeil - quantileFloor); double quantileComputed = QUANTILE_SAMPLE_INTERPOLATION.quantileFromSorted(LEVEL, SAMPLE_SORTED_123); assertEquals(quantileComputed, quantileExpected, TOLERANCE_QUANTILE); }
@Test public void interpolation_samplePlusOne_095_123() { double indexDouble = LEVEL * (SAMPLE_SIZE_123 + 1); int indexCeil = (int) Math.ceil(indexDouble); int indexFloor = (int) Math.floor(indexDouble); double quantileCeil = SAMPLE_SORTED_123[indexCeil - 1]; double quantileFloor = SAMPLE_SORTED_123[indexFloor - 1]; double pi = (double) indexFloor / (double) (SAMPLE_SIZE_123 + 1); double pi1 = (double) indexCeil / (double) (SAMPLE_SIZE_123 + 1); double quantileExpected = quantileFloor + (LEVEL - pi) / (pi1 - pi) * (quantileCeil - quantileFloor); double quantileComputed = QUANTILE_SAMPLE1_INTERPOLATION.quantileFromSorted(LEVEL, SAMPLE_SORTED_123); assertEquals(quantileComputed, quantileExpected, TOLERANCE_QUANTILE); }
@Test public void interpolation_midway_095_123() { double correction = 0.5; double indexDouble = LEVEL * SAMPLE_SIZE_123 + correction; int indexCeil = (int) Math.ceil(indexDouble); int indexFloor = (int) Math.floor(indexDouble); double quantileCeil = SAMPLE_SORTED_123[indexCeil - 1]; double quantileFloor = SAMPLE_SORTED_123[indexFloor - 1]; double pi = (indexFloor - correction) / (double) SAMPLE_SIZE_123; double pi1 = (indexCeil - correction) / (double) SAMPLE_SIZE_123; double quantileExpected = quantileFloor + (LEVEL - pi) / (pi1 - pi) * (quantileCeil - quantileFloor); double quantileComputed = QUANTILE_MIDWAY_INTERPOLATION.quantileFromSorted(LEVEL, SAMPLE_SORTED_123); assertEquals(quantileComputed, quantileExpected, TOLERANCE_QUANTILE); }