Skip to content

Commit

Permalink
Remove generic
Browse files Browse the repository at this point in the history
Add test
  • Loading branch information
a.usenko authored and anti-social committed Dec 28, 2023
1 parent 71561a3 commit fc38444
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ data class PercentileAggResult(val values: Map<Double, Double>) : AggregationRes
}
}

data class PercentilesAgg<T>(
val field: FieldOperations<T>,
data class PercentilesAgg(
val field: FieldOperations<*>,
val percents: List<Double> = listOf(1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0),
) : MetricAggregation<PercentileAggResult>() {
override fun processResult(obj: Deserializer.ObjectCtx): PercentileAggResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,39 @@ class MetricTests : TestAggregation() {

@Test
fun percentile() {
val agg = PercentilesAgg(
MovieDoc.rating,
percents = listOf(1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0),
val ratingAgg = PercentilesAgg(
MovieDoc.rating
)
agg.compile() shouldContainExactly mapOf(
ratingAgg.compile() shouldContainExactly mapOf(
"percentiles" to mapOf(
"field" to "rating",
"percents" to listOf(1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0),
)
)

val numRatingsAgg = PercentilesAgg(
MovieDoc.numRatings,
percents = listOf(25.0, 50.0, 75.0, 95.0, 99.0),
)

numRatingsAgg.compile() shouldContainExactly mapOf(
"percentiles" to mapOf(
"field" to "num_ratings",
"percents" to listOf(25.0, 50.0, 75.0, 95.0, 99.0),
)
)



shouldThrow<DeserializationException> {
process(
agg,
ratingAgg,
mapOf("values" to null)
)
}

process(
agg,
ratingAgg,
mapOf(
"values" to mapOf(
"1.0" to 0.9,
Expand All @@ -100,6 +114,27 @@ class MetricTests : TestAggregation() {
99.0 to 6.6,
)
}

process(
numRatingsAgg,
mapOf(
"values" to mapOf(
"25.0" to 1.0,
"50.0" to 2.0,
"75.0" to 3.0,
"95.0" to 4.0,
"99.0" to 5.0,
),
)
).let { res ->
res.values shouldBe mapOf(
25.0 to 1.0,
50.0 to 2.0,
75.0 to 3.0,
95.0 to 4.0,
99.0 to 5.0,
)
}
}

@Test
Expand Down

0 comments on commit fc38444

Please sign in to comment.