48 lines
2.1 KiB
Python
48 lines
2.1 KiB
Python
"""Spec of the aggregation (python3 -m unittest score/test_aggregation.py)."""
|
|
import os, sys, unittest
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
import aggregation as G
|
|
|
|
JE100 = {"FLOP|srp|eroeffnen": 10.0, "RIVER|srp|eroeffnen": 30.0, "TURN|srp|eroeffnen": 5.0}
|
|
|
|
|
|
def sp(i, st, loss):
|
|
return {"id": i, "stratum": st, "loss": loss}
|
|
|
|
|
|
SPOTS = [sp("a1", "FLOP|srp|eroeffnen", 100.0), sp("a2", "FLOP|srp|eroeffnen", 300.0), sp("b1", "RIVER|srp|eroeffnen", 100.0)]
|
|
|
|
|
|
class Aggregation(unittest.TestCase):
|
|
def test_weighted_bb_per_100_hand_computed(self):
|
|
# flop: 10 decisions per 100 hands x mean 200 chips = 2 bb -> 20 ; river: 30 x 1 bb = 30
|
|
tot, missing = G.weighted_bb100(SPOTS, JE100, lambda s: s["loss"])
|
|
self.assertAlmostEqual(tot["gesamt"], 50.0)
|
|
self.assertEqual(missing, ["TURN|srp|eroeffnen"]) # not measured, not zero
|
|
by_street, _ = G.weighted_bb100(SPOTS, JE100, lambda s: s["loss"], G.area_street)
|
|
self.assertAlmostEqual(by_street["FLOP"], 20.0)
|
|
self.assertAlmostEqual(by_street["RIVER"], 30.0)
|
|
|
|
def test_strength_anchor_points(self):
|
|
self.assertAlmostEqual(G.strength(0.0, 8.0), 100.0)
|
|
self.assertAlmostEqual(G.strength(8.0, 8.0), 0.0)
|
|
self.assertAlmostEqual(G.strength(2.0, 8.0), 75.0)
|
|
self.assertIsNone(G.strength(1.0, 0.0))
|
|
|
|
def test_paired_difference_uses_the_same_spots_and_brackets_the_point(self):
|
|
base = [dict(s, loss=s["loss"] * 2) for s in SPOTS] # twice the loss: cand - base = -(base)/2 per spot
|
|
point, (lo, hi), n = G.bootstrap_diff(SPOTS, base, JE100, lambda s: s["loss"])
|
|
self.assertEqual(n, 3)
|
|
self.assertAlmostEqual(point, -50.0) # 20+30 vs 40+60
|
|
self.assertLessEqual(lo, point + 1e-9)
|
|
self.assertGreaterEqual(hi, point - 1e-9)
|
|
|
|
def test_pairing_ignores_spots_the_base_does_not_have(self):
|
|
point, _, n = G.bootstrap_diff(SPOTS, SPOTS[:2], JE100, lambda s: s["loss"])
|
|
self.assertEqual(n, 2)
|
|
self.assertAlmostEqual(point, 0.0)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|