From 95fbdff75fcc192756df540a6312812b7ae057e6 Mon Sep 17 00:00:00 2001 From: Pavel Patsey Date: Sat, 18 Jan 2025 23:54:00 +0300 Subject: [PATCH] add find_neighbours_singles function test --- tests/test_cidr4_merger.py | 62 ++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/tests/test_cidr4_merger.py b/tests/test_cidr4_merger.py index 18af387..3389d7f 100644 --- a/tests/test_cidr4_merger.py +++ b/tests/test_cidr4_merger.py @@ -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( # [