137 lines
5.8 KiB
Python
137 lines
5.8 KiB
Python
"""Tische je Stufe (Owner 26.11.: "ich kann nicht live die Tische anpassen, nur alle NL2 weg druecken"):
|
|
der Plan traegt je Stufe eine Hoechstzahl; eine volle Stufe oeffnet nichts mehr, eine gesenkte baut ihre
|
|
schwaechsten Tische ab. Ohne Zahl bleibt alles wie bisher."""
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
_W = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
for _u in ("betrieb", "lesen", "hand", "client", "sicht", "mcp"):
|
|
_p = os.path.join(_W, _u)
|
|
if _p not in sys.path:
|
|
sys.path.insert(0, _p)
|
|
|
|
import spielplan # noqa: E402
|
|
|
|
|
|
def plan(**extra):
|
|
return spielplan.aus_dict({"modus": "cash", "tische": 16, "stufen": {"cash": [0.02, 0.05]}, **extra})
|
|
|
|
|
|
class StufenTische(unittest.TestCase):
|
|
def test_ohne_zahl_nichts_begrenzt(self):
|
|
p = plan()
|
|
self.assertEqual(spielplan.stufen_tische_von(p), {})
|
|
self.assertEqual(spielplan.stufen_voll(p, {0.02: 40}), set())
|
|
self.assertNotIn("stufen_tische", spielplan.als_dict(p))
|
|
|
|
def test_hin_und_zurueck(self):
|
|
p = plan(stufen_tische={"cash": {"0.02": 10, "0.05": 4}})
|
|
self.assertEqual(spielplan.stufen_tische_von(p), {0.02: 10, 0.05: 4})
|
|
self.assertEqual(spielplan.stufen_tische_von(spielplan.aus_dict(spielplan.als_dict(p))), {0.02: 10, 0.05: 4})
|
|
|
|
def test_unsinn_faellt_weg(self):
|
|
p = plan(stufen_tische={"cash": {"x": 3, "0.02": "viele", "0.05": True, "0.1": -1, "0.25": 2}})
|
|
self.assertEqual(spielplan.stufen_tische_von(p), {0.25: 2})
|
|
|
|
def test_je_modus(self):
|
|
p = plan(stufen_tische={"uebung": {"0.02": 3}})
|
|
self.assertEqual(spielplan.stufen_tische_von(p), {})
|
|
|
|
def test_volle_stufe(self):
|
|
p = plan(stufen_tische={"cash": {"0.02": 10, "0.05": 0}})
|
|
self.assertEqual(spielplan.stufen_voll(p, {0.02: 10}), {0.02, 0.05})
|
|
self.assertEqual(spielplan.stufen_voll(p, {0.02: 9}), {0.05})
|
|
|
|
def test_abbau_die_schwaechsten_der_stufe(self):
|
|
p = plan(stufen_tische={"cash": {"0.02": 2}})
|
|
werte = {"a": 5.0, "b": -3.0, "c": 1.0, "d": -9.0}
|
|
bb = {"a": 0.02, "b": 0.02, "c": 0.02, "d": 0.05}
|
|
self.assertEqual(spielplan.abzubauen_je_stufe(p, werte, bb), ["b"])
|
|
self.assertEqual(spielplan.abzubauen_je_stufe(p, werte, bb, gehend={"b"}), [])
|
|
|
|
def test_abbau_ohne_zahl_leer(self):
|
|
self.assertEqual(spielplan.abzubauen_je_stufe(plan(), {"a": 1.0}, {"a": 0.02}), [])
|
|
|
|
|
|
class ServerBehaeltDieZahlen(unittest.TestCase):
|
|
def test_spielplan_ohne_feld_behaelt_stufen_tische(self):
|
|
import steuern
|
|
with tempfile.TemporaryDirectory() as d:
|
|
pfad = os.path.join(d, "spielplan.json")
|
|
alt = steuern.SPIELPLAN
|
|
steuern.SPIELPLAN = pfad
|
|
try:
|
|
spielplan.schreiben(pfad, plan(stufen_tische={"cash": {"0.02": 6}}))
|
|
steuern.spielplan_setzen({"modus": "cash", "tische": 12, "stufen": {"cash": [0.02]}})
|
|
self.assertEqual(spielplan.stufen_tische_von(spielplan.lesen(pfad)), {0.02: 6})
|
|
steuern.spielplan_setzen({"modus": "cash", "tische": 12, "stufen_tische": {"cash": {}}})
|
|
self.assertEqual(spielplan.stufen_tische_von(spielplan.lesen(pfad)), {})
|
|
finally:
|
|
steuern.SPIELPLAN = alt
|
|
|
|
|
|
|
|
|
|
class AbgewaehlteStufe(unittest.TestCase):
|
|
"""26.11. 21:36 live: nur Freeroll gewaehlt, nach Neustart adoptierte der Laeufer drei offene NL2-Tische
|
|
und kaufte sich ein. Eine nicht gewaehlte Stufe: kein Sitz, wer sitzt, steht auf."""
|
|
|
|
def test_nur_freeroll_sperrt_jede_cash_stufe(self):
|
|
p = spielplan.aus_dict({"modus": "cash", "tische": 16, "stufen": {"cash": [-1.0]}})
|
|
self.assertTrue(spielplan.stufe_abgewaehlt(p, 0.02))
|
|
|
|
def test_gewaehlte_stufe_frei(self):
|
|
self.assertFalse(spielplan.stufe_abgewaehlt(plan(), 0.02))
|
|
self.assertTrue(spielplan.stufe_abgewaehlt(plan(), 0.1))
|
|
|
|
def test_automatisch_und_unbekannt_nie(self):
|
|
p = spielplan.aus_dict({"modus": "cash", "tische": 16})
|
|
self.assertFalse(spielplan.stufe_abgewaehlt(p, 0.1))
|
|
self.assertFalse(spielplan.stufe_abgewaehlt(plan(), None))
|
|
|
|
def test_abbau_nimmt_abgewaehlte_zuerst(self):
|
|
p = spielplan.aus_dict({"modus": "cash", "tische": 16, "stufen": {"cash": [-1.0]}})
|
|
werte = {"a": 5.0, "b": 1.0, "t": 0.0}
|
|
raus = spielplan.abzubauen_je_stufe(p, werte, {"a": 0.02, "b": 0.02, "t": None})
|
|
self.assertEqual(sorted(raus), ["a", "b"])
|
|
|
|
|
|
|
|
class StufeGesperrt(unittest.TestCase):
|
|
"""27.11. 00:06 live: Zahl NL2 auf 0 - er stand auf und kaufte sich am selben Tisch sofort wieder ein."""
|
|
|
|
def ob(self, lagen, abgang=()):
|
|
import types
|
|
import runner
|
|
o = types.SimpleNamespace(lagen=lagen, abgang={r: (0, {}) for r in abgang}, zahl_abbau={})
|
|
o._tische_je_stufe = runner.Sitzer._tische_je_stufe.__get__(o)
|
|
return lambda raum, sitzt: runner.Sitzer._stufe_gesperrt(o, raum, lagen.get(raum), self.p, sitzt)
|
|
|
|
def setUp(self):
|
|
import types
|
|
self.L = lambda sitz, bb=0.02: types.SimpleNamespace(held_sitz=sitz, bb=bb, turnier=False, format=None)
|
|
self.p = plan(stufen_tische={"cash": {"0.02": 0}})
|
|
|
|
def test_null_heisst_kein_neuer_sitz(self):
|
|
frage = self.ob({"A": self.L(None)})
|
|
self.assertIn("Tischzahl der Stufe", frage("A", False))
|
|
|
|
def test_unter_der_zahl_frei(self):
|
|
self.p = plan(stufen_tische={"cash": {"0.02": 2}})
|
|
frage = self.ob({"A": self.L(None), "B": self.L(3)})
|
|
self.assertEqual(frage("A", False), "")
|
|
|
|
def test_im_abgang_kein_neuer_sitz(self):
|
|
self.p = plan()
|
|
frage = self.ob({"A": self.L(None)}, abgang=["A"])
|
|
self.assertIn("Abgang", frage("A", False))
|
|
|
|
def test_andere_stufe_unberuehrt(self):
|
|
frage = self.ob({"A": self.L(None, bb=0.05)})
|
|
self.assertEqual(frage("A", False), "")
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|