bbgo_origin/pkg/bbgo/order_processor_test.go

57 lines
1.2 KiB
Go
Raw Normal View History

2020-11-09 06:56:54 +00:00
package bbgo
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/c9s/bbgo/pkg/fixedpoint"
2020-11-09 06:56:54 +00:00
)
func TestAdjustQuantityByMinAmount(t *testing.T) {
type args struct {
quantity, price, minAmount fixedpoint.Value
2020-11-09 06:56:54 +00:00
}
type testcase struct {
name string
args args
wanted string
2020-11-09 06:56:54 +00:00
}
tests := []testcase{
{
name: "amount too small",
args: args{
fixedpoint.MustNewFromString("0.1"),
fixedpoint.MustNewFromString("10.0"),
fixedpoint.MustNewFromString("10.0"),
},
wanted: "1.0",
2020-11-09 06:56:54 +00:00
},
{
name: "amount equals to min amount",
args: args{
fixedpoint.MustNewFromString("1.0"),
fixedpoint.MustNewFromString("10.0"),
fixedpoint.MustNewFromString("10.0"),
},
wanted: "1.0",
2020-11-09 06:56:54 +00:00
},
{
name: "amount is greater than min amount",
args: args{
fixedpoint.MustNewFromString("2.0"),
fixedpoint.MustNewFromString("10.0"),
fixedpoint.MustNewFromString("10.0"),
},
wanted: "2.0",
2020-11-09 06:56:54 +00:00
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
q := AdjustFloatQuantityByMinAmount(test.args.quantity, test.args.price, test.args.minAmount)
assert.Equal(t, test.wanted, q.String())
2020-11-09 06:56:54 +00:00
})
}
}