assertThat(oneValueAccumulator.populationStandardDeviation()).isWithin(0.0).of(0.0); assertThat(oneValueAccumulatorByAddAllEmptyStats.populationStandardDeviation()) .isWithin(0.0) .of(0.0); assertThat(twoValuesAccumulator.populationStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(TWO_VALUES_SUM_OF_SQUARES_OF_DELTAS / 2)); assertThat(twoValuesAccumulatorByAddAllStats.populationStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(TWO_VALUES_SUM_OF_SQUARES_OF_DELTAS / 2)); assertThat(manyValuesAccumulatorByAddAllIterable.populationStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / MANY_VALUES_COUNT)); assertThat(manyValuesAccumulatorByAddAllIterator.populationStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / MANY_VALUES_COUNT)); assertThat(manyValuesAccumulatorByAddAllVarargs.populationStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / MANY_VALUES_COUNT)); assertThat(manyValuesAccumulatorByRepeatedAdd.populationStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / MANY_VALUES_COUNT)); assertThat(manyValuesAccumulatorByAddAndAddAll.populationStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / MANY_VALUES_COUNT)); assertThat(manyValuesAccumulatorByAddAllStats.populationStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / MANY_VALUES_COUNT)); assertThat(integerManyValuesAccumulatorByAddAllIterable.populationStandardDeviation())
@Test public void float64Wrapper() { Value v = Value.float64(Double.valueOf(1.23)); assertThat(v.getType()).isEqualTo(Type.float64()); assertThat(v.isNull()).isFalse(); assertThat(v.getFloat64()).isWithin(0.0001).of(1.23); assertThat(v.toString()).isEqualTo("1.23"); }
assertThat(ONE_VALUE_STATS.mean()).isWithin(ALLOWED_ERROR).of(ONE_VALUE); assertThat(Stats.of(POSITIVE_INFINITY).mean()).isPositiveInfinity(); assertThat(Stats.of(NEGATIVE_INFINITY).mean()).isNegativeInfinity(); assertThat(Stats.of(NaN).mean()).isNaN(); assertThat(TWO_VALUES_STATS.mean()).isWithin(ALLOWED_ERROR).of(TWO_VALUES_MEAN); assertThat(mean).named("mean of " + values).isNegativeInfinity(); } else { assertThat(mean).named("mean of " + values).isWithin(ALLOWED_ERROR).of(MANY_VALUES_MEAN); assertThat(MANY_VALUES_STATS_ITERABLE.mean()).isWithin(ALLOWED_ERROR).of(MANY_VALUES_MEAN); assertThat(MANY_VALUES_STATS_ITERATOR.mean()).isWithin(ALLOWED_ERROR).of(MANY_VALUES_MEAN); assertThat(MANY_VALUES_STATS_SNAPSHOT.mean()).isWithin(ALLOWED_ERROR).of(MANY_VALUES_MEAN); assertThat(LARGE_VALUES_STATS.mean()) .isWithin(ALLOWED_ERROR * Double.MAX_VALUE) .of(LARGE_VALUES_MEAN); assertThat(INTEGER_MANY_VALUES_STATS_VARARGS.mean()) .isWithin(ALLOWED_ERROR) .of(INTEGER_MANY_VALUES_MEAN); assertThat(INTEGER_MANY_VALUES_STATS_ITERABLE.mean()) .isWithin(ALLOWED_ERROR) .of(INTEGER_MANY_VALUES_MEAN); assertThat(LARGE_INTEGER_VALUES_STATS.mean()) .isWithin(ALLOWED_ERROR * Integer.MAX_VALUE) .of(LARGE_INTEGER_VALUES_MEAN); assertThat(LONG_MANY_VALUES_STATS_ITERATOR.mean()) .isWithin(ALLOWED_ERROR) .of(LONG_MANY_VALUES_MEAN); assertThat(LONG_MANY_VALUES_STATS_SNAPSHOT.mean())
@Test public void testAdaptiveDataSetChunkSizeDistribution() { double expectedStdDev = 4.0; FakeAdaptiveDataSet dataSet = new FakeAdaptiveDataSet( TRACK_GROUP, 100000 * C.MICROS_PER_SECOND, 1 * C.MICROS_PER_SECOND, expectedStdDev, new Random(0)); for (int i = 0; i < TEST_FORMATS.length; i++) { FakeData data = dataSet.getData(dataSet.getUri(i)); double mean = computeSegmentSizeMean(data.getSegments()); double stddev = computeSegmentSizeStdDev(data.getSegments(), mean); double relativePercentStdDev = stddev / mean * 100.0; assertThat(relativePercentStdDev).isWithin(0.02).of(expectedStdDev); assertThat(mean * 8 / TEST_FORMATS[i].bitrate).isWithin(0.01).of(1.0); } }
.of(TWO_VALUES_SUM_OF_PRODUCTS_OF_DELTAS); assertThat(twoValuesAccumulatorByAddAllPartitionedPairedStats.sampleCovariance()) .isWithin(ALLOWED_ERROR) .of(TWO_VALUES_SUM_OF_PRODUCTS_OF_DELTAS); assertThat(manyValuesAccumulator.sampleCovariance()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_SUM_OF_PRODUCTS_OF_DELTAS / (MANY_VALUES_COUNT - 1)); assertThat(manyValuesAccumulatorByAddAllPartitionedPairedStats.sampleCovariance()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_SUM_OF_PRODUCTS_OF_DELTAS / (MANY_VALUES_COUNT - 1)); assertThat(horizontalValuesAccumulator.sampleCovariance()).isWithin(ALLOWED_ERROR).of(0.0); assertThat(horizontalValuesAccumulatorByAddAllPartitionedPairedStats.sampleCovariance()) .isWithin(ALLOWED_ERROR) .of(0.0); assertThat(verticalValuesAccumulator.sampleCovariance()).isWithin(ALLOWED_ERROR).of(0.0); assertThat(verticalValuesAccumulatorByAddAllPartitionedPairedStats.sampleCovariance()) .isWithin(ALLOWED_ERROR) .of(0.0); assertThat(constantValuesAccumulator.sampleCovariance()).isWithin(ALLOWED_ERROR).of(0.0); assertThat(constantValuesAccumulatorByAddAllPartitionedPairedStats.sampleCovariance()) .isWithin(ALLOWED_ERROR) .of(0.0);
} catch (IllegalStateException expected) { assertThat(ONE_VALUE_STATS.min()).isWithin(ALLOWED_ERROR).of(ONE_VALUE); assertThat(Stats.of(POSITIVE_INFINITY).min()).isPositiveInfinity(); assertThat(Stats.of(NEGATIVE_INFINITY).min()).isNegativeInfinity(); assertThat(Stats.of(NaN).min()).isNaN(); assertThat(TWO_VALUES_STATS.min()).isWithin(ALLOWED_ERROR).of(TWO_VALUES_MIN); assertThat(MANY_VALUES_STATS_VARARGS.min()).isWithin(ALLOWED_ERROR).of(MANY_VALUES_MIN); assertThat(MANY_VALUES_STATS_ITERABLE.min()).isWithin(ALLOWED_ERROR).of(MANY_VALUES_MIN); assertThat(MANY_VALUES_STATS_ITERATOR.min()).isWithin(ALLOWED_ERROR).of(MANY_VALUES_MIN); assertThat(min).named("min of " + values).isNegativeInfinity(); } else { assertThat(min).named("min of " + values).isWithin(ALLOWED_ERROR).of(MANY_VALUES_MIN); .of(INTEGER_MANY_VALUES_MIN); assertThat(INTEGER_MANY_VALUES_STATS_ITERABLE.min()) .isWithin(ALLOWED_ERROR) .of(INTEGER_MANY_VALUES_MIN); assertThat(LONG_MANY_VALUES_STATS_ITERATOR.min()) .isWithin(ALLOWED_ERROR) .of(LONG_MANY_VALUES_MIN); assertThat(LONG_MANY_VALUES_STATS_SNAPSHOT.min()) .isWithin(ALLOWED_ERROR) .of(LONG_MANY_VALUES_MIN);
} catch (IllegalArgumentException expected) { assertThat(Stats.meanOf(ONE_VALUE)).isWithin(ALLOWED_ERROR).of(ONE_VALUE); assertThat(Stats.meanOf(POSITIVE_INFINITY)).isPositiveInfinity(); assertThat(Stats.meanOf(NEGATIVE_INFINITY)).isNegativeInfinity(); assertThat(Stats.meanOf(NaN)).isNaN(); assertThat(Stats.meanOf(TWO_VALUES)).isWithin(ALLOWED_ERROR).of(TWO_VALUES_MEAN); assertThat(mean).named("mean of " + values).isNegativeInfinity(); } else { assertThat(mean).named("mean of " + values).isWithin(ALLOWED_ERROR).of(MANY_VALUES_MEAN); assertThat(Stats.meanOf(MANY_VALUES)).isWithin(ALLOWED_ERROR).of(MANY_VALUES_MEAN); assertThat(Stats.meanOf(MANY_VALUES.iterator())).isWithin(ALLOWED_ERROR).of(MANY_VALUES_MEAN); assertThat(Stats.meanOf(INTEGER_MANY_VALUES)) .isWithin(ALLOWED_ERROR) .of(INTEGER_MANY_VALUES_MEAN); assertThat(Stats.meanOf(Ints.toArray(INTEGER_MANY_VALUES))) .isWithin(ALLOWED_ERROR) .of(INTEGER_MANY_VALUES_MEAN); assertThat(Stats.meanOf(LONG_MANY_VALUES)).isWithin(ALLOWED_ERROR).of(LONG_MANY_VALUES_MEAN); assertThat(Stats.meanOf(Longs.toArray(LONG_MANY_VALUES))) .isWithin(ALLOWED_ERROR) .of(LONG_MANY_VALUES_MEAN);
.of(sqrt(TWO_VALUES_SUM_OF_SQUARES_OF_DELTAS)); assertThat(MANY_VALUES_STATS_VARARGS.sampleStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / (MANY_VALUES_COUNT - 1))); assertThat(MANY_VALUES_STATS_ITERABLE.sampleStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / (MANY_VALUES_COUNT - 1))); assertThat(MANY_VALUES_STATS_ITERATOR.sampleStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / (MANY_VALUES_COUNT - 1))); assertThat(MANY_VALUES_STATS_SNAPSHOT.sampleStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / (MANY_VALUES_COUNT - 1))); assertThat(INTEGER_MANY_VALUES_STATS_VARARGS.sampleStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(INTEGER_MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / (INTEGER_MANY_VALUES_COUNT - 1))); assertThat(INTEGER_MANY_VALUES_STATS_ITERABLE.sampleStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(INTEGER_MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / (INTEGER_MANY_VALUES_COUNT - 1))); assertThat(LONG_MANY_VALUES_STATS_ITERATOR.sampleStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(LONG_MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / (LONG_MANY_VALUES_COUNT - 1))); assertThat(LONG_MANY_VALUES_STATS_SNAPSHOT.sampleStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(LONG_MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / (LONG_MANY_VALUES_COUNT - 1)));
} catch (IllegalStateException expected) { assertThat(ONE_VALUE_STATS.max()).isWithin(ALLOWED_ERROR).of(ONE_VALUE); assertThat(Stats.of(POSITIVE_INFINITY).max()).isPositiveInfinity(); assertThat(Stats.of(NEGATIVE_INFINITY).max()).isNegativeInfinity(); assertThat(Stats.of(NaN).max()).isNaN(); assertThat(TWO_VALUES_STATS.max()).isWithin(ALLOWED_ERROR).of(TWO_VALUES_MAX); assertThat(MANY_VALUES_STATS_VARARGS.max()).isWithin(ALLOWED_ERROR).of(MANY_VALUES_MAX); assertThat(MANY_VALUES_STATS_ITERABLE.max()).isWithin(ALLOWED_ERROR).of(MANY_VALUES_MAX); assertThat(max).named("max of " + values).isPositiveInfinity(); } else { assertThat(max).named("max of " + values).isWithin(ALLOWED_ERROR).of(MANY_VALUES_MAX); assertThat(MANY_VALUES_STATS_SNAPSHOT.max()).isWithin(ALLOWED_ERROR).of(MANY_VALUES_MAX); assertThat(INTEGER_MANY_VALUES_STATS_VARARGS.max()) .isWithin(ALLOWED_ERROR) .of(INTEGER_MANY_VALUES_MAX); assertThat(INTEGER_MANY_VALUES_STATS_ITERABLE.max()) .isWithin(ALLOWED_ERROR) .of(INTEGER_MANY_VALUES_MAX); assertThat(LONG_MANY_VALUES_STATS_ITERATOR.max()) .isWithin(ALLOWED_ERROR) .of(LONG_MANY_VALUES_MAX); assertThat(LONG_MANY_VALUES_STATS_SNAPSHOT.max()) .isWithin(ALLOWED_ERROR) .of(LONG_MANY_VALUES_MAX);
.of(TWO_VALUES_SUM_OF_SQUARES_OF_DELTAS); assertThat(MANY_VALUES_STATS_VARARGS.sampleVariance()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / (MANY_VALUES_COUNT - 1)); assertThat(MANY_VALUES_STATS_ITERABLE.sampleVariance()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / (MANY_VALUES_COUNT - 1)); assertThat(MANY_VALUES_STATS_ITERATOR.sampleVariance()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / (MANY_VALUES_COUNT - 1)); assertThat(MANY_VALUES_STATS_SNAPSHOT.sampleVariance()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / (MANY_VALUES_COUNT - 1)); assertThat(INTEGER_MANY_VALUES_STATS_VARARGS.sampleVariance()) .isWithin(ALLOWED_ERROR) .of(INTEGER_MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / (INTEGER_MANY_VALUES_COUNT - 1)); assertThat(INTEGER_MANY_VALUES_STATS_ITERABLE.sampleVariance()) .isWithin(ALLOWED_ERROR) .of(INTEGER_MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / (INTEGER_MANY_VALUES_COUNT - 1)); assertThat(LONG_MANY_VALUES_STATS_ITERATOR.sampleVariance()) .isWithin(ALLOWED_ERROR) .of(LONG_MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / (LONG_MANY_VALUES_COUNT - 1)); assertThat(LONG_MANY_VALUES_STATS_SNAPSHOT.sampleVariance()) .isWithin(ALLOWED_ERROR) .of(LONG_MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / (LONG_MANY_VALUES_COUNT - 1));
public void testSum() { assertThat(emptyAccumulator.sum()).isWithin(0.0).of(0.0); assertThat(emptyAccumulatorByAddAllEmptyIterable.sum()).isWithin(0.0).of(0.0); assertThat(emptyAccumulatorByAddAllEmptyStats.sum()).isWithin(0.0).of(0.0); assertThat(oneValueAccumulator.sum()).isWithin(ALLOWED_ERROR).of(ONE_VALUE); assertThat(oneValueAccumulatorByAddAllEmptyStats.sum()).isWithin(ALLOWED_ERROR).of(ONE_VALUE); assertThat(twoValuesAccumulator.sum()).isWithin(ALLOWED_ERROR).of(TWO_VALUES_MEAN * 2); assertThat(twoValuesAccumulatorByAddAllStats.sum()) .isWithin(ALLOWED_ERROR) .of(TWO_VALUES_MEAN * 2); assertThat(manyValuesAccumulatorByAddAllIterable.sum()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_MEAN * MANY_VALUES_COUNT); assertThat(manyValuesAccumulatorByAddAllIterator.sum()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_MEAN * MANY_VALUES_COUNT); assertThat(manyValuesAccumulatorByAddAllVarargs.sum()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_MEAN * MANY_VALUES_COUNT); assertThat(manyValuesAccumulatorByRepeatedAdd.sum()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_MEAN * MANY_VALUES_COUNT); assertThat(manyValuesAccumulatorByAddAndAddAll.sum()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_MEAN * MANY_VALUES_COUNT); assertThat(manyValuesAccumulatorByAddAllStats.sum()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_MEAN * MANY_VALUES_COUNT); assertThat(integerManyValuesAccumulatorByAddAllIterable.sum()) .isWithin(ALLOWED_ERROR)
assertThat(actualStats.mean()).isWithin(ALLOWED_ERROR).of(expectedStats.mean()); assertThat(actualStats.populationVariance()).isWithin(0.0).of(0.0); assertThat(actualStats.min()).isWithin(ALLOWED_ERROR).of(expectedStats.min()); assertThat(actualStats.max()).isWithin(ALLOWED_ERROR).of(expectedStats.max()); } else { assertThat(actualStats.mean()).isWithin(ALLOWED_ERROR).of(expectedStats.mean()); assertThat(actualStats.populationVariance()) .isWithin(ALLOWED_ERROR) .of(expectedStats.populationVariance()); assertThat(actualStats.min()).isWithin(ALLOWED_ERROR).of(expectedStats.min()); assertThat(actualStats.max()).isWithin(ALLOWED_ERROR).of(expectedStats.max());
assertThat(ONE_VALUE_STATS.populationStandardDeviation()).isWithin(0.0).of(0.0); assertThat(TWO_VALUES_STATS.populationStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(TWO_VALUES_SUM_OF_SQUARES_OF_DELTAS / 2)); assertThat(MANY_VALUES_STATS_VARARGS.populationStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / MANY_VALUES_COUNT)); assertThat(MANY_VALUES_STATS_ITERABLE.populationStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / MANY_VALUES_COUNT)); assertThat(MANY_VALUES_STATS_ITERATOR.populationStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / MANY_VALUES_COUNT)); assertThat(MANY_VALUES_STATS_SNAPSHOT.populationStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / MANY_VALUES_COUNT)); assertThat(INTEGER_MANY_VALUES_STATS_VARARGS.populationStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(INTEGER_MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / INTEGER_MANY_VALUES_COUNT)); assertThat(INTEGER_MANY_VALUES_STATS_ITERABLE.populationStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(INTEGER_MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / INTEGER_MANY_VALUES_COUNT)); assertThat(LONG_MANY_VALUES_STATS_ITERATOR.populationStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(LONG_MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / LONG_MANY_VALUES_COUNT)); assertThat(LONG_MANY_VALUES_STATS_SNAPSHOT.populationStandardDeviation()) .isWithin(ALLOWED_ERROR) .of(sqrt(LONG_MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / LONG_MANY_VALUES_COUNT));
public void testSum() { assertThat(EMPTY_STATS_VARARGS.sum()).isEqualTo(0.0); assertThat(EMPTY_STATS_ITERABLE.sum()).isEqualTo(0.0); assertThat(ONE_VALUE_STATS.sum()).isWithin(ALLOWED_ERROR).of(ONE_VALUE); assertThat(TWO_VALUES_STATS.sum()).isWithin(ALLOWED_ERROR).of(TWO_VALUES_MEAN * 2); assertThat(MANY_VALUES_STATS_VARARGS.sum()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_MEAN * MANY_VALUES_COUNT); assertThat(MANY_VALUES_STATS_ITERABLE.sum()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_MEAN * MANY_VALUES_COUNT); assertThat(MANY_VALUES_STATS_ITERATOR.sum()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_MEAN * MANY_VALUES_COUNT); assertThat(MANY_VALUES_STATS_SNAPSHOT.sum()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_MEAN * MANY_VALUES_COUNT); assertThat(INTEGER_MANY_VALUES_STATS_VARARGS.sum()) .isWithin(ALLOWED_ERROR) .of(INTEGER_MANY_VALUES_MEAN * INTEGER_MANY_VALUES_COUNT); assertThat(INTEGER_MANY_VALUES_STATS_ITERABLE.sum()) .isWithin(ALLOWED_ERROR) .of(INTEGER_MANY_VALUES_MEAN * INTEGER_MANY_VALUES_COUNT); assertThat(LONG_MANY_VALUES_STATS_ITERATOR.sum()) .isWithin(ALLOWED_ERROR) .of(LONG_MANY_VALUES_MEAN * LONG_MANY_VALUES_COUNT); assertThat(LONG_MANY_VALUES_STATS_SNAPSHOT.sum()) .isWithin(ALLOWED_ERROR) .of(LONG_MANY_VALUES_MEAN * LONG_MANY_VALUES_COUNT); }
} catch (IllegalStateException expected) { assertThat(ONE_VALUE_PAIRED_STATS.populationCovariance()).isWithin(0.0).of(0.0); assertThat(createSingleStats(Double.POSITIVE_INFINITY, 1.23).populationCovariance()).isNaN(); assertThat(createSingleStats(Double.NEGATIVE_INFINITY, 1.23).populationCovariance()).isNaN(); assertThat(TWO_VALUES_PAIRED_STATS.populationCovariance()) .isWithin(ALLOWED_ERROR) .of(TWO_VALUES_SUM_OF_PRODUCTS_OF_DELTAS / 2); .named("population covariance of " + values) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_SUM_OF_PRODUCTS_OF_DELTAS / MANY_VALUES_COUNT); .of(0.0); assertThat(VERTICAL_VALUES_PAIRED_STATS.populationCovariance()).isWithin(ALLOWED_ERROR).of(0.0); assertThat(CONSTANT_VALUES_PAIRED_STATS.populationCovariance()).isWithin(ALLOWED_ERROR).of(0.0);
/** * Asserts that {@code transformation} is vertical with the given value of {@code x}. Includes * assertions about all the public instance methods of {@link LinearTransformation}, including * assertions that {@link LinearTransformation#slope} and {@link LinearTransformation#transform} * throw as expected. */ static void assertVerticalLinearTransformation(LinearTransformation transformation, double x) { assertThat(transformation.isHorizontal()).isFalse(); assertThat(transformation.isVertical()).isTrue(); assertThat(transformation.inverse().isHorizontal()).isTrue(); assertThat(transformation.inverse().isVertical()).isFalse(); try { transformation.transform(0.0); fail("Expected IllegalStateException"); } catch (IllegalStateException expected) { } assertThat(transformation.inverse().transform(-1.0)).isWithin(ALLOWED_ERROR).of(x); assertThat(transformation.inverse().transform(1.0)).isWithin(ALLOWED_ERROR).of(x); try { transformation.slope(); fail("Expected IllegalStateException"); } catch (IllegalStateException expected) { } assertThat(transformation.inverse().slope()).isWithin(ALLOWED_ERROR).of(0.0); assertThat(transformation.inverse()).isSameAs(transformation.inverse()); assertThat(transformation.inverse().inverse()).isSameAs(transformation); }
/** * Asserts that {@code transformation} is horizontal with the given value of {@code y}. Includes * assertions about all the public instance methods of {@link LinearTransformation}, including an * assertion that {@link LinearTransformation#transform} and {@link LinearTransformation#slope} on * its inverse throws as expected. */ static void assertHorizontalLinearTransformation(LinearTransformation transformation, double y) { assertThat(transformation.isHorizontal()).isTrue(); assertThat(transformation.isVertical()).isFalse(); assertThat(transformation.inverse().isHorizontal()).isFalse(); assertThat(transformation.inverse().isVertical()).isTrue(); assertThat(transformation.transform(-1.0)).isWithin(ALLOWED_ERROR).of(y); assertThat(transformation.transform(1.0)).isWithin(ALLOWED_ERROR).of(y); try { transformation.inverse().transform(0.0); fail("Expected IllegalStateException"); } catch (IllegalStateException expected) { } assertThat(transformation.slope()).isWithin(ALLOWED_ERROR).of(0.0); try { transformation.inverse().slope(); fail("Expected IllegalStateException"); } catch (IllegalStateException expected) { } assertThat(transformation.inverse()).isSameAs(transformation.inverse()); assertThat(transformation.inverse().inverse()).isSameAs(transformation); }
/** * Asserts that {@code transformation} is diagonal (i.e. neither horizontal or vertical) and * passes through both {@code (x1, y1)} and {@code (x1 + xDelta, y1 + yDelta)}. Includes * assertions about all the public instance methods of {@link LinearTransformation} (on both * {@code transformation} and its inverse). Since the transformation is expected to be diagonal, * neither {@code xDelta} nor {@code yDelta} may be zero. */ static void assertDiagonalLinearTransformation( LinearTransformation transformation, double x1, double y1, double xDelta, double yDelta) { checkArgument(xDelta != 0.0); checkArgument(yDelta != 0.0); assertThat(transformation.isHorizontal()).isFalse(); assertThat(transformation.isVertical()).isFalse(); assertThat(transformation.inverse().isHorizontal()).isFalse(); assertThat(transformation.inverse().isVertical()).isFalse(); assertThat(transformation.transform(x1)).isWithin(ALLOWED_ERROR).of(y1); assertThat(transformation.transform(x1 + xDelta)).isWithin(ALLOWED_ERROR).of(y1 + yDelta); assertThat(transformation.inverse().transform(y1)).isWithin(ALLOWED_ERROR).of(x1); assertThat(transformation.inverse().transform(y1 + yDelta)) .isWithin(ALLOWED_ERROR) .of(x1 + xDelta); assertThat(transformation.slope()).isWithin(ALLOWED_ERROR).of(yDelta / xDelta); assertThat(transformation.inverse().slope()).isWithin(ALLOWED_ERROR).of(xDelta / yDelta); assertThat(transformation.inverse()).isSameAs(transformation.inverse()); assertThat(transformation.inverse().inverse()).isSameAs(transformation); }
public void testSampleCovariance() { try { EMPTY_PAIRED_STATS.sampleCovariance(); fail("Expected IllegalStateException"); } catch (IllegalStateException expected) { } try { ONE_VALUE_PAIRED_STATS.sampleCovariance(); fail("Expected IllegalStateException"); } catch (IllegalStateException expected) { } assertThat(TWO_VALUES_PAIRED_STATS.sampleCovariance()) .isWithin(ALLOWED_ERROR) .of(TWO_VALUES_SUM_OF_PRODUCTS_OF_DELTAS); assertThat(MANY_VALUES_PAIRED_STATS.sampleCovariance()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_SUM_OF_PRODUCTS_OF_DELTAS / (MANY_VALUES_COUNT - 1)); assertThat(HORIZONTAL_VALUES_PAIRED_STATS.sampleCovariance()).isWithin(ALLOWED_ERROR).of(0.0); assertThat(VERTICAL_VALUES_PAIRED_STATS.sampleCovariance()).isWithin(ALLOWED_ERROR).of(0.0); assertThat(CONSTANT_VALUES_PAIRED_STATS.sampleCovariance()).isWithin(ALLOWED_ERROR).of(0.0); }