Skip to content

Commit eff55a9

Browse files
edenoclaude
andcommitted
test(core): add failing tests for correct edge_map semantics
Add test_edge_map.py with tests that demonstrate the desired behavior: - edge_map should operate on edge labels (edge_id), not indices - edge_map should validate that target values exist in the graph - edge_map should allow merging multiple edges to a single label These tests currently fail due to the current implementation mixing segment indices with edge labels. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 2c4c810 commit eff55a9

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import numpy as np
2+
import pytest
3+
4+
import track_linearization.core as core
5+
from track_linearization import make_track_graph
6+
7+
def _mk_line_graph():
8+
pos = np.array([[0.0,0.0],[1.0,0.0],[2.0,0.0]], dtype=float)
9+
edges = [(0,1),(1,2)]
10+
g = make_track_graph(pos, edges)
11+
# Explicit, non-index edge IDs to highlight id/index mismatch
12+
g.edges[(0,1)]["edge_id"] = 10
13+
g.edges[(1,2)]["edge_id"] = 20
14+
# Ensure edge distances exist
15+
g.edges[(0,1)]["distance"] = 1.0
16+
g.edges[(1,2)]["distance"] = 1.0
17+
return g
18+
19+
def test_edge_map_label_passthrough_no_change():
20+
g = _mk_line_graph()
21+
pts = np.array([[0.2,0.0],[1.7,0.0]])
22+
df_nomap = core.get_linearized_position(pts, g, use_HMM=False)
23+
df_map = core.get_linearized_position(pts, g, edge_map={10:10, 20:20}, use_HMM=False)
24+
# Same geometry -> identical linear positions
25+
assert np.allclose(df_nomap["linear_position"], df_map["linear_position"])
26+
27+
def test_edge_map_merge_two_edges_to_one_label():
28+
g = _mk_line_graph()
29+
pts = np.array([[0.2,0.0],[1.7,0.0]])
30+
df = core.get_linearized_position(pts, g, edge_map={10:99, 20:99}, use_HMM=False)
31+
assert set(df["track_segment_id"].unique()) == {99}
32+
33+
def test_edge_map_invalid_target_raises():
34+
g = _mk_line_graph()
35+
pts = np.array([[0.2,0.0]])
36+
with pytest.raises(ValueError):
37+
# 42 is not a real edge_id in the graph; must raise
38+
core.get_linearized_position(pts, g, edge_map={10:42}, use_HMM=False)

0 commit comments

Comments
 (0)