b733e551a0
Add scripts/normalize_ambiguous_unicode.py; fix corrupted patch_instance_theme_templates.py. Preserves curly quotes in string literals; removes Git homoglyph warnings on .env.example. Co-authored-by: Cursor <cursoragent@cursor.com>
34 lines
1012 B
Python
34 lines
1012 B
Python
"""instance_embed_context_lib 顶栏统计."""
|
|
from __future__ import annotations
|
|
|
|
import unittest
|
|
|
|
from lib.instance.instance_embed_context_lib import (
|
|
profit_loss_ratio_from_averages,
|
|
profit_loss_ratio_from_trades,
|
|
total_funds_usdt,
|
|
)
|
|
|
|
|
|
class TestHeaderStatsLib(unittest.TestCase):
|
|
def test_profit_loss_ratio_from_averages(self):
|
|
self.assertEqual(profit_loss_ratio_from_averages(9.0, -3.0), 3.0)
|
|
self.assertIsNone(profit_loss_ratio_from_averages(9.0, 0))
|
|
|
|
def test_profit_loss_ratio_from_trades(self):
|
|
trades = [
|
|
{"effective_pnl_amount": 10},
|
|
{"effective_pnl_amount": 8},
|
|
{"effective_pnl_amount": -4},
|
|
{"effective_pnl_amount": -2},
|
|
]
|
|
self.assertEqual(profit_loss_ratio_from_trades(trades), 3.0)
|
|
|
|
def test_total_funds_usdt(self):
|
|
self.assertEqual(total_funds_usdt(100.5, 59.27), 159.77)
|
|
self.assertIsNone(total_funds_usdt(None, 10))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|