Skip to content

Commit

Permalink
Fix test bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpountz committed Feb 6, 2017
1 parent ffab6c9 commit ee6fe29
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@

package org.elasticsearch.search.aggregations.bucket.histogram;

import org.apache.lucene.util.TestUtil;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.InternalAggregationTestCase;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class InternalHistogramTests extends InternalAggregationTestCase<InternalHistogram> {

Expand All @@ -42,22 +43,23 @@ protected InternalHistogram createTestInstance(String name, List<PipelineAggrega
final int interval = randomIntBetween(1, 3);
List<InternalHistogram.Bucket> buckets = new ArrayList<>();
for (int i = 0; i < numBuckets; ++i) {
buckets.add(new InternalHistogram.Bucket(base + i * interval, randomInt(50), keyed, format, InternalAggregations.EMPTY));
final int docCount = TestUtil.nextInt(random(), 1, 50);
buckets.add(new InternalHistogram.Bucket(base + i * interval, docCount, keyed, format, InternalAggregations.EMPTY));
}
return new InternalHistogram(name, buckets, (InternalOrder) InternalHistogram.Order.KEY_ASC,
1, null, format, keyed, pipelineAggregators, metaData);
}

@Override
protected void assertReduced(InternalHistogram reduced, List<InternalHistogram> inputs) {
Map<Double, Long> expectedCounts = new HashMap<>();
Map<Double, Long> expectedCounts = new TreeMap<>();
for (Histogram histogram : inputs) {
for (Histogram.Bucket bucket : histogram.getBuckets()) {
expectedCounts.compute((Double) bucket.getKey(),
(key, oldValue) -> (oldValue == null ? 0 : oldValue) + bucket.getDocCount());
}
}
Map<Double, Long> actualCounts = new HashMap<>();
Map<Double, Long> actualCounts = new TreeMap<>();
for (Histogram.Bucket bucket : reduced.getBuckets()) {
actualCounts.compute((Double) bucket.getKey(),
(key, oldValue) -> (oldValue == null ? 0 : oldValue) + bucket.getDocCount());
Expand Down

0 comments on commit ee6fe29

Please sign in to comment.