From 82673e501bfa5faaa88312bc1de56063b4bdf5f3 Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 26 Jul 2022 18:07:28 +0800 Subject: [PATCH] indicator: fix test cases --- pkg/indicator/sma_test.go | 9 +++++++-- pkg/indicator/stoch_test.go | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/indicator/sma_test.go b/pkg/indicator/sma_test.go index fb40716cc..a6ecc1324 100644 --- a/pkg/indicator/sma_test.go +++ b/pkg/indicator/sma_test.go @@ -4,9 +4,10 @@ import ( "encoding/json" "testing" + "github.com/stretchr/testify/assert" + "github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/types" - "github.com/stretchr/testify/assert" ) /* @@ -52,7 +53,11 @@ func Test_SMA(t *testing.T) { sma := SMA{ 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.next, sma.Index(1), Delta) sma.Update(tt.update) diff --git a/pkg/indicator/stoch_test.go b/pkg/indicator/stoch_test.go index 56839dadc..eb3d0206c 100644 --- a/pkg/indicator/stoch_test.go +++ b/pkg/indicator/stoch_test.go @@ -56,7 +56,10 @@ func TestSTOCH_update(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { kd := STOCH{IntervalWindow: types.IntervalWindow{Window: tt.window}} - kd.CalculateAndUpdate(tt.kLines) + + for _, k := range tt.kLines { + kd.PushK(k) + } got_k := kd.LastK() diff_k := math.Trunc((got_k-tt.want_k)*100) / 100