mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
indicator: fix test cases
This commit is contained in:
parent
16c62eab2b
commit
82673e501b
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user