Files
pokerfreak/score/test_messung.py
T

64 lines
3.2 KiB
Python

"""Spec of the mapping and the loss (python3 -m unittest score/test_messung.py)."""
import os, sys, unittest
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import messung as M
REF = {"pot": 200, "to_call": 0, "cur_bet": 0, "max_raise_to": 1000,
"actions": [{"kind": "check"}, {"kind": "raise", "to": 100, "frac": 0.5}, {"kind": "raise", "to": 200, "frac": 1.0},
{"kind": "raise", "to": 1000, "frac": 5.0, "all_in": True}],
"hands": [{"c": "AsKs", "w": 0.25, "q": [10.0, 30.0, 20.0, 0.0], "sigma": [0.0, 1.0, 0.0, 0.0]},
{"c": "7c2d", "w": 0.75, "q": [-5.0, -9.0, -20.0, -50.0], "sigma": [1.0, 0.0, 0.0, 0.0]}]}
class Messung(unittest.TestCase):
def test_harmonic_between_two_sizes_hand_computed(self):
m = M.harmonic([0.5, 1.0], 0.75) # pA = (1-.75)*1.5 / (.5*1.75)
self.assertAlmostEqual(m[0], 0.375 / 0.875)
self.assertAlmostEqual(m[1], 1 - 0.375 / 0.875)
def test_harmonic_on_a_size_and_outside_the_grid(self):
self.assertEqual(M.harmonic([0.5, 1.0], 0.5), {0: 1.0})
self.assertEqual(M.harmonic([0.5, 1.0], 0.2), {0: 1.0})
self.assertEqual(M.harmonic([0.5, 1.0], 3.0), {1: 1.0})
def test_answers_map_onto_the_menu(self):
self.assertEqual(M.map_answer(REF, {"action": "CHECK"}, 0.02), ({0: 1.0}, None))
m, d = M.map_answer(REF, {"action": "RAISE", "size": 0.02}, 0.02) # 100 chips = 0.5 pot: on the menu
self.assertEqual(m, {1: 1.0})
self.assertAlmostEqual(d, 0.0)
m, d = M.map_answer(REF, {"action": "RAISE", "size": 0.03}, 0.02) # 150 chips = 0.75 pot
self.assertAlmostEqual(m[1], 0.375 / 0.875)
self.assertAlmostEqual(d, 0.25)
m, d = M.map_answer(REF, {"action": "RAISE", "size": 0.2}, 0.02) # 1000 chips = the jam
self.assertEqual(m, {3: 1.0})
def test_fold_without_fold_option_is_the_passive_action(self):
self.assertEqual(M.map_answer(REF, {"action": "FOLD"}, 0.02)[0], {0: 1.0})
def test_loss_is_zero_for_the_best_action_and_weighted(self):
best = {"AsKs": {1: 1.0}, "7c2d": {0: 1.0}}
self.assertAlmostEqual(M.loss_chips(REF, best), 0.0)
# always check: AsKs loses 20 (30-10), 7c2d loses 0: 0.25 * 20
self.assertAlmostEqual(M.loss_chips(REF, {"AsKs": {0: 1.0}, "7c2d": {0: 1.0}}), 5.0)
# a mixture: AsKs 50/50 between 30 and 20 loses 5
self.assertAlmostEqual(M.loss_chips(REF, {"AsKs": {1: 0.5, 2: 0.5}, "7c2d": {0: 1.0}}), 0.25 * 5.0)
def test_a_missing_hand_is_an_error_not_a_zero(self):
with self.assertRaises(KeyError):
M.loss_chips(REF, {"AsKs": {1: 1.0}})
def test_reference_noise_floor(self):
self.assertAlmostEqual(M.reference_loss_chips(REF), 0.0)
def test_knoten_menu_entries_map_like_answers(self):
self.assertEqual(M.map_menu_entry(REF, 1, 0.0)[0], {0: 1.0})
self.assertEqual(M.map_menu_entry(REF, 0, 0.0)[0], {0: 1.0}) # no fold on this menu: the passive action
m, d = M.map_menu_entry(REF, 2, 1.5) # 150 chips = 0.75 pot
self.assertAlmostEqual(m[1], 0.375 / 0.875)
self.assertAlmostEqual(d, 0.25)
self.assertEqual(M.map_menu_entry(REF, 2, 10.0)[0], {3: 1.0})
if __name__ == "__main__":
unittest.main()