@@ -22,6 +22,23 @@ def test_transition_matrix_rows_sum_to_one():
2222 assert np .allclose (T .sum (axis = 1 ), 1.0 )
2323
2424
25+ def test_transition_matrix_handles_non_contiguous_node_ids ():
26+ hg = Hypergraph (edge_list = [(492 , 938 ), (938 , 1200 ), (1200 , 5000 )])
27+
28+ T = transition_matrix (hg ).toarray ()
29+ _ , mapping = hg .binary_incidence_matrix (return_mapping = True )
30+ node_to_idx = {node : idx for idx , node in mapping .items ()}
31+
32+ assert T .shape == (4 , 4 )
33+ assert np .allclose (T .sum (axis = 1 ), 1.0 )
34+ assert T [node_to_idx [492 ], node_to_idx [938 ]] == 1.0
35+ assert T [node_to_idx [938 ], node_to_idx [492 ]] == 0.5
36+ assert T [node_to_idx [938 ], node_to_idx [1200 ]] == 0.5
37+ assert T [node_to_idx [1200 ], node_to_idx [938 ]] == 0.5
38+ assert T [node_to_idx [1200 ], node_to_idx [5000 ]] == 0.5
39+ assert T [node_to_idx [5000 ], node_to_idx [1200 ]] == 1.0
40+
41+
2542def test_random_walk_length ():
2643 """Test random walk length equals time + 1."""
2744 np .random .seed (0 )
@@ -31,6 +48,15 @@ def test_random_walk_length():
3148 assert len (path ) == 4
3249
3350
51+ def test_random_walk_returns_non_contiguous_node_ids ():
52+ hg = Hypergraph (edge_list = [(492 , 938 ), (938 , 1200 ), (1200 , 5000 )])
53+
54+ path = random_walk (hg , s = 492 , time = 5 , seed = 0 )
55+
56+ assert path [0 ] == 492
57+ assert set (path ).issubset ({492 , 938 , 1200 , 5000 })
58+
59+
3460def test_stationary_state_properties ():
3561 """Test stationary state is a valid distribution."""
3662 hg = _make_connected_hypergraph ()
0 commit comments