def test_closest_nodes_only_additional(empty_routing_table):
    target = NodeIDFactory()
    nodes = [NodeIDFactory() for _ in range(10)]
    closest_nodes = list(iter_closest_nodes(target, empty_routing_table,
                                            nodes))
    assert closest_nodes == sorted(
        nodes, key=lambda node: compute_distance(target, node))
def test_closest_nodes_only_routing(empty_routing_table):
    target = NodeIDFactory()
    nodes = [NodeIDFactory() for _ in range(10)]
    for node in nodes:
        empty_routing_table.update(node)

    closest_nodes = list(iter_closest_nodes(target, empty_routing_table, []))
    assert closest_nodes == sorted(nodes, key=lambda node: compute_distance(target, node))
def test_lookup_generator_mixed(empty_routing_table):
    target = NodeIDFactory()
    nodes = sorted([NodeIDFactory() for _ in range(10)],
                   key=lambda node: compute_distance(node, target))
    nodes_in_routing_table = nodes[:3] + nodes[6:8]
    nodes_in_additional = nodes[3:6] + nodes[8:]
    for node in nodes_in_routing_table:
        empty_routing_table.update(node)
    closest_nodes = list(
        iter_closest_nodes(target, empty_routing_table, nodes_in_additional))
    assert closest_nodes == nodes
def test_closest_nodes_empty(empty_routing_table):
    target = NodeIDFactory()
    assert list(iter_closest_nodes(target, empty_routing_table, [])) == []