Something went wrong. Try again.
bayes for days
Something went wrong. Try again.
Python
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990"""What `sds melee` counts, and what it refuses to count."""
import gzipimport jsonimport unittestfrom pathlib import Pathfrom tempfile import TemporaryDirectory
from sds.melee import scan
# One round of MegaMek's own log: a kick that lands, a punch that misses, and a# weapon attack that must not be mistaken for either.REPORT = """<html><body><span>Weapon Attack Phase</span><span>Weapons fire for Atlas AS7-D (sds North)</span><span> Medium Laser at Dragon DRG-1N (princess South); needs 8, rolls 9 :hits CT</span><span>Physical Attack Phase-------------------</span><span>Physical attacks for Atlas AS7-D (sds North)</span><span> Kick (Left leg) at Dragon DRG-1N (princess South); needs 5, rolls 7 :hits (using Left Side Kick table) LL</span><span>Physical attacks for Dragon DRG-1N (princess South)</span><span> Punch (Right Arm) at Atlas AS7-D (sds North); needs 6, rolls 3 :misses</span><span>Heat Phase-------------------</span></body></html>"""
SEAT = { "name": "sds North", "kind": "sds", "sds": { "decisions": 10, "answered": 9, "defaulted": 1, "illegal": 0, "phases": {"physical": {"decisions": 2, "answered": 2}}, },}
class MeleeCounts(unittest.TestCase): def _run(self, name="m1.report.html", body=REPORT, compress=False): tmp = TemporaryDirectory() self.addCleanup(tmp.cleanup) run = Path(tmp.name) path = run / (name + ".gz" if compress else name) if compress: path.write_bytes(gzip.compress(body.encode())) else: path.write_text(body, encoding="utf-8") (run / "m1-sds_North.seat.json").write_text(json.dumps(SEAT), encoding="utf-8") return run
def test_counts_each_side_separately(self): found = scan(self._run()) self.assertEqual(found.matches, 1) self.assertEqual(found.side("sds North"), 1) self.assertEqual(found.hits("sds North"), 1) self.assertEqual(found.side("princess South"), 1) self.assertEqual(found.hits("princess South"), 0, "a miss is a swing, not a hit")
def test_a_weapon_attack_is_not_a_physical(self): """The Medium Laser in the fixture is the whole point of it.
A looser pattern - anything that "hits" - counts the gun as a kick and every rate this tool prints becomes a firing rate wearing melee's name. """ found = scan(self._run()) kinds = {kind for (_side, kind, _outcome) in found.swings} self.assertEqual(kinds, {"Kick", "Punch"})
def test_a_run_with_no_physicals_reads_nought_rather_than_failing(self): quiet = REPORT[: REPORT.index("<span>Physical attacks")] + "</body></html>" found = scan(self._run(body=quiet)) self.assertEqual(found.matches, 1) self.assertEqual(sum(found.swings.values()), 0)
def test_a_gzipped_log_reads_the_same(self): """Decision logs get compressed as a run goes; readers accept `.gz`.""" plain = scan(self._run()) packed = scan(self._run(compress=True)) self.assertEqual(plain.swings, packed.swings)
def test_the_seat_tallies_come_back_with_the_rate(self): found = scan(self._run()) self.assertEqual((found.answered, found.decisions), (9, 10)) self.assertEqual(found.physical_answered, 2)
if __name__ == "__main__": unittest.main()