99 lines
3.6 KiB
Python
99 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Spezifikation des Gegnerprofils - geschrieben VOR dem Code.
|
|
|
|
Der Client liefert Gegnerstatistiken je Nutzerkennung, und die Sitzliste führt
|
|
Sitz, Name und Kennung zusammen. Daraus entsteht ein Profil je Sitz.
|
|
|
|
Geprüft wird: Werte werden auf 0..1 normiert, fehlende Felder fliegen raus,
|
|
spätere Angaben schlagen frühere, fremde Kennungen tauchen nicht auf.
|
|
|
|
python3 tests/profil_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)
|
|
for _u in ("lesen",):
|
|
_q = os.path.join(_w, _u)
|
|
if os.path.isdir(_q):
|
|
sys.path.append(_q)
|
|
|
|
import profil
|
|
|
|
|
|
def esc(text):
|
|
"""Wie im Client-Log: innere Anführungszeichen sind maskiert."""
|
|
return text.replace('"', '\\"')
|
|
|
|
|
|
SITZE = esc('"seatResponseDataList":['
|
|
'{"seatId":2,"userName":"SneS77","userId":1662615,"userChips":9.8},'
|
|
'{"seatId":4,"userName":"Chicago111","userId":1701711,"userChips":10.6},'
|
|
'{"seatId":5,"userName":"mmintel","userId":1671088,"userChips":9.0}]')
|
|
|
|
KOMPLETT = esc('"api":"hud_stats","data":{"msg":{'
|
|
'"1662615":{"1":{"fold":73,"fta":65,"vpip":29,"pfr":20,"threeBet":9}},'
|
|
'"1701711":{"1":{"fold":76,"fta":62,"vpip":26,"pfr":15}},'
|
|
'"999999":{"1":{"fold":50,"fta":40,"vpip":11,"pfr":3}}}}')
|
|
|
|
OHNE_FTA = esc('"api":"hud_stats","data":{"msg":{"1701711":{"1":{"fold":76,"vpip":26,"pfr":15}}}}')
|
|
|
|
KAPUTT = esc('"api":"hud_stats","data":{"msg":{"1701711":{"1":{"mkdir":1,"vpip":120,"pfr":-5}}}}')
|
|
|
|
|
|
class Werte(unittest.TestCase):
|
|
def test_prozent_wird_zu_anteil(self):
|
|
s = profil.statistiken(SITZE + KOMPLETT)
|
|
self.assertAlmostEqual(s["1662615"]["vpip"], 0.29, places=4)
|
|
self.assertAlmostEqual(s["1662615"]["pfr"], 0.20, places=4)
|
|
|
|
def test_foldtobet_aus_dem_feld_fuer_druck(self):
|
|
s = profil.statistiken(SITZE + KOMPLETT)
|
|
self.assertAlmostEqual(s["1662615"]["foldToBet"], 0.65, places=4)
|
|
|
|
def test_ohne_druck_feld_zaehlt_das_gesamte_folden(self):
|
|
s = profil.statistiken(SITZE + OHNE_FTA)
|
|
self.assertAlmostEqual(s["1701711"]["foldToBet"], 0.76, places=4)
|
|
|
|
def test_werte_bleiben_zwischen_null_und_eins(self):
|
|
s = profil.statistiken(KAPUTT)
|
|
self.assertLessEqual(s["1701711"]["vpip"], 1.0)
|
|
self.assertGreaterEqual(s["1701711"]["pfr"], 0.0)
|
|
|
|
def test_unbekannte_felder_stoeren_nicht(self):
|
|
s = profil.statistiken(KAPUTT)
|
|
self.assertIn("vpip", s["1701711"])
|
|
|
|
def test_leerer_text_ergibt_leere_abbildung(self):
|
|
self.assertEqual(profil.statistiken(""), {})
|
|
|
|
|
|
class Sitze(unittest.TestCase):
|
|
def test_profil_haengt_am_sitz(self):
|
|
p = profil.profile_je_sitz(SITZE + KOMPLETT)
|
|
self.assertEqual(sorted(p), [2, 4])
|
|
self.assertAlmostEqual(p[2]["vpip"], 0.29, places=4)
|
|
|
|
def test_sitz_ohne_statistik_fehlt(self):
|
|
p = profil.profile_je_sitz(SITZE + OHNE_FTA)
|
|
self.assertNotIn(2, p)
|
|
self.assertIn(4, p)
|
|
|
|
def test_ohne_sitzliste_leer(self):
|
|
self.assertEqual(profil.profile_je_sitz(KOMPLETT), {})
|
|
|
|
|
|
class Reihenfolge(unittest.TestCase):
|
|
def test_spaetere_angabe_schlaegt_fruehere(self):
|
|
alt = esc('"api":"hud_stats","data":{"msg":{"1701711":{"1":{"vpip":10,"pfr":5}}}}')
|
|
neu = esc('"api":"hud_stats","data":{"msg":{"1701711":{"1":{"vpip":40,"pfr":30}}}}')
|
|
s = profil.statistiken(alt + " ... " + neu)
|
|
self.assertAlmostEqual(s["1701711"]["vpip"], 0.40, places=4)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main(verbosity=2)
|