import importlib.util from pathlib import Path spec = importlib.util.spec_from_file_location("sell", Path(__file__).resolve().parent.parent / "tools" / "sell.py") sell = importlib.util.module_from_spec(spec) spec.loader.exec_module(sell) TRADES = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50] # evenly spaced: median 25, 80th pct 40 def test_quantile_median_and_80th(): assert sell.quantile(TRADES, 0.5) == 25 assert sell.quantile(TRADES, 0.8) == 40 assert sell.quantile([], 0.5) == 0.0 def test_tranche_split_caps_aggressive_at_quantile_not_full_stock(): aggr, patient = sell.tranche_split(60, TRADES, tight=False) assert aggr == 25 and patient == 35 # median cap def test_tranche_split_tight_uses_higher_quantile(): aggr, patient = sell.tranche_split(60, TRADES, tight=True) assert aggr == 40 and patient == 20 # 80th pct cap, bigger aggressive tranche than non-tight def test_tranche_split_no_split_when_stock_below_quantile(): aggr, patient = sell.tranche_split(11, TRADES, tight=False) assert aggr == 11 and patient == 0 # whole stock fits under the median, nothing held back def test_tranche_split_falls_back_to_full_qty_with_no_history(): aggr, patient = sell.tranche_split(8, [], tight=False) assert aggr == 8 and patient == 0