@Test
public void testAggregateWithWeightedAverage() {

    Map<Long, List<Pair<String, Double>>> keyMetric = new HashMap<>();
    List<Pair<String, Double>> keyPoints1 = new ArrayList<>();
    keyPoints1.add(Pair.of("stream1", 10.0));
    keyPoints1.add(Pair.of("stream2", 20.0));
    keyMetric.put(1L, keyPoints1);
    List<Pair<String, Double>> keyPoints2 = new ArrayList<>();
    keyPoints2.add(Pair.of("stream1", 10.0));
    keyPoints2.add(Pair.of("stream2", 20.0));
    keyMetric.put(2L, keyPoints2);
    Map<Long, List<Pair<String, Double>>> weightMetric = new HashMap<>();
    List<Pair<String, Double>> weightPoints1 = new ArrayList<>();
    weightPoints1.add(Pair.of("stream1", 10.0));
    weightPoints1.add(Pair.of("stream2", 5.0));
    weightMetric.put(1L, weightPoints1);
    List<Pair<String, Double>> weightPoints2 = new ArrayList<>();
    weightPoints2.add(Pair.of("stream1", 5.0));
    weightPoints2.add(Pair.of("stream2", 10.0));
    weightMetric.put(2L, weightPoints2);
    Map<Long, Double> ret = querier.aggregateWithApplyingWeightedAverage(keyMetric, weightMetric);
    Assert.assertEquals(2, ret.size());
    Double aggregated = ret.get(1L);
    Assert.assertNotNull(aggregated);
    Double expected = 10.0 * 10.0 / (10.0 + 5.0) + 20.0 * 5.0 / (10.0 + 5.0);
    Assert.assertEquals(expected, aggregated, 0.00001d);
    aggregated = ret.get(2L);
    Assert.assertNotNull(aggregated);
    expected = 10.0 * 5.0 / (5.0 + 10.0) + 20.0 * 10.0 / (5.0 + 10.0);
    Assert.assertEquals(expected, aggregated, 0.00001d);
}