From 9d32754bc0456f3026be8cb8ad7009e776b3d1a6 Mon Sep 17 00:00:00 2001 From: Jeanette Tan Date: Fri, 22 Mar 2024 03:42:50 +0800 Subject: [PATCH] add unit tests with all negative values for histogram_stddev and var Signed-off-by: Jeanette Tan --- promql/engine_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/promql/engine_test.go b/promql/engine_test.go index cc5d0ee78..3f5f2dc13 100644 --- a/promql/engine_test.go +++ b/promql/engine_test.go @@ -3498,6 +3498,38 @@ func TestNativeHistogram_HistogramStdDevVar(t *testing.T) { }, stdVar: 1544.8582535368798, // actual variance: 1738.4082 }, + { + name: "-100000, -10000, -1000, -888, -888, -100, -50, -9, -8, -3", + h: &histogram.Histogram{ + Count: 10, + ZeroCount: 0, + Sum: -112946, + Schema: 0, + NegativeSpans: []histogram.Span{ + {Offset: 2, Length: 3}, + {Offset: 1, Length: 2}, + {Offset: 2, Length: 1}, + {Offset: 3, Length: 1}, + {Offset: 2, Length: 1}, + }, + NegativeBuckets: []int64{1, 0, 0, 0, 0, 2, -2, 0}, + }, + stdVar: 1240930974.5260057, // actual variance: 882690990 + }, + { + name: "-10 x10", + h: &histogram.Histogram{ + Count: 10, + ZeroCount: 0, + Sum: -100, + Schema: 0, + NegativeSpans: []histogram.Span{ + {Offset: 4, Length: 1}, + }, + NegativeBuckets: []int64{10}, + }, + stdVar: 454.2741699796952, // actual variance: 0 + }, { name: "-50, -8, 0, 3, 8, 9, 100, NaN", h: &histogram.Histogram{