def test_add_overlap_edges():

    grid_dict = {
        "id": [0, 1, 2, 3, 4, 5, 6, 7],
        "i": [0, 1, 2, 0, 1, 2, 0, 1],
        "j": [2, 2, 2, 1, 1, 1, 0, 0],
        "x": [1., 2., 3., 1., 2., 3., 1., 2.],
        "y": [6., 6., 6., 5., 5., 5., 4., 4.],
        'layer 1 start': [0., 0., 0., 0., 0., 0., 0., 0.]
    }
    overlap_dict = {"id_x": [0], "id_y": [100]}

    grid_df = pd.DataFrame(grid_dict)
    id_indexed_grid_df = grid_df.set_index("id")
    id_array, x_array, y_array, z_array = make_grid_arrays(grid_df)

    grid_dict = get_neighbours_distance(grid_df, id_indexed_grid_df, id_array,
                                        x_array, y_array, z_array)

    overlap_df = pd.DataFrame(overlap_dict)

    pre_length = len(grid_dict[0])

    add_overlap_edges(grid_dict, overlap_df)

    assert len(grid_dict[0]) == pre_length + 1
    assert 100 in grid_dict[0].keys()
def test_get_neighbours_gradient():

    grid_dict = {
        "id": [0, 1, 2, 3, 4, 5, 6, 7],
        "i": [0, 1, 2, 0, 1, 2, 0, 1],
        "j": [2, 2, 2, 1, 1, 1, 0, 0],
        "x": [1., 2., 3., 1., 2., 3., 1., 2.],
        "y": [6., 6., 6., 5., 5., 5., 4., 4.],
        'layer 1 start': [0., 0., 0., 0., 1., 0., 0., 0.]
    }

    grid_df = pd.DataFrame(grid_dict)
    id_indexed_grid_df = grid_df.set_index("id")
    id_array, x_array, y_array, z_array = make_grid_arrays(grid_df)

    result = get_neighbours_gradient(grid_df, id_indexed_grid_df, id_array,
                                     x_array, y_array, z_array)

    angle_rad = np.arctan(1. / np.sqrt(2))
    angle_deg = np.degrees(angle_rad)

    indices = [0, 2, 6, 1, 3, 5, 7]
    metrics = [angle_deg, angle_deg, angle_deg, 45., 45., 45., 45.]

    assert set(result[4].keys()) == set(indices)

    for index, weight in zip(indices, metrics):
        assert np.isclose(result[4][index]['weight'], weight)
def test_get_metric_weights():

    grid_dict = {
        "id": [0, 1, 2, 3, 4, 5, 6, 7],
        "i": [0, 1, 2, 0, 1, 2, 0, 1],
        "j": [2, 2, 2, 1, 1, 1, 0, 0],
        "x": [1., 2., 3., 1., 2., 3., 1., 2.],
        "y": [6., 6., 6., 5., 5., 5., 4., 4.],
        'layer 1 start': [0., 0., 0., 0., 0., 0., 0., 0.]
    }

    grid_df = pd.DataFrame(grid_dict)
    id_indexed_grid_df = grid_df.set_index("id")
    id_array, x_array, y_array, z_array = make_grid_arrays(grid_df)

    result = get_metric_weights(4, id_indexed_grid_df, id_array, x_array,
                                y_array, z_array, edge_length)

    indices = [0, 2, 6, 1, 3, 5, 7]
    metrics = [np.sqrt(2), np.sqrt(2), np.sqrt(2), 1.0, 1.0, 1.0, 1.0]

    assert set(result.keys()) == set(indices)

    for index, weight in zip(indices, metrics):
        assert np.isclose(result[index]['weight'], weight)
def test_get_metric_edges():

    grid_dict = {
        "id": [0, 1, 2, 3, 4, 5, 6, 7],
        "i": [0, 1, 2, 0, 1, 2, 0, 1],
        "j": [2, 2, 2, 1, 1, 1, 0, 0],
        "x": [1., 2., 3., 1., 2., 3., 1., 2.],
        "y": [6., 6., 6., 5., 5., 5., 4., 4.],
        'layer 1 start': [0., 0., 0., 0., 0., 0., 0., 0.]
    }

    grid_df = pd.DataFrame(grid_dict)
    id_indexed_grid_df = grid_df.set_index("id")
    id_array, x_array, y_array, z_array = make_grid_arrays(grid_df)

    point_ids, metrics = get_metric_edges(4, id_indexed_grid_df, id_array,
                                          x_array, y_array, z_array,
                                          edge_length)

    assert len(point_ids) == len(metrics)
    assert set(point_ids) == set([0, 1, 2, 3, 5, 6, 7])
    assert set(metrics) == set([1.0, np.sqrt(2)])