123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- package sentio
- import (
- "reflect"
- "slices"
- "testing"
- )
- func TestCompareStrategyOrders(t *testing.T) {
- tests := []struct {
- name string
- orders []StrategyOrder
- want []StrategyOrder
- }{
- {
- name: "Sell first",
- orders: []StrategyOrder{
- {
- Action: OrderBuy,
- Ratio: .3,
- },
- {
- Action: OrderSell,
- Ratio: 1,
- },
- },
- want: []StrategyOrder{
- {
- Action: OrderSell,
- Ratio: 1,
- },
- {
- Action: OrderBuy,
- Ratio: .3,
- },
- },
- },
- {
- name: "Buy largest first",
- orders: []StrategyOrder{
- {
- Action: OrderBuy,
- Ratio: .3,
- },
- {
- Action: OrderBuy,
- Ratio: .6,
- },
- },
- want: []StrategyOrder{
- {
- Action: OrderBuy,
- Ratio: .6,
- },
- {
- Action: OrderBuy,
- Ratio: .3,
- },
- },
- },
- {
- name: "Sell largest first",
- orders: []StrategyOrder{
- {
- Action: OrderSell,
- Ratio: .3,
- },
- {
- Action: OrderSell,
- Ratio: .6,
- },
- },
- want: []StrategyOrder{
- {
- Action: OrderSell,
- Ratio: .6,
- },
- {
- Action: OrderSell,
- Ratio: .3,
- },
- },
- },
- {
- name: "Sell largest first then buy",
- orders: []StrategyOrder{
- {
- Action: OrderSell,
- Ratio: .3,
- },
- {
- Action: OrderBuy,
- Ratio: .6,
- },
- {
- Action: OrderSell,
- Ratio: .6,
- },
- },
- want: []StrategyOrder{
- {
- Action: OrderSell,
- Ratio: .6,
- },
- {
- Action: OrderSell,
- Ratio: .3,
- },
- {
- Action: OrderBuy,
- Ratio: .6,
- },
- },
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- slices.SortFunc(tt.orders, CompareStrategyOrders)
- if ok := reflect.DeepEqual(tt.want, tt.orders); !ok {
- t.Errorf("SortFunc = %v, want %v", tt.orders, tt.want)
- }
- })
- }
- }
|