@Test
  public void testLongAvgWithExtractor() throws Exception {

    Value<Long>[] values =
        buildValues(
            new ValueProvider<Long>() {
              @Override
              public Long provideRandom(Random random) {
                return 10000L + random(1000, 2000);
              }
            });

    long expectation = 0;
    for (int i = 0; i < values.length; i++) {
      expectation += values[i].value;
    }
    expectation = (long) ((double) expectation / values.length);

    Aggregation<String, Long, Long> aggregation = Aggregations.longAvg();
    long result = testAvgWithExtractor(values, aggregation);
    assertEquals(expectation, result);
  }
  @Test
  public void testDoubleAvgWithExtractor() throws Exception {

    Value<Double>[] values =
        buildValues(
            new ValueProvider<Double>() {
              @Override
              public Double provideRandom(Random random) {
                return 10000.0D + random(1000, 2000);
              }
            });

    double expectation = 0;
    for (int i = 0; i < values.length; i++) {
      expectation += values[i].value;
    }
    expectation = expectation / values.length;

    Aggregation<String, Double, Double> aggregation = Aggregations.doubleAvg();
    double result = testAvgWithExtractor(values, aggregation);
    assertEquals(expectation, result, 0.0);
  }
  @Test
  public void testIntegerAvgWithExtractor() throws Exception {

    Value<Integer>[] values =
        buildValues(
            new ValueProvider<Integer>() {
              @Override
              public Integer provideRandom(Random random) {
                return random(1000, 2000);
              }
            });

    int expectation = 0;
    for (int i = 0; i < values.length; i++) {
      expectation += values[i].value;
    }
    expectation = (int) ((double) expectation / values.length);

    Aggregation<String, Integer, Integer> aggregation = Aggregations.integerAvg();
    int result = testAvgWithExtractor(values, aggregation);
    assertEquals(expectation, result);
  }
  @Test
  public void testBigIntegerAvgWithExtractor() throws Exception {

    Value<BigInteger>[] values =
        buildValues(
            new ValueProvider<BigInteger>() {
              @Override
              public BigInteger provideRandom(Random random) {
                return BigInteger.valueOf(10000L + random(1000, 2000));
              }
            });

    BigInteger expectation = BigInteger.ZERO;
    for (int i = 0; i < values.length; i++) {
      expectation = expectation.add(values[i].value);
    }
    expectation = expectation.divide(BigInteger.valueOf(values.length));

    Aggregation<String, BigInteger, BigInteger> aggregation = Aggregations.bigIntegerAvg();
    BigInteger result = testAvgWithExtractor(values, aggregation);
    assertEquals(expectation, result);
  }
  @Test
  public void testBigDecimalAvg() throws Exception {

    BigDecimal[] values =
        buildPlainValues(
            new ValueProvider<BigDecimal>() {
              @Override
              public BigDecimal provideRandom(Random random) {
                return BigDecimal.valueOf(10000.0D + random(1000, 2000));
              }
            },
            BigDecimal.class);

    BigDecimal expectation = BigDecimal.ZERO;
    for (int i = 0; i < values.length; i++) {
      expectation = expectation.add(values[i]);
    }
    expectation = expectation.divide(BigDecimal.valueOf(values.length));

    Aggregation<String, BigDecimal, BigDecimal> aggregation = Aggregations.bigDecimalAvg();
    BigDecimal result = testAvg(values, aggregation);
    assertEquals(expectation, result);
  }