mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-06 23:16:53 +00:00
backtester: Improve test coverage (#717)
* Improve config test coverage * Improve common test coverage * Improve data test coverage * Silence false positives on table tests
This commit is contained in:
@@ -2,17 +2,26 @@ package data
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
|
||||
)
|
||||
|
||||
const testExchange = "binance"
|
||||
|
||||
type fakeDataHandler struct {
|
||||
time int
|
||||
}
|
||||
|
||||
func TestBaseDataFunctions(t *testing.T) {
|
||||
t.Parallel()
|
||||
var d Base
|
||||
d.Latest()
|
||||
latest := d.Latest()
|
||||
if latest != nil {
|
||||
t.Error("expected nil")
|
||||
}
|
||||
d.Next()
|
||||
o := d.Offset()
|
||||
if o != 0 {
|
||||
@@ -27,8 +36,14 @@ func TestBaseDataFunctions(t *testing.T) {
|
||||
if o != 0 {
|
||||
t.Error("expected 0")
|
||||
}
|
||||
d.List()
|
||||
d.History()
|
||||
list := d.List()
|
||||
if list != nil {
|
||||
t.Error("expected nil")
|
||||
}
|
||||
history := d.History()
|
||||
if history != nil {
|
||||
t.Error("expected nil")
|
||||
}
|
||||
d.SetStream(nil)
|
||||
st := d.GetStream()
|
||||
if st != nil {
|
||||
@@ -48,6 +63,55 @@ func TestSetup(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStream(t *testing.T) {
|
||||
var d Base
|
||||
var f fakeDataHandler
|
||||
|
||||
// shut up coverage report
|
||||
f.GetOffset()
|
||||
f.SetOffset(1)
|
||||
f.IsEvent()
|
||||
f.Pair()
|
||||
f.GetExchange()
|
||||
f.GetInterval()
|
||||
f.GetAssetType()
|
||||
f.GetReason()
|
||||
f.AppendReason("fake")
|
||||
f.ClosePrice()
|
||||
f.HighPrice()
|
||||
f.LowPrice()
|
||||
f.OpenPrice()
|
||||
|
||||
d.AppendStream(fakeDataHandler{time: 1})
|
||||
d.AppendStream(fakeDataHandler{time: 4})
|
||||
d.AppendStream(fakeDataHandler{time: 10})
|
||||
d.AppendStream(fakeDataHandler{time: 2})
|
||||
d.AppendStream(fakeDataHandler{time: 20})
|
||||
|
||||
d.SortStream()
|
||||
|
||||
f = d.Next().(fakeDataHandler)
|
||||
if f.time != 1 {
|
||||
t.Error("expected 1")
|
||||
}
|
||||
f = d.Next().(fakeDataHandler)
|
||||
if f.time != 2 {
|
||||
t.Error("expected 2")
|
||||
}
|
||||
f = d.Next().(fakeDataHandler)
|
||||
if f.time != 4 {
|
||||
t.Error("expected 4")
|
||||
}
|
||||
f = d.Next().(fakeDataHandler)
|
||||
if f.time != 10 {
|
||||
t.Error("expected 10")
|
||||
}
|
||||
f = d.Next().(fakeDataHandler)
|
||||
if f.time != 20 {
|
||||
t.Error("expected 20")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDataForCurrency(t *testing.T) {
|
||||
t.Parallel()
|
||||
d := HandlerPerCurrency{}
|
||||
@@ -107,3 +171,58 @@ func TestReset(t *testing.T) {
|
||||
t.Error("expected nil")
|
||||
}
|
||||
}
|
||||
|
||||
// methods that satisfy the common.DataEventHandler interface
|
||||
func (t fakeDataHandler) GetOffset() int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (t fakeDataHandler) SetOffset(int64) {
|
||||
}
|
||||
|
||||
func (t fakeDataHandler) IsEvent() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (t fakeDataHandler) GetTime() time.Time {
|
||||
return time.Now().Add(time.Hour * time.Duration(t.time))
|
||||
}
|
||||
|
||||
func (t fakeDataHandler) Pair() currency.Pair {
|
||||
return currency.NewPair(currency.BTC, currency.USD)
|
||||
}
|
||||
|
||||
func (t fakeDataHandler) GetExchange() string {
|
||||
return "fake"
|
||||
}
|
||||
|
||||
func (t fakeDataHandler) GetInterval() kline.Interval {
|
||||
return kline.Interval(time.Minute)
|
||||
}
|
||||
|
||||
func (t fakeDataHandler) GetAssetType() asset.Item {
|
||||
return asset.Spot
|
||||
}
|
||||
|
||||
func (t fakeDataHandler) GetReason() string {
|
||||
return "fake"
|
||||
}
|
||||
|
||||
func (t fakeDataHandler) AppendReason(string) {
|
||||
}
|
||||
|
||||
func (t fakeDataHandler) ClosePrice() float64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (t fakeDataHandler) HighPrice() float64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (t fakeDataHandler) LowPrice() float64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (t fakeDataHandler) OpenPrice() float64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user