indicator: fix test cases

This commit is contained in:
c9s 2022-07-26 18:07:28 +08:00
parent 16c62eab2b
commit 82673e501b
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 11 additions and 3 deletions

View File

@ -4,9 +4,10 @@ import (
"encoding/json" "encoding/json"
"testing" "testing"
"github.com/stretchr/testify/assert"
"github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
"github.com/stretchr/testify/assert"
) )
/* /*
@ -52,7 +53,11 @@ func Test_SMA(t *testing.T) {
sma := SMA{ sma := SMA{
IntervalWindow: types.IntervalWindow{Window: 5}, IntervalWindow: types.IntervalWindow{Window: 5},
} }
sma.CalculateAndUpdate(tt.kLines)
for _, k := range tt.kLines {
sma.PushK(k)
}
assert.InDelta(t, tt.want, sma.Last(), Delta) assert.InDelta(t, tt.want, sma.Last(), Delta)
assert.InDelta(t, tt.next, sma.Index(1), Delta) assert.InDelta(t, tt.next, sma.Index(1), Delta)
sma.Update(tt.update) sma.Update(tt.update)

View File

@ -56,7 +56,10 @@ func TestSTOCH_update(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
kd := STOCH{IntervalWindow: types.IntervalWindow{Window: tt.window}} kd := STOCH{IntervalWindow: types.IntervalWindow{Window: tt.window}}
kd.CalculateAndUpdate(tt.kLines)
for _, k := range tt.kLines {
kd.PushK(k)
}
got_k := kd.LastK() got_k := kd.LastK()
diff_k := math.Trunc((got_k-tt.want_k)*100) / 100 diff_k := math.Trunc((got_k-tt.want_k)*100) / 100