Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/test_layout_of.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,25 @@ def test_a_map_row_without_a_string_id_is_no_map() -> None:
this["id"] = no_id
pins = [{"type": "pin", "id": "p", "map": no_id, "x_hand": True}]
assert layout_of(this, [this, ground], pins) == {"layout": None, "ground": None, "hand": []}, no_id


def test_layout_of_is_pure() -> None:
cases = {c["name"]: c for c in load_fixture()["layout_cases"]}
case = cases["hand-in-id-order"]
elements: list[dict[str, Any]] = case["elements"]
maps = [e for e in elements if e["type"] == "map"]
pins = [e for e in elements if e["type"] == "pin"]
this = rows_read(case, elements)[0]
before = json.dumps([this, maps, pins], sort_keys=True)
got = layout_of(this, maps, pins)
assert json.dumps([this, maps, pins], sort_keys=True) == before, "layout_of moved its input"
first = json.dumps(got, sort_keys=True)
assert got["layout"] is not None and got["hand"]
got["layout"] = "planted"
got["hand"][0] = "planted"
got["hand"].append("extra")
assert json.dumps([this, maps, pins], sort_keys=True) == before
again = layout_of(this, maps, pins)
assert json.dumps(again, sort_keys=True) == first
assert again["layout"] != "planted"
assert again["hand"] != got["hand"]
20 changes: 20 additions & 0 deletions tests/test_map_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,23 @@ def test_a_whole_float_reads_as_its_integer_and_a_boolean_is_no_number() -> None
assert got["zones"] == [{"zone": "z", "map": "m", "shape": "polygon", "points": [[2, 3, 0]]}]
assert got["out"] == {"no_point": 3}
assert all(type(n) is int for n in got["zones"][0]["points"][0])


def test_map_space_is_pure() -> None:
cases = {c["name"]: c for c in load_fixture()["cases"]}
elements: list[dict[str, Any]] = cases["measured-frame-from-placed-points"]["elements"]
before = json.dumps(elements, sort_keys=True)
got = map_space(elements)
assert json.dumps(elements, sort_keys=True) == before, "map_space moved its input"
first = json.dumps(got, sort_keys=True)
assert got["maps"] and got["zones"] and got["pins"] and got["out"]
got["maps"][0]["id"] = "planted"
got["zones"][0]["points"][0][0] = -1
got["zones"][0]["points"].append([-2, -2, -2])
got["pins"][0]["x"] = -1
got["out"]["no_point"] = -1
assert json.dumps(elements, sort_keys=True) == before
again = map_space(elements)
assert json.dumps(again, sort_keys=True) == first
assert again["maps"][0]["id"] != "planted"
assert again["zones"][0]["points"] != got["zones"][0]["points"]
22 changes: 22 additions & 0 deletions tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,25 @@ def test_only_a_report_is_shown_with_talks() -> None:
no_report: tuple[Any, ...] = (None, [], "a report", 7)
for nothing in no_report:
assert report_talks_of(nothing) == []


def test_report_threads_of_is_pure() -> None:
cases = {c["name"]: c for c in load_fixture()["thread_cases"]}
narratives: list[dict[str, Any]] = cases["chain-as-written"]["narratives"]
before = json.dumps(narratives, sort_keys=True)
got = report_threads_of(narratives)
assert json.dumps(narratives, sort_keys=True) == before, "report_threads_of moved its input"
first = json.dumps(got, sort_keys=True)
assert got["parents"] and got["groups"] and got["lints"]
first_report = next(iter(got["parents"]))
got["parents"][first_report] = "missing"
got["groups"][0]["parent"] = "planted"
got["groups"][0]["reports"][0] = "planted"
got["groups"][0]["reports"].append("extra")
got["lints"][0]["report"] = "planted"
assert json.dumps(narratives, sort_keys=True) == before
again = report_threads_of(narratives)
assert json.dumps(again, sort_keys=True) == first
assert again["parents"][first_report] != "missing"
assert again["groups"][0]["parent"] != "planted"
assert again["groups"][0]["reports"] != got["groups"][0]["reports"]