Skip to content

Commit

Permalink
feat: adds dijkstra.railroad (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
william-silversmith committed Aug 31, 2021
1 parent 8ebe334 commit d3da628
Show file tree
Hide file tree
Showing 4 changed files with 8,915 additions and 5,785 deletions.
59 changes: 59 additions & 0 deletions automated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,65 @@ def test_dijkstra2d_10x10_26(dtype, bidirectional, connectivity, compass):
[5,5,0],
]))

@pytest.mark.parametrize("dtype", TEST_TYPES)
@pytest.mark.parametrize("connectivity", [ 18, 26 ])
def test_value_target_dijkstra2d_10x10_26(dtype, connectivity):
values = np.ones((10,10,1), dtype=dtype)
values[1,1,0] = 0

path = dijkstra3d.railroad(
values, (1,1,0), connectivity=connectivity,
)
assert len(path) == 1
assert np.all(path == np.array([ [1,1,0] ]))

path = dijkstra3d.railroad(
values, (0,0,0), connectivity=connectivity,
)

assert len(path) == 2
assert np.all(path == np.array([
[0,0,0],
[1,1,0],
]))

values[:,:,:] = 1
values[5,5,0] = 0

path = dijkstra3d.railroad(
values, (0,0,0), connectivity=connectivity,
)

assert len(path) == 6
assert np.all(path == np.array([
[0,0,0],
[1,1,0],
[2,2,0],
[3,3,0],
[4,4,0],
[5,5,0],
]))

values[:,:,:] = 1
values[9,9,0] = 0
path = dijkstra3d.railroad(
values, (0,0,0), connectivity=connectivity,
)

assert len(path) == 10
assert np.all(path == np.array([
[0,0,0],
[1,1,0],
[2,2,0],
[3,3,0],
[4,4,0],
[5,5,0],
[6,6,0],
[7,7,0],
[8,8,0],
[9,9,0]
]))

# There are many more equal distance paths
# for 6 connected... so we have to be less specific.
@pytest.mark.parametrize("dtype", TEST_TYPES)
Expand Down

0 comments on commit d3da628

Please sign in to comment.