From 58c2b5cbe05b56287738f7fbae0d743c4ccd8f78 Mon Sep 17 00:00:00 2001 From: Pavel Patsey Date: Sun, 19 Jan 2025 00:05:21 +0300 Subject: [PATCH] add fixtures for nodes and groups --- tests/test_cidr4_merger.py | 66 ++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/tests/test_cidr4_merger.py b/tests/test_cidr4_merger.py index 3389d7f..efb0925 100644 --- a/tests/test_cidr4_merger.py +++ b/tests/test_cidr4_merger.py @@ -230,15 +230,54 @@ def test_make_groups(): } -def test_find_neighbours_singles(): - nodes_with_neighbours = [ +@pytest.fixture +def nodes_only_neighbours(): + return [ (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) == ( + + +@pytest.fixture +def nodes_only_singles(): + return [ + (0, 2, 12, 0), + (2147483648, 2, 1, 2147483648), + ] + + +@pytest.fixture +def nodes_with_neighbours_n_singles(): + return [ + (0, 2, 12, 0), + (1073741824, 2, 3, 0), + (2147483648, 2, 1, 2147483648), + ] + + +@pytest.fixture +def groups_only_neighbours(nodes_only_neighbours): + return make_groups(nodes_only_neighbours) + + +@pytest.fixture +def groups_only_singles(nodes_only_singles): + return make_groups(nodes_only_singles) + + +@pytest.fixture +def groups_with_neighbours_n_singles(nodes_with_neighbours_n_singles): + return make_groups(nodes_with_neighbours_n_singles) + + +def test_find_neighbours_singles( + groups_only_neighbours, + groups_only_singles, + groups_with_neighbours_n_singles, +): + assert find_neighbours_singles(groups_only_neighbours) == ( [ ((0, 2, 12, 0), (1073741824, 2, 3, 0)), ((2147483648, 2, 1, 2147483648), (3221225472, 2, 2, 2147483648)), @@ -246,28 +285,21 @@ def test_find_neighbours_singles(): [], ) - 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) == ( + assert find_neighbours_singles(groups_only_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) == ( + assert find_neighbours_singles(groups_with_neighbours_n_singles) == ( [((0, 2, 12, 0), (1073741824, 2, 3, 0))], [(2147483648, 2, 1, 2147483648)], ) +def test_merge_neighbors(): + assert True + + # def test_merge_nodes_recursion(): # assert merge_nodes( # [