public void testPercentiles_indexes_varargsAll_compute_doubleCollection() { ArrayList<Integer> indexes = new ArrayList<>(); ImmutableMap.Builder<Integer, Double> expectedBuilder = ImmutableMap.builder(); for (int index = 0; index <= 100; index++) { indexes.add(index); expectedBuilder.put(index, expectedLargeDatasetPercentile(index)); } Random random = new Random(770683168895677741L); Collections.shuffle(indexes, random); assertThat(percentiles().indexes(Ints.toArray(indexes)).compute(PSEUDORANDOM_DATASET)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactlyEntriesIn(expectedBuilder.build()); }
public void testPercentiles_indexes_varargsPairs_compute_doubleCollection() { for (int index1 = 0; index1 <= 100; index1++) { for (int index2 = 0; index2 <= 100; index2++) { ImmutableMap.Builder<Integer, Double> expectedBuilder = ImmutableMap.builder(); expectedBuilder.put(index1, expectedLargeDatasetPercentile(index1)); if (index2 != index1) { expectedBuilder.put(index2, expectedLargeDatasetPercentile(index2)); } assertThat(percentiles().indexes(index1, index2).compute(PSEUDORANDOM_DATASET)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactlyEntriesIn(expectedBuilder.build()); } } }
public void testScale_indexes_collection_compute_doubleCollection() { // Note that we specify index 1 twice, which by the method contract should be ignored. assertThat( Quantiles.scale(10) .indexes(ImmutableList.of(0, 10, 5, 1, 8, 1)) .compute(SIXTEEN_SQUARES_DOUBLES)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactly( 0, SIXTEEN_SQUARES_MIN, 10, SIXTEEN_SQUARES_MAX, 5, SIXTEEN_SQUARES_MEDIAN, 1, SIXTEEN_SQUARES_DECILE_1, 8, SIXTEEN_SQUARES_DECILE_8); }
public void testQuartiles_indexes_varargs_compute_doubleCollection() { assertThat(quartiles().indexes(1, 3).compute(SIXTEEN_SQUARES_DOUBLES)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactly(1, SIXTEEN_SQUARES_QUARTILE_1, 3, SIXTEEN_SQUARES_QUARTILE_3); }
public void testScale_indexes_varargs_compute_doubleCollection_nan() { assertThat(Quantiles.scale(10).indexes(0, 1, 2, 8, 9, 10).compute(ONE_TO_FIVE_AND_NAN)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactly( 0, NaN, 1, NaN, 2, NaN, 8, NaN, 9, NaN, 10, NaN); }
public void testScale_indexes_varargs_compute_doubleCollection() { // Note that we specify index 1 twice, which by the method contract should be ignored. assertThat(Quantiles.scale(10).indexes(0, 10, 5, 1, 8, 1).compute(SIXTEEN_SQUARES_DOUBLES)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactly( 0, SIXTEEN_SQUARES_MIN, 10, SIXTEEN_SQUARES_MAX, 5, SIXTEEN_SQUARES_MEDIAN, 1, SIXTEEN_SQUARES_DECILE_1, 8, SIXTEEN_SQUARES_DECILE_8); }
public void testScale_indexes_varargs_compute_longCollection() { // Note that we specify index 1 twice, which by the method contract should be ignored. assertThat(Quantiles.scale(10).indexes(0, 10, 5, 1, 8, 1).compute(SIXTEEN_SQUARES_LONGS)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactly( 0, SIXTEEN_SQUARES_MIN, 10, SIXTEEN_SQUARES_MAX, 5, SIXTEEN_SQUARES_MEDIAN, 1, SIXTEEN_SQUARES_DECILE_1, 8, SIXTEEN_SQUARES_DECILE_8); }
public void testScale_indexes_varargs_compute_integerCollection() { // Note that we specify index 1 twice, which by the method contract should be ignored. assertThat(Quantiles.scale(10).indexes(0, 10, 5, 1, 8, 1).compute(SIXTEEN_SQUARES_INTEGERS)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactly( 0, SIXTEEN_SQUARES_MIN, 10, SIXTEEN_SQUARES_MAX, 5, SIXTEEN_SQUARES_MEDIAN, 1, SIXTEEN_SQUARES_DECILE_1, 8, SIXTEEN_SQUARES_DECILE_8); }
public void testScale_indexes_varargs_computeInPlace_explicitVarargs() { assertThat(Quantiles.scale(10).indexes(0, 10).computeInPlace(78.9, 12.3, 45.6)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactly( 0, 12.3, 10, 78.9); }
public void testScale_indexes_largeVarargs_compute_doubleCollection() { int scale = Integer.MAX_VALUE; int otherIndex = (Integer.MAX_VALUE - 1) / 3; // this divides exactly // For the otherIndex calculation, we have q=Integer.MAX_VALUE, k=(Integer.MAX_VALUE-1)/3, and // N=16. Therefore k*(N-1)/q = 5-5/Integer.MAX_VALUE, which has floor 4 and fractional part // (1-5/Integer.MAX_VALUE). double otherValue = 16.0 * 5.0 / Integer.MAX_VALUE + 25.0 * (1.0 - 5.0 / Integer.MAX_VALUE); assertThat( Quantiles.scale(scale).indexes(0, scale, otherIndex).compute(SIXTEEN_SQUARES_DOUBLES)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactly( 0, SIXTEEN_SQUARES_MIN, scale, SIXTEEN_SQUARES_MAX, otherIndex, otherValue); }
@AndroidIncompatible // slow public void testPercentiles_indexes_varargsAll_computeInPlace() { double[] dataset = Doubles.toArray(PSEUDORANDOM_DATASET); List<Integer> indexes = new ArrayList<>(); ImmutableMap.Builder<Integer, Double> expectedBuilder = ImmutableMap.builder(); for (int index = 0; index <= 100; index++) { indexes.add(index); expectedBuilder.put(index, expectedLargeDatasetPercentile(index)); } Random random = new Random(770683168895677741L); Collections.shuffle(indexes, random); assertThat(percentiles().indexes(Ints.toArray(indexes)).computeInPlace(dataset)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactlyEntriesIn(expectedBuilder.build()); assertThat(dataset).usingExactEquality().containsExactlyElementsIn(PSEUDORANDOM_DATASET); }
public void testScale_indexes_varargs_compute_doubleCollection_negativeInfinity() { assertThat( Quantiles.scale(10) .indexes(0, 1, 2, 8, 9, 10) .compute(ONE_TO_FIVE_AND_NEGATIVE_INFINITY)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactly( 0, NEGATIVE_INFINITY, 1, NEGATIVE_INFINITY, // interpolating between NEGATIVE_INFNINITY and 1.0 2, 1.0, 8, 4.0, 9, 4.5, 10, 5.0); }
public void testScale_indexes_varargs_compute_doubleCollection_bothInfinities() { assertThat( Quantiles.scale(10) .indexes(0, 1, 2, 8, 9, 10) .compute(NEGATIVE_INFINITY_AND_FIVE_POSITIVE_INFINITIES)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactly( 0, NEGATIVE_INFINITY, 1, NaN, // interpolating between NEGATIVE_ and POSITIVE_INFINITY values 2, POSITIVE_INFINITY, 8, POSITIVE_INFINITY, 9, POSITIVE_INFINITY, // interpolating between two POSITIVE_INFINITY values 10, POSITIVE_INFINITY); }
public void testScale_indexes_varargs_compute_doubleCollection_positiveInfinity() { assertThat( Quantiles.scale(10) .indexes(0, 1, 2, 8, 9, 10) .compute(ONE_TO_FIVE_AND_POSITIVE_INFINITY)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactly( 0, 1.0, 1, 1.5, 2, 2.0, 8, 5.0, 9, POSITIVE_INFINITY, // interpolating between 5.0 and POSITIVE_INFNINITY 10, POSITIVE_INFINITY); }
public void testScale_indexes_collection_computeInPlace() { double[] dataset = Doubles.toArray(SIXTEEN_SQUARES_DOUBLES); assertThat( Quantiles.scale(10) .indexes(ImmutableList.of(0, 10, 5, 1, 8, 1)) .computeInPlace(dataset)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactly( 0, SIXTEEN_SQUARES_MIN, 10, SIXTEEN_SQUARES_MAX, 5, SIXTEEN_SQUARES_MEDIAN, 1, SIXTEEN_SQUARES_DECILE_1, 8, SIXTEEN_SQUARES_DECILE_8); assertThat(dataset).usingExactEquality().containsExactlyElementsIn(SIXTEEN_SQUARES_DOUBLES); }
public void testQuartiles_indexes_varargs_computeInPlace() { double[] dataset = Doubles.toArray(SIXTEEN_SQUARES_DOUBLES); assertThat(quartiles().indexes(1, 3).computeInPlace(dataset)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactly( 1, SIXTEEN_SQUARES_QUARTILE_1, 3, SIXTEEN_SQUARES_QUARTILE_3); assertThat(dataset).usingExactEquality().containsExactlyElementsIn(SIXTEEN_SQUARES_DOUBLES); }
public void testScale_indexes_varargs_compute_longVarargs() { long[] dataset = Longs.toArray(SIXTEEN_SQUARES_LONGS); assertThat(Quantiles.scale(10).indexes(0, 10, 5, 1, 8, 1).compute(dataset)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactly( 0, SIXTEEN_SQUARES_MIN, 10, SIXTEEN_SQUARES_MAX, 5, SIXTEEN_SQUARES_MEDIAN, 1, SIXTEEN_SQUARES_DECILE_1, 8, SIXTEEN_SQUARES_DECILE_8); assertThat(dataset).asList().isEqualTo(SIXTEEN_SQUARES_LONGS); }
public void testScale_indexes_varargs_compute_intVarargs() { int[] dataset = Ints.toArray(SIXTEEN_SQUARES_INTEGERS); assertThat(Quantiles.scale(10).indexes(0, 10, 5, 1, 8, 1).compute(dataset)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactly( 0, SIXTEEN_SQUARES_MIN, 10, SIXTEEN_SQUARES_MAX, 5, SIXTEEN_SQUARES_MEDIAN, 1, SIXTEEN_SQUARES_DECILE_1, 8, SIXTEEN_SQUARES_DECILE_8); assertThat(dataset).asList().isEqualTo(SIXTEEN_SQUARES_INTEGERS); }
public void testScale_indexes_varargs_computeInPlace() { double[] dataset = Doubles.toArray(SIXTEEN_SQUARES_DOUBLES); assertThat(Quantiles.scale(10).indexes(0, 10, 5, 1, 8, 1).computeInPlace(dataset)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactly( 0, SIXTEEN_SQUARES_MIN, 10, SIXTEEN_SQUARES_MAX, 5, SIXTEEN_SQUARES_MEDIAN, 1, SIXTEEN_SQUARES_DECILE_1, 8, SIXTEEN_SQUARES_DECILE_8); assertThat(dataset).usingExactEquality().containsExactlyElementsIn(SIXTEEN_SQUARES_DOUBLES); }
public void testScale_indexes_varargs_compute_doubleVarargs() { double[] dataset = Doubles.toArray(SIXTEEN_SQUARES_DOUBLES); assertThat(Quantiles.scale(10).indexes(0, 10, 5, 1, 8, 1).compute(dataset)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactly( 0, SIXTEEN_SQUARES_MIN, 10, SIXTEEN_SQUARES_MAX, 5, SIXTEEN_SQUARES_MEDIAN, 1, SIXTEEN_SQUARES_DECILE_1, 8, SIXTEEN_SQUARES_DECILE_8); assertThat(dataset) .usingExactEquality() .containsExactlyElementsIn(SIXTEEN_SQUARES_DOUBLES) .inOrder(); }