begin_unit|revision:0.9.5;language:Java;cregit-version:0.0.1
begin_comment
comment|/*  * Licensed to Elasticsearch under one or more contributor  * license agreements. See the NOTICE file distributed with  * this work for additional information regarding copyright  * ownership. Elasticsearch licenses this file to you under  * the Apache License, Version 2.0 (the "License"); you may  * not use this file except in compliance with the License.  * You may obtain a copy of the License at  *  *    http://www.apache.org/licenses/LICENSE-2.0  *  * Unless required by applicable law or agreed to in writing,  * software distributed under the License is distributed on an  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY  * KIND, either express or implied.  See the License for the  * specific language governing permissions and limitations  * under the License.  */
end_comment

begin_package
DECL|package|org.elasticsearch.search.aggregations.metrics.percentiles.hdr
package|package
name|org
operator|.
name|elasticsearch
operator|.
name|search
operator|.
name|aggregations
operator|.
name|metrics
operator|.
name|percentiles
operator|.
name|hdr
package|;
end_package

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|lucene
operator|.
name|document
operator|.
name|Document
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|lucene
operator|.
name|document
operator|.
name|SortedNumericDocValuesField
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|lucene
operator|.
name|index
operator|.
name|IndexReader
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|lucene
operator|.
name|index
operator|.
name|MultiReader
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|lucene
operator|.
name|index
operator|.
name|RandomIndexWriter
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|lucene
operator|.
name|search
operator|.
name|IndexSearcher
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|lucene
operator|.
name|search
operator|.
name|MatchAllDocsQuery
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|lucene
operator|.
name|store
operator|.
name|Directory
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|lucene
operator|.
name|util
operator|.
name|NumericUtils
import|;
end_import

begin_import
import|import
name|org
operator|.
name|elasticsearch
operator|.
name|index
operator|.
name|mapper
operator|.
name|MappedFieldType
import|;
end_import

begin_import
import|import
name|org
operator|.
name|elasticsearch
operator|.
name|index
operator|.
name|mapper
operator|.
name|NumberFieldMapper
import|;
end_import

begin_import
import|import
name|org
operator|.
name|elasticsearch
operator|.
name|search
operator|.
name|aggregations
operator|.
name|AggregatorTestCase
import|;
end_import

begin_import
import|import
name|org
operator|.
name|elasticsearch
operator|.
name|search
operator|.
name|aggregations
operator|.
name|metrics
operator|.
name|percentiles
operator|.
name|Percentile
import|;
end_import

begin_import
import|import
name|org
operator|.
name|elasticsearch
operator|.
name|search
operator|.
name|aggregations
operator|.
name|metrics
operator|.
name|percentiles
operator|.
name|PercentileRanks
import|;
end_import

begin_import
import|import
name|org
operator|.
name|elasticsearch
operator|.
name|search
operator|.
name|aggregations
operator|.
name|metrics
operator|.
name|percentiles
operator|.
name|PercentileRanksAggregationBuilder
import|;
end_import

begin_import
import|import
name|org
operator|.
name|elasticsearch
operator|.
name|search
operator|.
name|aggregations
operator|.
name|metrics
operator|.
name|percentiles
operator|.
name|PercentilesMethod
import|;
end_import

begin_import
import|import
name|org
operator|.
name|hamcrest
operator|.
name|Matchers
import|;
end_import

begin_import
import|import
name|java
operator|.
name|io
operator|.
name|IOException
import|;
end_import

begin_import
import|import
name|java
operator|.
name|util
operator|.
name|Iterator
import|;
end_import

