types: add recalculate test

This commit is contained in:
c9s 2022-09-08 23:15:49 +08:00
parent 3aebb58091
commit 7823489553
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -43,3 +43,17 @@ func TestTradeStats_consecutiveCounterAndAmount(t *testing.T) {
assert.Equal(t, "-200", stats.MaximumConsecutiveLoss.String()) assert.Equal(t, "-200", stats.MaximumConsecutiveLoss.String())
assert.Equal(t, 2, stats.MaximumConsecutiveLosses) assert.Equal(t, 2, stats.MaximumConsecutiveLosses)
} }
func TestTradeStats_Recalculate(t *testing.T) {
stats := NewTradeStats("BTCUSDT")
stats.add(&Profit{OrderID: 1, Profit: number(20.0)})
stats.add(&Profit{OrderID: 1, Profit: number(30.0)})
stats.add(&Profit{OrderID: 2, Profit: number(50.0)})
stats.add(&Profit{OrderID: 2, Profit: number(50.0)})
stats.add(&Profit{OrderID: 3, Profit: number(-50.0)})
stats.add(&Profit{OrderID: 3, Profit: number(-50.0)})
assert.Equal(t, "50", stats.TotalNetProfit.String())
stats.Recalculate()
assert.Equal(t, "50", stats.TotalNetProfit.String())
}