qbtrade/pkg/indicator/vidya_test.go
2024-06-27 22:42:38 +08:00

20 lines
435 B
Go

package indicator
import (
"testing"
"git.qtrade.icu/lychiyu/qbtrade/pkg/types"
"github.com/stretchr/testify/assert"
)
func Test_VIDYA(t *testing.T) {
vidya := &VIDYA{IntervalWindow: types.IntervalWindow{Window: 16}}
vidya.Update(1)
assert.Equal(t, vidya.Last(0), 1.)
vidya.Update(2)
newV := 2./17.*2. + 1.*(1.-2./17.)
assert.Equal(t, vidya.Last(0), newV)
vidya.Update(1)
assert.Equal(t, vidya.Last(0), vidya.Index(1))
}