You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.4 KiB
42 lines
1.4 KiB
"""Small integration test: compute_party_coords vs centroids code-path used in trajectories tab.
|
|
|
|
Builds a tiny synthetic positions_by_window and party_map and asserts that the centroids
|
|
returned by compute_party_coords (x and y) match the centroids computed by the
|
|
build_trajectories_tab logic (the same mean computations).
|
|
"""
|
|
|
|
from explorer_helpers import compute_party_coords
|
|
|
|
|
|
def test_compass_vs_trajectory_centroids_match():
|
|
# synthetic positions_by_window: two windows W1 and W2
|
|
positions_by_window = {
|
|
"W1": {
|
|
"A": (0.1, 0.2),
|
|
"B": (0.3, 0.4),
|
|
"C": (-0.2, 0.0),
|
|
},
|
|
"W2": {
|
|
"A": (0.15, 0.25),
|
|
"B": (0.35, 0.45),
|
|
"C": (-0.25, 0.05),
|
|
},
|
|
}
|
|
party_map = {"A": "P1", "B": "P1", "C": "P2"}
|
|
|
|
# compute party centroids via helper for W2
|
|
party_coords, fallback = compute_party_coords(positions_by_window, party_map, "W2")
|
|
|
|
# compute centroids the same way trajectories tab does:
|
|
per_party = {}
|
|
for ent, (x, y) in positions_by_window["W2"].items():
|
|
p = party_map.get(ent)
|
|
per_party.setdefault(p, []).append((x, y))
|
|
centroids = {}
|
|
for p, coords in per_party.items():
|
|
xs = [c[0] for c in coords]
|
|
ys = [c[1] for c in coords]
|
|
centroids[p] = (sum(xs) / len(xs), sum(ys) / len(ys))
|
|
|
|
assert party_coords == centroids
|
|
assert not fallback
|
|
|