scripts: pl_calc, vision_schema, calendar_parse + tests (67 passing)
This commit is contained in:
89
tests/test_pl_calc.py
Normal file
89
tests/test_pl_calc.py
Normal file
@@ -0,0 +1,89 @@
|
||||
"""Tests for scripts/pl_calc.py."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from scripts.pl_calc import ( # noqa: E402
|
||||
PL_MARIUS_TABLE,
|
||||
PL_THEORETICAL_TABLE,
|
||||
pl_marius,
|
||||
pl_theoretical,
|
||||
)
|
||||
|
||||
|
||||
class TestPlMarius:
|
||||
def test_sl(self) -> None:
|
||||
assert pl_marius("SL", be_moved=True) == -1.0
|
||||
assert pl_marius("SL", be_moved=False) == -1.0
|
||||
|
||||
def test_tp0_sl_be_moved(self) -> None:
|
||||
assert pl_marius("TP0->SL", be_moved=True) == pytest.approx(0.20)
|
||||
|
||||
def test_tp0_sl_no_be(self) -> None:
|
||||
assert pl_marius("TP0->SL", be_moved=False) == pytest.approx(-0.30)
|
||||
|
||||
def test_tp0_tp1(self) -> None:
|
||||
assert pl_marius("TP0->TP1", be_moved=True) == pytest.approx(0.50)
|
||||
assert pl_marius("TP0->TP1", be_moved=False) == pytest.approx(0.50)
|
||||
|
||||
def test_tp0_tp2_closes_at_tp1(self) -> None:
|
||||
assert pl_marius("TP0->TP2", be_moved=True) == pytest.approx(0.50)
|
||||
assert pl_marius("TP0->TP2", be_moved=False) == pytest.approx(0.50)
|
||||
|
||||
def test_tp0_pending_returns_none(self) -> None:
|
||||
assert pl_marius("TP0->pending", be_moved=True) is None
|
||||
assert pl_marius("TP0->pending", be_moved=False) is None
|
||||
|
||||
def test_pending_returns_none(self) -> None:
|
||||
assert pl_marius("pending", be_moved=True) is None
|
||||
assert pl_marius("pending", be_moved=False) is None
|
||||
|
||||
def test_unicode_arrow_accepted(self) -> None:
|
||||
assert pl_marius("TP0→TP1", be_moved=True) == pytest.approx(0.50)
|
||||
assert pl_marius("TP0→SL", be_moved=False) == pytest.approx(-0.30)
|
||||
|
||||
def test_invalid_outcome_path(self) -> None:
|
||||
with pytest.raises(ValueError):
|
||||
pl_marius("nonsense", be_moved=True)
|
||||
with pytest.raises(ValueError):
|
||||
pl_marius("TP3", be_moved=False)
|
||||
with pytest.raises(ValueError):
|
||||
pl_marius("", be_moved=True)
|
||||
|
||||
|
||||
class TestPlTheoretical:
|
||||
def test_sl_first(self) -> None:
|
||||
assert pl_theoretical("SL_first") == -1.0
|
||||
|
||||
def test_tp0(self) -> None:
|
||||
assert pl_theoretical("TP0") == pytest.approx(0.133)
|
||||
|
||||
def test_tp1(self) -> None:
|
||||
assert pl_theoretical("TP1") == pytest.approx(0.333)
|
||||
|
||||
def test_tp2(self) -> None:
|
||||
assert pl_theoretical("TP2") == pytest.approx(0.667)
|
||||
|
||||
def test_invalid_max_reached(self) -> None:
|
||||
with pytest.raises(ValueError):
|
||||
pl_theoretical("TP3")
|
||||
with pytest.raises(ValueError):
|
||||
pl_theoretical("sl_first") # case-sensitive
|
||||
with pytest.raises(ValueError):
|
||||
pl_theoretical("")
|
||||
|
||||
|
||||
class TestTables:
|
||||
def test_marius_table_exported(self) -> None:
|
||||
assert ("SL", True) in PL_MARIUS_TABLE
|
||||
assert PL_MARIUS_TABLE[("TP0->TP1", True)] == pytest.approx(0.50)
|
||||
|
||||
def test_theoretical_table_exported(self) -> None:
|
||||
assert PL_THEORETICAL_TABLE["TP2"] == pytest.approx(0.667)
|
||||
assert PL_THEORETICAL_TABLE["SL_first"] == -1.0
|
||||
Reference in New Issue
Block a user