bbgo/pkg/indicator/drift_test.go

41 lines
968 B
Go
Raw Normal View History

package indicator
import (
"encoding/json"
"testing"
"git.qtrade.icu/lychiyu/bbgo/pkg/fixedpoint"
"git.qtrade.icu/lychiyu/bbgo/pkg/types"
"github.com/stretchr/testify/assert"
)
func Test_Drift(t *testing.T) {
var randomPrices = []byte(`[1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4, 1, 2, 3, 4, 5, 6, 7, 8, 9]`)
var input []fixedpoint.Value
if err := json.Unmarshal(randomPrices, &input); err != nil {
panic(err)
}
tests := []struct {
name string
kLines []types.KLine
all int
}{
{
name: "random_case",
kLines: buildKLines(input),
all: 47,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
drift := Drift{IntervalWindow: types.IntervalWindow{Window: 3}}
drift.CalculateAndUpdate(tt.kLines)
assert.Equal(t, drift.Length(), tt.all)
for _, v := range drift.Values {
assert.LessOrEqual(t, v, 1.0)
}
})
}
}