@@ -0,0 +1,3356 @@
+/*%0A * Licensed to Elasticsearch under one or more contributor%0A * license agreements. See the NOTICE file distributed with%0A * this work for additional information regarding copyright%0A * ownership. Elasticsearch licenses this file to you under%0A * the Apache License, Version 2.0 (the %22License%22); you may%0A * not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *    http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing,%0A * software distributed under the License is distributed on an%0A * %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY%0A * KIND, either express or implied.  See the License for the%0A * specific language governing permissions and limitations%0A * under the License.%0A */%0A%0Apackage org.elasticsearch.search.aggregations.metrics.percentiles.tdigest;%0A%0Aimport org.elasticsearch.common.io.stream.Writeable;%0Aimport org.elasticsearch.search.DocValueFormat;%0Aimport org.elasticsearch.search.aggregations.InternalAggregationTestCase;%0Aimport org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;%0A%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0Apublic class InternalTDigestPercentilesTests extends InternalAggregationTestCase%3CInternalTDigestPercentiles%3E %7B%0A%0A    private final double%5B%5D percents = randomPercents();%0A%0A    @Override%0A    protected InternalTDigestPercentiles createTestInstance(String name,%0A                                                            List%3CPipelineAggregator%3E pipelineAggregators,%0A                                                            Map%3CString, Object%3E metaData) %7B%0A        boolean keyed = randomBoolean();%0A        DocValueFormat format = DocValueFormat.RAW;%0A        TDigestState state = new TDigestState(100);%0A%0A        int numValues = randomInt(10);%0A        for (int i = 0; i %3C numValues; ++i) %7B%0A            state.add(randomDouble() * 100);%0A        %7D%0A        assertEquals(state.centroidCount(), numValues);%0A        return new InternalTDigestPercentiles(name, percents, state, keyed, format, pipelineAggregators, metaData);%0A    %7D%0A%0A    @Override%0A    protected void assertReduced(InternalTDigestPercentiles reduced, List%3CInternalTDigestPercentiles%3E inputs) %7B%0A        final TDigestState expectedState = new TDigestState(reduced.state.compression());%0A%0A        long totalCount = 0;%0A        for (InternalTDigestPercentiles input : inputs) %7B%0A            assertArrayEquals(reduced.keys, input.keys, 0d);%0A            expectedState.add(input.state);%0A            totalCount += input.state.size();%0A        %7D%0A%0A        assertEquals(totalCount, reduced.state.size());%0A        if (totalCount %3E 0) %7B%0A            assertEquals(expectedState.quantile(0), reduced.state.quantile(0), 0d);%0A            assertEquals(expectedState.quantile(1), reduced.state.quantile(1), 0d);%0A        %7D%0A    %7D%0A%0A    @Override%0A    protected Writeable.Reader%3CInternalTDigestPercentiles%3E instanceReader() %7B%0A        return InternalTDigestPercentiles::new;%0A    %7D%0A%0A    private static double%5B%5D randomPercents() %7B%0A        List%3CDouble%3E randomCdfValues = randomSubsetOf(randomIntBetween(1, 7), 0.01d, 0.05d, 0.25d, 0.50d, 0.75d, 0.95d, 0.99d);%0A        double%5B%5D percents = new double%5BrandomCdfValues.size()%5D;%0A        for (int i = 0; i %3C randomCdfValues.size(); i++) %7B%0A            percents%5Bi%5D = randomCdfValues.get(i);%0A        %7D%0A        return percents;%0A    %7D%0A%7D%0A

Add unit tests for InternalTDigestPercentilesTests (#24090)