2020-11-09 06:56:54 +00:00
|
|
|
package bbgo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-02-09 10:23:35 +00:00
|
|
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
2022-02-15 05:55:19 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-11-09 06:56:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAdjustQuantityByMinAmount(t *testing.T) {
|
|
|
|
type args struct {
|
2022-02-09 10:23:35 +00:00
|
|
|
quantity, price, minAmount fixedpoint.Value
|
2020-11-09 06:56:54 +00:00
|
|
|
}
|
|
|
|
type testcase struct {
|
|
|
|
name string
|
|
|
|
args args
|
2022-02-09 10:23:35 +00:00
|
|
|
wanted string
|
2020-11-09 06:56:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tests := []testcase{
|
|
|
|
{
|
2022-02-15 05:55:19 +00:00
|
|
|
name: "amount too small",
|
|
|
|
args: args{
|
2022-02-09 10:23:35 +00:00
|
|
|
fixedpoint.MustNewFromString("0.1"),
|
|
|
|
fixedpoint.MustNewFromString("10.0"),
|
|
|
|
fixedpoint.MustNewFromString("10.0"),
|
|
|
|
},
|
|
|
|
wanted: "1.0",
|
2020-11-09 06:56:54 +00:00
|
|
|
},
|
|
|
|
{
|
2022-02-15 05:55:19 +00:00
|
|
|
name: "amount equals to min amount",
|
|
|
|
args: args{
|
2022-02-09 10:23:35 +00:00
|
|
|
fixedpoint.MustNewFromString("1.0"),
|
|
|
|
fixedpoint.MustNewFromString("10.0"),
|
|
|
|
fixedpoint.MustNewFromString("10.0"),
|
|
|
|
},
|
|
|
|
wanted: "1.0",
|
2020-11-09 06:56:54 +00:00
|
|
|
},
|
|
|
|
{
|
2022-02-15 05:55:19 +00:00
|
|
|
name: "amount is greater than min amount",
|
|
|
|
args: args{
|
2022-02-09 10:23:35 +00:00
|
|
|
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) {
|
2021-05-14 06:52:19 +00:00
|
|
|
q := AdjustFloatQuantityByMinAmount(test.args.quantity, test.args.price, test.args.minAmount)
|
2022-02-09 11:37:49 +00:00
|
|
|
assert.Equal(t, fixedpoint.MustNewFromString(test.wanted), q)
|
2020-11-09 06:56:54 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|