From 8773c220f50b8ed4d5148c4f8d10fa2b710c3247 Mon Sep 17 00:00:00 2001 From: Any Yang Date: Wed, 7 Aug 2024 17:52:39 +0800 Subject: [PATCH 1/2] fix float64 series use mean or stdev function result is zero --- pkg/types/series_float64.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/types/series_float64.go b/pkg/types/series_float64.go index 8c07b4a13..904d22958 100644 --- a/pkg/types/series_float64.go +++ b/pkg/types/series_float64.go @@ -13,7 +13,7 @@ type Float64Series struct { func NewFloat64Series(v ...float64) *Float64Series { s := &Float64Series{} s.Slice = v - s.SeriesBase.Series = s.Slice + s.SeriesBase.Series = &s.Slice return s } From b27fc896f98c087e3264457f1f4654a07ee12289 Mon Sep 17 00:00:00 2001 From: anywhy Date: Thu, 15 Aug 2024 16:44:45 +0800 Subject: [PATCH 2/2] add serie_float64 test case --- pkg/types/series_float64_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 pkg/types/series_float64_test.go diff --git a/pkg/types/series_float64_test.go b/pkg/types/series_float64_test.go new file mode 100644 index 000000000..270cd92f8 --- /dev/null +++ b/pkg/types/series_float64_test.go @@ -0,0 +1,18 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestSeriesBaseFuncWithPushData(t *testing.T) { + series := NewFloat64Series(0.5, 1.0) + series.Push(2.5) + series.Push(3.0) + series.Push(4.0) + mean := series.Mean(5) + assert.Equal(t, 2.2, mean) + stdev := series.Stdev(5) + assert.Equal(t, 1.2884098726725126, stdev) +}