from lib.trade.trade_result_lib import normalize_result_with_pnl, normalize_display_result, is_winning_pnl


def test_stop_loss_with_profit_becomes_trailing_tp():
    assert normalize_result_with_pnl("止损", 4.33) == "移动止盈"


def test_manual_close_unchanged_even_with_profit():
    assert normalize_result_with_pnl("手动平仓", 10) == "手动平仓"


def test_stop_loss_with_loss_unchanged():
    assert normalize_result_with_pnl("止损", -2.5) == "止损"


def test_take_profit_unchanged():
    assert normalize_result_with_pnl("止盈", 5) == "止盈"


def test_external_close_becomes_manual_close():
    assert normalize_display_result("外部平仓") == "手动平仓"
    assert normalize_result_with_pnl("外部平仓", 2.5) == "手动平仓"
    assert normalize_result_with_pnl("外部平仓(自动同步)", -1) == "手动平仓"


def test_winning_pnl_positive_only():
    assert is_winning_pnl(2.96) is True
    assert is_winning_pnl(0) is False
    assert is_winning_pnl(-1.05) is False
    assert is_winning_pnl(None) is False
