Cidr4 merge algorithm #5

Merged
PavelPatsey merged 91 commits from CIDR4_merge_algorithm into main 2025-01-27 22:05:39 +03:00
Showing only changes of commit 95fbdff75f - Show all commits
+56 -6
View File
@@ -1,11 +1,23 @@
import pytest import pytest
from cidr4_merger import (Cidr4MergerError, cidr4_to_node, from cidr4_merger import (
find_neighbours_singles, get_group_with_max_mask_len, Cidr4MergerError,
get_net_addr, get_parent_ip, have_same_parent, cidr4_to_node,
lift_lonely_node, make_cidr4, make_groups, find_neighbours_singles,
make_parent, merge_neighbors, merge_nodes, get_group_with_max_mask_len,
merge_nodes_recursion, reduce_nodes, sort_nodes) 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(): 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(): # def test_merge_nodes_recursion():
# assert merge_nodes( # assert merge_nodes(
# [ # [