Merge pull request #1689 from anywhy/fix_float64_series

fix float64 series use mean or stdev function result is zero
This commit is contained in:
c9s 2024-08-20 14:41:29 +08:00 committed by GitHub
commit baffefac07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

@ -13,7 +13,7 @@ type Float64Series struct {
func NewFloat64Series(v ...float64) *Float64Series { func NewFloat64Series(v ...float64) *Float64Series {
s := &Float64Series{} s := &Float64Series{}
s.Slice = v s.Slice = v
s.SeriesBase.Series = s.Slice s.SeriesBase.Series = &s.Slice
return s return s
} }

View File

@ -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)
}