begin_class
DECL|class|HDRPercentileRanksAggregatorTests
specifier|public
class|class
name|HDRPercentileRanksAggregatorTests
extends|extends
name|AggregatorTestCase
block|{
DECL|method|testEmpty
specifier|public
name|void
name|testEmpty
parameter_list|()
throws|throws
name|IOException
block|{
name|PercentileRanksAggregationBuilder
name|aggBuilder
init|=
operator|new
name|PercentileRanksAggregationBuilder
argument_list|(
literal|"my_agg"
argument_list|)
operator|.
name|field
argument_list|(
literal|"field"
argument_list|)
operator|.
name|method
argument_list|(
name|PercentilesMethod
operator|.
name|HDR
argument_list|)
operator|.
name|values
argument_list|(
literal|0.5
argument_list|)
decl_stmt|;
name|MappedFieldType
name|fieldType
init|=
operator|new
name|NumberFieldMapper
operator|.
name|NumberFieldType
argument_list|(
name|NumberFieldMapper
operator|.
name|NumberType
operator|.
name|DOUBLE
argument_list|)
decl_stmt|;
name|fieldType
operator|.
name|setName
argument_list|(
literal|"field"
argument_list|)
expr_stmt|;
try|try
init|(
name|IndexReader
name|reader
init|=
operator|new
name|MultiReader
argument_list|()
init|)
block|{
name|IndexSearcher
name|searcher
init|=
operator|new
name|IndexSearcher
argument_list|(
name|reader
argument_list|)
decl_stmt|;
name|PercentileRanks
name|ranks
init|=
name|search
argument_list|(
name|searcher
argument_list|,
operator|new
name|MatchAllDocsQuery
argument_list|()
argument_list|,
name|aggBuilder
argument_list|,
name|fieldType
argument_list|)
decl_stmt|;
name|Percentile
name|rank
init|=
name|ranks
operator|.
name|iterator
argument_list|()
operator|.
name|next
argument_list|()
decl_stmt|;
name|assertEquals
argument_list|(
name|Double
operator|.
name|NaN
argument_list|,
name|rank
operator|.
name|getPercent
argument_list|()
argument_list|,
literal|0d
argument_list|)
expr_stmt|;
name|assertEquals
argument_list|(
literal|0.5
argument_list|,
name|rank
operator|.
name|getValue
argument_list|()
argument_list|,
literal|0d
argument_list|)
expr_stmt|;
block|}
block|}
DECL|method|testSimple
specifier|public
name|void
name|testSimple
parameter_list|()
throws|throws
name|IOException
block|{
try|try
init|(
name|Directory
name|dir
init|=
name|newDirectory
argument_list|()
init|;
name|RandomIndexWriter
name|w
operator|=
operator|new
name|RandomIndexWriter
argument_list|(
name|random
argument_list|()
argument_list|,
name|dir
argument_list|)
init|)
block|{
for|for
control|(
name|double
name|value
range|:
operator|new
name|double
index|[]
block|{
literal|3
block|,
literal|0.2
block|,
literal|10
block|}
control|)
block|{
name|Document
name|doc
init|=
operator|new
name|Document
argument_list|()
decl_stmt|;
name|doc
operator|.
name|add
argument_list|(
operator|new
name|SortedNumericDocValuesField
argument_list|(
literal|"field"
argument_list|,
name|NumericUtils
operator|.
name|doubleToSortableLong
argument_list|(
name|value
argument_list|)
argument_list|)
argument_list|)
expr_stmt|;
name|w
operator|.
name|addDocument
argument_list|(
name|doc
argument_list|)
expr_stmt|;
block|}
name|PercentileRanksAggregationBuilder
name|aggBuilder
init|=
operator|new
name|PercentileRanksAggregationBuilder
argument_list|(
literal|"my_agg"
argument_list|)
operator|.
name|field
argument_list|(
literal|"field"
argument_list|)
operator|.
name|method
argument_list|(
name|PercentilesMethod
operator|.
name|HDR
argument_list|)
operator|.
name|values
argument_list|(
literal|0.1
argument_list|,
literal|0.5
argument_list|,
literal|12
argument_list|)
decl_stmt|;
name|MappedFieldType
name|fieldType
init|=
operator|new
name|NumberFieldMapper
operator|.
name|NumberFieldType
argument_list|(
name|NumberFieldMapper
operator|.
name|NumberType
operator|.
name|DOUBLE
argument_list|)
decl_stmt|;
name|fieldType
operator|.
name|setName
argument_list|(
literal|"field"
argument_list|)
expr_stmt|;
try|try
init|(
name|IndexReader
name|reader
init|=
name|w
operator|.
name|getReader
argument_list|()
init|)
block|{
name|IndexSearcher
name|searcher
init|=
operator|new
name|IndexSearcher
argument_list|(
name|reader
argument_list|)
decl_stmt|;
name|PercentileRanks
name|ranks
init|=
name|search
argument_list|(
name|searcher
argument_list|,
operator|new
name|MatchAllDocsQuery
argument_list|()
argument_list|,
name|aggBuilder
argument_list|,
name|fieldType
argument_list|)
decl_stmt|;
name|Iterator
argument_list|<
name|Percentile
argument_list|>
name|rankIterator
init|=
name|ranks
operator|.
name|iterator
argument_list|()
decl_stmt|;
name|Percentile
name|rank
init|=
name|rankIterator
operator|.
name|next
argument_list|()
decl_stmt|;
name|assertEquals
argument_list|(
literal|0.1
argument_list|,
name|rank
operator|.
name|getValue
argument_list|()
argument_list|,
literal|0d
argument_list|)
expr_stmt|;
name|assertThat
argument_list|(
name|rank
operator|.
name|getPercent
argument_list|()
argument_list|,
name|Matchers
operator|.
name|equalTo
argument_list|(
literal|0d
argument_list|)
argument_list|)
expr_stmt|;
name|rank
operator|=
name|rankIterator
operator|.
name|next
argument_list|()
expr_stmt|;
name|assertEquals
argument_list|(
literal|0.5
argument_list|,
name|rank
operator|.
name|getValue
argument_list|()
argument_list|,
literal|0d
argument_list|)
expr_stmt|;
name|assertThat
argument_list|(
name|rank
operator|.
name|getPercent
argument_list|()
argument_list|,
name|Matchers
operator|.
name|greaterThan
argument_list|(
literal|0d
argument_list|)
argument_list|)
expr_stmt|;
name|assertThat
argument_list|(
name|rank
operator|.
name|getPercent
argument_list|()
argument_list|,
name|Matchers
operator|.
name|lessThan
argument_list|(
literal|100d
argument_list|)
argument_list|)
expr_stmt|;
name|rank
operator|=
name|rankIterator
operator|.
name|next
argument_list|()
expr_stmt|;
name|assertEquals
argument_list|(
literal|12
argument_list|,
name|rank
operator|.
name|getValue
argument_list|()
argument_list|,
literal|0d
argument_list|)
expr_stmt|;
name|assertThat
argument_list|(
name|rank
operator|.
name|getPercent
argument_list|()
argument_list|,
name|Matchers
operator|.
name|equalTo
argument_list|(
literal|100d
argument_list|)
argument_list|)
expr_stmt|;
name|assertFalse
argument_list|(
name|rankIterator
operator|.
name|hasNext
argument_list|()
argument_list|)
expr_stmt|;
block|}
block|}
block|}
block|}
end_class

end_unit

