Files
scikit-image/scikits/image/graph/tests/test_spath.py
T
2009-11-04 07:52:51 +02:00

35 lines
1003 B
Python

import numpy as np
from numpy.testing import *
from scikits.image.graph import shortest_path
class TestShortestPath:
def test_basic(self):
x = np.array([[1, 1, 3],
[0, 2, 0],
[4, 3, 1]])
path, cost = shortest_path(x)
assert_array_equal(path, [0, 0, 1])
assert_equal(cost, 1)
def test_reach(self):
x = np.array([[1, 1, 3],
[0, 2, 0],
[4, 3, 1]])
path, cost = shortest_path(x, reach=2)
assert_array_equal(path, [0, 0, 2])
assert_equal(cost, 0)
def test_non_square(self):
x = np.array([[1, 1, 1, 1, 5, 5, 5],
[5, 0, 0, 5, 9, 1, 1],
[0, 5, 1, 0, 5, 5, 0],
[6, 1, 1, 5, 0, 0, 1]])
path, cost = shortest_path(x, reach=2)
assert_array_equal(path, [2, 1, 1, 2, 3, 3, 2])
assert_equal(cost, 0)
if __name__ == "__main__":
run_module_suite()