Skip to content

Commit

Permalink
Merge pull request #1689 from anywhy/fix_float64_series
Browse files Browse the repository at this point in the history
fix float64 series use mean or stdev function result is zero
  • Loading branch information
c9s authored Aug 20, 2024
2 parents d1617b6 + b27fc89 commit baffefa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/types/series_float64.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/types/series_float64_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit baffefa

Please sign in to comment.