934e48b9a8
Co-authored-by: Cursor <cursoragent@cursor.com>
35 lines
941 B
Python
35 lines
941 B
Python
"""全仓 / 以损定仓 风险展示文案。"""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from position_sizing_lib import ( # noqa: E402
|
|
format_risk_display_text,
|
|
risk_percent_for_storage,
|
|
)
|
|
|
|
|
|
class TestPositionSizingRiskDisplay(unittest.TestCase):
|
|
def test_full_margin_shows_amount_only(self):
|
|
self.assertEqual(
|
|
format_risk_display_text("full_margin", 1.0, 2.58, decimals=2),
|
|
"2.58U",
|
|
)
|
|
self.assertIsNone(risk_percent_for_storage("full_margin", 1.0))
|
|
|
|
def test_risk_mode_shows_percent_and_amount(self):
|
|
self.assertEqual(
|
|
format_risk_display_text("risk", 2.0, 10.5, decimals=2),
|
|
"2%≈10.5U",
|
|
)
|
|
self.assertEqual(risk_percent_for_storage("risk", 2.0), 2.0)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|