add merge_nodes_cycle func

This commit is contained in:
Pavel Patsey
2025-01-19 01:00:01 +03:00
parent 8ce8ac6e1a
commit 39e99d24b6
2 changed files with 44 additions and 2 deletions
+27
View File
@@ -15,6 +15,7 @@ from cidr4_merger import (
merge_neighbors,
merge_nodes_deprecated,
merge_nodes_recursion,
merge_nodes_cycle,
reduce_nodes,
sort_nodes,
)
@@ -351,3 +352,29 @@ def test_merge_nodes_recursion():
)
assert exc_info.type is Cidr4MergerError
assert str(exc_info.value) == "The top of the tree has no parent!"
def test_merge_nodes_cycle():
assert merge_nodes_cycle(
[
(0, 2, 12, 0),
(2147483648, 2, 1, 2147483648),
(3221225472, 2, 2, 2147483648),
],
2,
) == [
(2147483648, 1, 3, 0),
(0, 2, 12, 0),
]
with pytest.raises(Exception) as exc_info:
merge_nodes_cycle(
[
(0, 2, 12, 0),
(2147483648, 2, 1, 2147483648),
(3221225472, 2, 2, 2147483648),
],
1,
)
assert exc_info.type is Cidr4MergerError
assert str(exc_info.value) == "The top of the tree has no parent!"