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) } }) } }