Merge pull request #54 from aguzererler/test-macro-regime-fmt-pct-18208719821293052000
🧪 Add tests for `_fmt_pct` in macro regime
This commit is contained in:
commit
2ec8a17216
|
|
@ -23,6 +23,28 @@ def _trending_series(start: float, end: float, n: int = 100) -> pd.Series:
|
||||||
return _make_series(list(np.linspace(start, end, n)))
|
return _make_series(list(np.linspace(start, end, n)))
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Helpers tests
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class TestFmtPct:
|
||||||
|
def setup_method(self):
|
||||||
|
from tradingagents.dataflows.macro_regime import _fmt_pct
|
||||||
|
self.fn = _fmt_pct
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("val", "expected"),
|
||||||
|
[
|
||||||
|
(None, "N/A"),
|
||||||
|
(1.234, "+1.2%"),
|
||||||
|
(-1.234, "-1.2%"),
|
||||||
|
(0.0, "+0.0%"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_fmt_pct(self, val, expected):
|
||||||
|
assert self.fn(val) == expected
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Individual signal tests
|
# Individual signal tests
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -71,8 +71,7 @@ def _pct_change_n(series: pd.Series, n: int) -> Optional[float]:
|
||||||
def _fmt_pct(val: Optional[float]) -> str:
|
def _fmt_pct(val: Optional[float]) -> str:
|
||||||
if val is None:
|
if val is None:
|
||||||
return "N/A"
|
return "N/A"
|
||||||
sign = "+" if val >= 0 else ""
|
return f"{val:+.1f}%"
|
||||||
return f"{sign}{val:.2f}%"
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue