add find_neighbours_singles function test

This commit is contained in:
Pavel Patsey
2025-01-18 23:54:00 +03:00
parent c56d09cfd9
commit 95fbdff75f
+56 -6
View File
@@ -1,11 +1,23 @@
import pytest
from cidr4_merger import (Cidr4MergerError, cidr4_to_node,
find_neighbours_singles, get_group_with_max_mask_len,
get_net_addr, get_parent_ip, have_same_parent,
lift_lonely_node, make_cidr4, make_groups,
make_parent, merge_neighbors, merge_nodes,
merge_nodes_recursion, reduce_nodes, sort_nodes)
from cidr4_merger import (
Cidr4MergerError,
cidr4_to_node,
find_neighbours_singles,
get_group_with_max_mask_len,
get_net_addr,
get_parent_ip,
have_same_parent,
lift_lonely_node,
make_cidr4,
make_groups,
make_parent,
merge_neighbors,
merge_nodes,
merge_nodes_recursion,
reduce_nodes,
sort_nodes,
)
def test_true():
@@ -218,6 +230,44 @@ def test_make_groups():
}
def test_find_neighbours_singles():
nodes_with_neighbours = [
(0, 2, 12, 0),
(1073741824, 2, 3, 0),
(2147483648, 2, 1, 2147483648),
(3221225472, 2, 2, 2147483648),
]
groups_with_neighbours = make_groups(nodes_with_neighbours)
assert find_neighbours_singles(groups_with_neighbours) == (
[
((0, 2, 12, 0), (1073741824, 2, 3, 0)),
((2147483648, 2, 1, 2147483648), (3221225472, 2, 2, 2147483648)),
],
[],
)
nodes_with_singles = [
(0, 2, 12, 0),
(2147483648, 2, 1, 2147483648),
]
groups_with_singles = make_groups(nodes_with_singles)
assert find_neighbours_singles(groups_with_singles) == (
[],
[(0, 2, 12, 0), (2147483648, 2, 1, 2147483648)],
)
nodes_with_neighbours_n_singles = [
(0, 2, 12, 0),
(1073741824, 2, 3, 0),
(2147483648, 2, 1, 2147483648),
]
groups_with_singles = make_groups(nodes_with_neighbours_n_singles)
assert find_neighbours_singles(groups_with_singles) == (
[((0, 2, 12, 0), (1073741824, 2, 3, 0))],
[(2147483648, 2, 1, 2147483648)],
)
# def test_merge_nodes_recursion():
# assert merge_nodes(
# [