mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-03 01:09:26 +08:00
trace_path: Add tests.
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import numpy as np
|
||||
from numpy.testing import *
|
||||
|
||||
from scikits.image.graph import trace_path
|
||||
|
||||
a = np.ones((8,8), dtype=np.float32)
|
||||
a[1:-1, 1] = 0
|
||||
a[1, 1:-1] = 0
|
||||
|
||||
## array([[ 1., 1., 1., 1., 1., 1., 1., 1.],
|
||||
## [ 1., 0., 0., 0., 0., 0., 0., 1.],
|
||||
## [ 1., 0., 1., 1., 1., 1., 1., 1.],
|
||||
## [ 1., 0., 1., 1., 1., 1., 1., 1.],
|
||||
## [ 1., 0., 1., 1., 1., 1., 1., 1.],
|
||||
## [ 1., 0., 1., 1., 1., 1., 1., 1.],
|
||||
## [ 1., 0., 1., 1., 1., 1., 1., 1.],
|
||||
## [ 1., 1., 1., 1., 1., 1., 1., 1.]], dtype=float32)
|
||||
|
||||
def test_basic():
|
||||
costs, return_path = trace_path(a, (1, 6), [(7, 2)])
|
||||
assert_array_equal(costs,
|
||||
[[ 1., 1., 1., 1., 1., 1., 1., 1.],
|
||||
[ 1., 0., 0., 0., 0., 0., 0., 1.],
|
||||
[ 1., 0., 1., 1., 1., 1., 1., 1.],
|
||||
[ 1., 0., 1., 2., 2., 2., 2., 2.],
|
||||
[ 1., 0., 1., 2., 3., 3., 3., 3.],
|
||||
[ 1., 0., 1., 2., 3., 4., 4., 4.],
|
||||
[ 1., 0., 1., 2., 3., 4., 5., 5.],
|
||||
[ 1., 1., 1., 2., 3., 4., 5., 6.]])
|
||||
|
||||
assert_array_equal(return_path,
|
||||
[[(1, 6),
|
||||
(1, 5),
|
||||
(1, 4),
|
||||
(1, 3),
|
||||
(1, 2),
|
||||
(2, 1),
|
||||
(3, 1),
|
||||
(4, 1),
|
||||
(5, 1),
|
||||
(6, 1),
|
||||
(7, 2)]])
|
||||
|
||||
def test_no_diagonal():
|
||||
costs, path = trace_path(a, (1, 6), [(7, 2)], diagonal_steps=False)
|
||||
assert_array_equal(costs,
|
||||
[[ 2., 1., 1., 1., 1., 1., 1., 2.],
|
||||
[ 1., 0., 0., 0., 0., 0., 0., 1.],
|
||||
[ 1., 0., 1., 1., 1., 1., 1., 2.],
|
||||
[ 1., 0., 1., 2., 2., 2., 2., 3.],
|
||||
[ 1., 0., 1., 2., 3., 3., 3., 4.],
|
||||
[ 1., 0., 1., 2., 3., 4., 4., 5.],
|
||||
[ 1., 0., 1., 2., 3., 4., 5., 6.],
|
||||
[ 2., 1., 2., 3., 4., 5., 6., 7.]])
|
||||
assert_array_equal(path,
|
||||
[[(1, 6),
|
||||
(1, 5),
|
||||
(1, 4),
|
||||
(1, 3),
|
||||
(1, 2),
|
||||
(1, 1),
|
||||
(2, 1),
|
||||
(3, 1),
|
||||
(4, 1),
|
||||
(5, 1),
|
||||
(6, 1),
|
||||
(6, 2),
|
||||
(7, 2)]])
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_module_suite()
|
||||
Reference in New Issue
Block a user