Something went wrong. Try again.
bayes for days
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127"""The recording MegaMek is held to, and the check that holds it there.
`./sds.sh conformance` re-asks MegaMek every question this repository hasalready asked it and diffs the answers against `bridge/conformance.txt`. Thathalf needs Docker and a MegaMek install and is not run here.
What is run here is the half that can be: the recording parses, it still holdsthe facts the code depends on, and the comparison actually reports a moved factrather than passing quietly. A conformance check nobody has seen fail is notknown to work, so the failure path is a test rather than a claim."""
import unittestfrom pathlib import Path
from sds.match import _facts
RECORDING = Path(__file__).resolve().parent.parent / "bridge" / "conformance.txt"
class RecordingTest(unittest.TestCase): def setUp(self) -> None: self.facts = _facts(RECORDING.read_text())
def test_the_recording_parses(self) -> None: self.assertGreater(len(self.facts), 30, "the recording is too small to be the real one") for key, value in self.facts.items(): self.assertTrue(key, "a fact with no key") self.assertTrue(value, f"{key} recorded nothing")
def test_keys_are_unique_and_sectioned(self) -> None: lines = [ line.partition(" = ")[0].strip() for line in RECORDING.read_text().splitlines() if " = " in line and not line.startswith("#") ] self.assertEqual(len(lines), len(set(lines)), "a key is recorded twice") for key in lines: self.assertIn(".", key, f"{key} names no section")
def test_the_artillery_guard_is_an_instanceof_and_not_a_flag(self) -> None: # An artillery cannon carries the artillery flag and is not an # ArtilleryWeapon. Declaring a cannon shot as a tube shot crashed # MegaMek's packet pump, so the guard reads the class. self.assertEqual(self.facts["class.artillery-cannon.is-artillery-weapon"], "false") self.assertEqual( self.facts["class.artillery-cannon.superclass"], "megamek.common.weapons.AmmoWeapon", )
def test_the_physical_options_that_build_nothing(self) -> None: # An enumeration that calls toAction on every type hands a null onward. for option in ("use-claw", "trip-attack", "thrash-inf"): self.assertTrue( self.facts[f"physical.to-action.{option}"].endswith("null"), f"{option} was recorded as building an action", ) # And one that does build, so the check above cannot pass by accident # on a probe that has stopped asking properly. self.assertTrue(self.facts["physical.to-action.use-club"].endswith("ClubAttackAction")) self.assertEqual(self.facts["physical.club.mounted"], "true")
def test_a_declared_displacement_attack_forbids_firing(self) -> None: self.assertIn("firing=true", self.facts["eligibility.firing.idle"]) self.assertIn("firing=false", self.facts["eligibility.firing.charging"]) self.assertIn("firing=false", self.facts["eligibility.firing.making-dfa"])
def test_infantry_cover_is_eight_terrains_and_carries_no_level(self) -> None: self.assertTrue(self.facts["infantry.cover.terrains"].startswith("8: ")) self.assertEqual(self.facts["infantry.cover.level-sensitive"], "false") # Urban guerrilla adds pavement and road, and nothing else. self.assertTrue(self.facts["infantry.cover.urban-guerrilla.terrains"].startswith("10: "))
def test_the_damage_sentinels_are_distinct_negatives(self) -> None: sentinels = { key: int(value) for key, value in self.facts.items() if key.startswith("sentinel.damage.") and not key.endswith("census") } self.assertEqual(len(sentinels), len(set(sentinels.values()))) for key, value in sentinels.items(): self.assertLess(value, 0, f"{key} is not a sentinel")
class ComparisonTest(unittest.TestCase): """The diff names the fact, in each of the three ways a recording can rot."""
def setUp(self) -> None: self.recorded = _facts(RECORDING.read_text())
@staticmethod def compare(recorded: dict, observed: dict) -> tuple[list, list, list]: moved = [k for k in recorded if k in observed and recorded[k] != observed[k]] gone = [k for k in recorded if k not in observed] added = [k for k in observed if k not in recorded] return moved, gone, added
def test_identical_recordings_agree(self) -> None: self.assertEqual(self.compare(self.recorded, dict(self.recorded)), ([], [], []))
def test_a_moved_answer_is_named(self) -> None: observed = dict(self.recorded) observed["class.artillery-cannon.is-artillery-weapon"] = "true" moved, gone, added = self.compare(self.recorded, observed) self.assertEqual(moved, ["class.artillery-cannon.is-artillery-weapon"]) self.assertEqual((gone, added), ([], []))
def test_a_vanished_fact_is_named(self) -> None: observed = dict(self.recorded) observed.pop("c3.max-nodes") moved, gone, added = self.compare(self.recorded, observed) self.assertEqual(gone, ["c3.max-nodes"])
def test_a_new_fact_is_named(self) -> None: observed = dict(self.recorded) observed["physical.to-action.headbutt"] = "type=14 null" moved, gone, added = self.compare(self.recorded, observed) self.assertEqual(added, ["physical.to-action.headbutt"])
def test_comments_and_blank_lines_are_not_facts(self) -> None: parsed = _facts("# a comment = not a fact\n\nkey.one = 1\n \nkey.two = 2\n") self.assertEqual(parsed, {"key.one": "1", "key.two": "2"})
if __name__ == "__main__": unittest.main()