def test_flexible(): # Create MCP and do a traceback mcp = FlexibleMCP(a) costs, traceback = mcp.find_costs([(0, 0)]) # Check that inner part is correct. This basically # tests whether travel_cost works. assert_array_equal( costs[:4, :4], [[1, 2, 3, 4], [2, 2, 3, 4], [3, 3, 3, 4], [4, 4, 4, 4]]) # Test that the algorithm stopped at the right distance. # Note that some of the costs are filled in but not yet frozen, # so we take a bit of margin assert np.all(costs[-2:, :] == np.inf) assert np.all(costs[:, -2:] == np.inf)
def test_flexible(): # Create MCP and do a traceback mcp = FlexibleMCP(a) costs, traceback = mcp.find_costs([(0, 0)]) # Check that inner part is correct. This basically # tests whether travel_cost works. assert_array_equal(costs[:4, :4], [[1, 2, 3, 4], [2, 2, 3, 4], [3, 3, 3, 4], [4, 4, 4, 4]]) # Test that the algorithm stopped at the right distance. # Note that some of the costs are filled in but not yet frozen, # so we take a bit of margin assert np.all(costs[-2:, :] == np.inf) assert np.all(costs[:, -2:] == np.inf)
def test_connections(): # Create MCP object with three seed points mcp = MCP(a) costs, traceback = mcp.find_costs([ (1,1), (7,7), (1,7) ]) # Test that all three seed points are connected connections = set(mcp._conn.keys()) assert (0, 1) in connections assert (1, 2) in connections assert (0, 2) in connections # Test that any two neighbors have only been connected once for position_tuples in mcp._conn.values(): n1 = len(position_tuples) n2 = len(set(position_tuples)) assert n1 == n2 # For seed 0 and 1 cost, pos1, pos2 = mcp._bestconn[(0,1)] # Test meeting points assert (pos1, pos2) == ( (3,3), (4,4) ) # Test the whole path path = mcp.traceback(pos1) + list(reversed(mcp.traceback(pos2))) assert_array_equal(path, [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)]) # For seed 1 and 2 cost, pos1, pos2 = mcp._bestconn[(1,2)] # Test meeting points assert (pos1, pos2) == ( (3,7), (4,7) ) # Test the whole path path = mcp.traceback(pos1) + list(reversed(mcp.traceback(pos2))) assert_array_equal(path, [(1, 7), (2, 7), (3, 7), (4, 7), (5, 7), (6, 7), (7, 7)]) # For seed 0 and 2 cost, pos1, pos2 = mcp._bestconn[(0,2)] # Test meeting points assert (pos1, pos2) == ( (1,3), (1,4) ) # Test the whole path path = mcp.traceback(pos1) + list(reversed(mcp.traceback(pos2))) assert_array_equal(path, [(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (1, 7)])
def test_connections(): # Create MCP object with three seed points mcp = MCP(a) costs, traceback = mcp.find_costs([(1, 1), (7, 7), (1, 7)]) # Test that all three seed points are connected connections = set(mcp._conn.keys()) assert (0, 1) in connections assert (1, 2) in connections assert (0, 2) in connections # Test that any two neighbors have only been connected once for position_tuples in mcp._conn.values(): n1 = len(position_tuples) n2 = len(set(position_tuples)) assert n1 == n2 # For seed 0 and 1 cost, pos1, pos2 = mcp._bestconn[(0, 1)] # Test meeting points assert (pos1, pos2) == ((3, 3), (4, 4)) # Test the whole path path = mcp.traceback(pos1) + list(reversed(mcp.traceback(pos2))) assert_array_equal(path, [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7)]) # For seed 1 and 2 cost, pos1, pos2 = mcp._bestconn[(1, 2)] # Test meeting points assert (pos1, pos2) == ((3, 7), (4, 7)) # Test the whole path path = mcp.traceback(pos1) + list(reversed(mcp.traceback(pos2))) assert_array_equal(path, [(1, 7), (2, 7), (3, 7), (4, 7), (5, 7), (6, 7), (7, 7)]) # For seed 0 and 2 cost, pos1, pos2 = mcp._bestconn[(0, 2)] # Test meeting points assert (pos1, pos2) == ((1, 3), (1, 4)) # Test the whole path path = mcp.traceback(pos1) + list(reversed(mcp.traceback(pos2))) assert_array_equal(path, [(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (1, 7)])