Skip to content

Commit

Permalink
indicator: fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Jul 26, 2022
1 parent 16c62ea commit 82673e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 7 additions & 2 deletions pkg/indicator/sma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

/*
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion pkg/indicator/stoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 82673e5

Please sign in to comment.