mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
add kline window tail test
This commit is contained in:
parent
163036c745
commit
86769d4535
|
@ -320,9 +320,14 @@ func (k KLineWindow) Take(size int) KLineWindow {
|
|||
|
||||
func (k KLineWindow) Tail(size int) KLineWindow {
|
||||
if len(k) <= size {
|
||||
return k[:]
|
||||
win := make(KLineWindow, len(k))
|
||||
copy(win, k)
|
||||
return win
|
||||
}
|
||||
return k[len(k)-size:]
|
||||
|
||||
win := make(KLineWindow, size)
|
||||
copy(win, k[len(k)-size:])
|
||||
return win
|
||||
}
|
||||
|
||||
func (k *KLineWindow) Truncate(size int) {
|
||||
|
|
22
bbgo/types/kline_test.go
Normal file
22
bbgo/types/kline_test.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package types
|
||||
|
||||
import ("testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestKLineWindow_Tail(t *testing.T) {
|
||||
var win = KLineWindow{
|
||||
{ Open: "11600.0", Close: "11600.0", High: "11600.0", Low: "11600.0"},
|
||||
{ Open: "11600.0", Close: "11600.0", High: "11600.0", Low: "11600.0"},
|
||||
}
|
||||
|
||||
var win2 = win.Tail(1)
|
||||
assert.Len(t, win2, 1)
|
||||
|
||||
var win3 = win.Tail(2)
|
||||
assert.Len(t, win3, 2)
|
||||
|
||||
var win4 = win.Tail(3)
|
||||
assert.Len(t, win4, 2)
|
||||
}
|
Loading…
Reference in New Issue
Block a user