Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
fxjung committed Aug 14, 2024
1 parent c6f46a1 commit 4279fe3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ dev = [
"tomli-w",
"packaging",
"python-gnupg",
"osmnx",
]
doc = [
"recommonmark",
Expand Down
1 change: 1 addition & 0 deletions src/ridepy/util/spaces_cython/spaces.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ cdef class Graph(TransportSpace):
velocity=velocity
)


def random_point(self):
return random.choice(self.vertices)

Expand Down
32 changes: 32 additions & 0 deletions test/test_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,3 +941,35 @@ def test_python_cython_graph_interpolation_equivalence():

assert py_loc == cy_loc
assert py_jump_time == cy_jump_time


def test_python_cython_osm_graph():
import osmnx as ox

g = ox.graph_from_point(
center_point=(45.8037597, 10.2711883),
dist=1000,
dist_type="bbox",
network_type="drive",
simplify=False,
retain_all=False,
)
g_proj = ox.project_graph(g).to_undirected()
high_node_id = 12110534471
other_node_id = 1425321707
assert high_node_id > 2**31 - 1
assert high_node_id in g_proj.nodes
assert other_node_id in g_proj.nodes

cy_graph = CyGraph.from_nx(g_proj, make_attribute_distance="length")
py_graph = Graph.from_nx(g_proj, make_attribute_distance="length")

dcyho = cy_graph.d(high_node_id, other_node_id)
dpyho = py_graph.d(high_node_id, other_node_id)
dcyoh = cy_graph.d(other_node_id, high_node_id)
dpyoh = py_graph.d(other_node_id, high_node_id)

assert dcyho == pytest.approx(dpyho)
assert dpyho == pytest.approx(dcyoh)
assert dcyoh == pytest.approx(dpyoh)
assert dpyoh == pytest.approx(dcyho)

0 comments on commit 4279fe3

Please sign in to comment.