53 lines
2.6 KiB
Python
53 lines
2.6 KiB
Python
"""Spec of the query helpers (python3 -m unittest score/test_abfrage.py)."""
|
|
import os, sys, tempfile, unittest
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
import abfrage as A
|
|
from test_messung import REF
|
|
|
|
|
|
class Abfrage(unittest.TestCase):
|
|
def test_hand_names_are_canonical_lower_card_first(self):
|
|
self.assertEqual(A.canon("AsKd"), "KdAs")
|
|
self.assertEqual(A.canon("KdAs"), "KdAs")
|
|
self.assertEqual(A.canon("7c7d"), "7c7d")
|
|
self.assertEqual(A.canon("7d7c"), "7c7d")
|
|
|
|
def test_hole_cards_are_replaced_in_the_request(self):
|
|
q = A.with_hole({"heroCards": [], "x": 1}, "AsKd")
|
|
self.assertEqual([c["rank"] for c in q["heroCards"]], ["ACE", "KING"])
|
|
self.assertEqual([c["suit"] for c in q["heroCards"]], ["SPADES", "DIAMONDS"])
|
|
self.assertEqual(q["x"], 1)
|
|
|
|
def test_knoten_mischung_maps_onto_the_reference_menu(self):
|
|
kn = {"menue": [[1, 0.0], [2, 1.0], [2, 1.5]], "haende": [["AsKs", [0.5, 0.25, 0.25]]], "reichweite": [["AsKs", 0.3]]}
|
|
prof, d = A.profile_from_knoten(REF, kn) # 1.0 bb = 100 chips = 0.5 pot (index 1); 1.5 bb = 150 chips = 0.75 pot
|
|
p = prof["KsAs"]
|
|
self.assertAlmostEqual(p[0], 0.5)
|
|
self.assertAlmostEqual(p[1], 0.25 + 0.25 * 0.375 / 0.875)
|
|
self.assertAlmostEqual(p[2], 0.25 * (1 - 0.375 / 0.875))
|
|
self.assertAlmostEqual(sum(p), 1.0)
|
|
self.assertAlmostEqual(d, (0.0 + 0.25) / 2)
|
|
|
|
def test_old_base_menu_entries_with_action_names(self):
|
|
kn = {"menue": [["CHECK", 0, 0], ["RAISE", 1.5, 0]], "haende": [["AsKs", [0.4, 0.6]]], "reichweite": [["AsKs", 1.0]]}
|
|
prof, d = A.profile_from_knoten(REF, kn)
|
|
self.assertAlmostEqual(prof["KsAs"][0], 0.4)
|
|
self.assertAlmostEqual(prof["KsAs"][1], 0.6 * 0.375 / 0.875)
|
|
self.assertAlmostEqual(d, 0.25)
|
|
|
|
def test_missing_hands_play_the_reference_mixture_and_the_mass_is_reported(self):
|
|
prof, miss = A.complete(REF, {"KsAs": [1.0, 0, 0, 0]})
|
|
self.assertEqual(prof["2d7c"], REF["hands"][1]["sigma"])
|
|
self.assertAlmostEqual(miss, 0.75)
|
|
|
|
def test_switch_line_with_arm_b(self):
|
|
with tempfile.NamedTemporaryFile("w", suffix=".txt", delete=False) as f:
|
|
f.write("MOTOR_A=1\nMOTOR_SUCHE_X=1 # service: dropped\nMOTOR_B=0\nAB_SPOT=MOTOR_B\nAB_SPOT_B=MOTOR_B=1;MOTOR_C=2\nOTHER=3\n")
|
|
self.assertEqual(A.read_switches(f.name, "A"), {"MOTOR_A": "1", "MOTOR_B": "0"})
|
|
self.assertEqual(A.read_switches(f.name, "B"), {"MOTOR_A": "1", "MOTOR_B": "1", "MOTOR_C": "2"})
|
|
os.unlink(f.name)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|