130 lines
6.0 KiB
Python
130 lines
6.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Spezifikation: die Sonderregel-Tafel eines Raums (lesen/tischregeln.py).
|
|
|
|
Die Tafel nennt je Raum, welche Sonderfaelle er traegt - aus ZWEI Quellen: den maschinenlesbaren
|
|
Raumdaten (`roomProperties`) UND dem Raumnamen. Beide zusammen sind der Schluessel; die Quelle
|
|
steht je Merkmal dabei ("daten", "name" oder "beide"), damit nichts geraten wirkt.
|
|
|
|
Belege sind woertlich aus der lebenden Cash-Liste gezogen (Stand 2026-11-03, `lesen/raumliste.py`,
|
|
Raumdaten der genannten Tische). Kein Log, keine Hand - reine Rechnung.
|
|
|
|
python3 tests/tischregeln_spec.py -v
|
|
"""
|
|
import os
|
|
import sys
|
|
import unittest
|
|
|
|
_w = os.path.dirname(os.path.abspath(__file__))
|
|
while _w != "/" and not os.path.isdir(os.path.join(_w, "lesen")):
|
|
_w = os.path.dirname(_w)
|
|
sys.path.append(os.path.join(_w, "lesen"))
|
|
import tischregeln
|
|
|
|
|
|
# Woertlich aus der lebenden Liste: PLO6, ANTE, MS im Namen; isEVChopAllowed, isNoLimp,
|
|
# isMustShowEnabled, ante 0.5 in den Daten (Tisch 1699237).
|
|
PLO6_ANTE_MS = {
|
|
"roomName": "14R PLO6 1-2 EV-INRIT-ANTE-MS (C) 1699237", "tableId": 1699237,
|
|
"gameVarient": "6CardPLO", "miniGameTypeId": 20, "iRitOptions": [0, 1, 2],
|
|
"isEVChopAllowed": True, "isNoLimp": True, "isKPoker": False, "isMustShowEnabled": True,
|
|
"isBombpot": False, "isDoubleBoard": False, "isStraddle": False, "isAnonymous": False,
|
|
"bombpotInducesDoubleBoard": False, "isFixedHandBombpot": False, "ante": 0.5, "runId": 0,
|
|
}
|
|
# Woertlich: PLO6 + HU im Namen, EV + INRIT in beiden Quellen (Tisch 1704430).
|
|
PLO6_HU = {
|
|
"roomName": "14R PLO6 HU 0.05-0.10 EV-INRIT (A) 1704430", "tableId": 1704430,
|
|
"gameVarient": "6CardPLO", "miniGameTypeId": 20, "iRitOptions": [0, 1, 2],
|
|
"isEVChopAllowed": True, "isNoLimp": False, "isKPoker": False, "isMustShowEnabled": False,
|
|
"isBombpot": False, "isDoubleBoard": False, "isStraddle": False, "isAnonymous": False,
|
|
"ante": 0,
|
|
}
|
|
# Woertlich: K-Poker (KP) und 7-Max (MAX) im Namen, isKPoker in den Daten (Tisch 1704584).
|
|
KP_MAX = {"roomName": "KP-NL 1 EV-INRIT-(A) 7MAX 1704584", "tableId": 1704584,
|
|
"iRitOptions": [0, 1, 2], "isKPoker": True, "isEVChopAllowed": True, "ante": 1}
|
|
# Woertlich: NOLP im Namen UND isNoLimp in den Daten (Tisch 1700853).
|
|
PLO_NOLP = {"roomName": "14R PLO 1-2 EV-INRIT-ANTE NOLP (A) 1700853", "tableId": 1700853,
|
|
"iRitOptions": [0, 1, 2], "isEVChopAllowed": True, "isNoLimp": True, "ante": 0.5}
|
|
|
|
|
|
class AusDenDaten(unittest.TestCase):
|
|
def test_felder_werden_zu_merkmalen(self):
|
|
d = tischregeln.aus_daten(PLO6_ANTE_MS)
|
|
for m in ("ev_chop", "no_limp", "must_show", "ante", "rit"):
|
|
self.assertIn(m, d)
|
|
self.assertEqual(d["ante"], 0.5)
|
|
|
|
def test_blosse_false_schalter_fehlen(self):
|
|
d = tischregeln.aus_daten({"isNoLimp": False, "isEVChopAllowed": False})
|
|
self.assertNotIn("no_limp", d)
|
|
self.assertNotIn("ev_chop", d)
|
|
|
|
def test_bombpot_und_doppelbrett_aus_daten(self):
|
|
d = tischregeln.aus_daten({"isBombpot": True, "bombpotInducesDoubleBoard": True})
|
|
self.assertIn("bomb_pot", d)
|
|
self.assertIn("doppelbrett", d)
|
|
|
|
def test_rit_nur_bei_echten_optionen(self):
|
|
self.assertIn("rit", tischregeln.aus_daten({"iRitOptions": [0, 1, 2]}))
|
|
self.assertIn("rit", tischregeln.aus_daten({"iRitOptions": "0,1,2"}))
|
|
self.assertNotIn("rit", tischregeln.aus_daten({"iRitOptions": [0]}))
|
|
self.assertNotIn("rit", tischregeln.aus_daten({"iRitOptions": []}))
|
|
|
|
|
|
class AusDemNamen(unittest.TestCase):
|
|
def test_namensteile_werden_zu_merkmalen(self):
|
|
n = tischregeln.aus_name(PLO6_ANTE_MS["roomName"])
|
|
for m in ("plo6", "ante", "mega_splash", "rit", "ev_chop"):
|
|
self.assertIn(m, n)
|
|
|
|
def test_no_limp_aus_dem_namen(self):
|
|
self.assertIn("no_limp", tischregeln.aus_name(PLO_NOLP["roomName"]))
|
|
|
|
def test_hu_und_max_aus_dem_namen(self):
|
|
self.assertIn("hu", tischregeln.aus_name(PLO6_HU["roomName"]))
|
|
self.assertIn("max", tischregeln.aus_name(KP_MAX["roomName"]))
|
|
self.assertIn("k_poker", tischregeln.aus_name(KP_MAX["roomName"]))
|
|
|
|
def test_schluesselwoerter_loesen_nicht_falsch_aus(self):
|
|
# "NL" allein darf nicht als No-Limp (NOLP) oder Mega-Splash (MS) gelten
|
|
n = tischregeln.aus_name("14R NL 0.02-0.05 EV-INRIT-(A) 1702438")
|
|
self.assertNotIn("no_limp", n)
|
|
self.assertNotIn("mega_splash", n)
|
|
self.assertIn("ev_chop", n)
|
|
self.assertIn("rit", n)
|
|
|
|
def test_standardname_ist_leer(self):
|
|
self.assertEqual(tischregeln.aus_name("Big Ben 1664572"), {})
|
|
|
|
|
|
class Tafel(unittest.TestCase):
|
|
def test_tafel_vereinigt_und_nennt_die_quelle(self):
|
|
t = tischregeln.tafel(PLO6_ANTE_MS, PLO6_ANTE_MS["roomName"])
|
|
self.assertEqual(t["rit"][1], "beide") # INRIT im Namen UND iRitOptions in den Daten
|
|
self.assertEqual(t["ev_chop"][1], "beide")
|
|
self.assertEqual(t["ante"][0], 0.5) # der Wert kommt aus den Daten
|
|
self.assertEqual(t["mega_splash"][1], "name") # MS nur im Namen
|
|
self.assertEqual(t["must_show"][1], "daten") # isMustShowEnabled nur in den Daten
|
|
# NOLP steht im Namen UND als isNoLimp in den Daten
|
|
self.assertEqual(tischregeln.tafel(PLO_NOLP, PLO_NOLP["roomName"])["no_limp"][1], "beide")
|
|
|
|
def test_tafel_ist_sortiert_und_rein(self):
|
|
rp = dict(PLO6_HU)
|
|
t1 = tischregeln.tafel(rp, rp["roomName"])
|
|
t2 = tischregeln.tafel(rp, rp["roomName"])
|
|
self.assertEqual(list(t1), sorted(t1))
|
|
self.assertEqual(t1, t2)
|
|
self.assertEqual(rp, PLO6_HU) # Eingabe bleibt unveraendert
|
|
|
|
def test_standardraum_ist_leer(self):
|
|
self.assertEqual(tischregeln.tafel({"gameType": "Ring"}, "Big Ben 1664572"), {})
|
|
|
|
def test_klartext_nennt_merkmal_und_quelle(self):
|
|
s = tischregeln.klartext_tafel(tischregeln.tafel(PLO6_ANTE_MS, PLO6_ANTE_MS["roomName"]))
|
|
self.assertIn("plo6", s)
|
|
self.assertIn("ante=0.5", s)
|
|
self.assertEqual(tischregeln.klartext_tafel({}), "Standardtisch")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main(verbosity=2)
|