about summary refs log tree commit diff
path: root/.venv/lib/python3.12/site-packages/networkx/algorithms/tests/test_broadcasting.py
diff options
context:
space:
mode:
authorS. Solomon Darnell2025-03-28 21:52:21 -0500
committerS. Solomon Darnell2025-03-28 21:52:21 -0500
commit4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch)
treeee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/networkx/algorithms/tests/test_broadcasting.py
parentcc961e04ba734dd72309fb548a2f97d67d578813 (diff)
downloadgn-ai-master.tar.gz
two version of R2R are here HEAD master
Diffstat (limited to '.venv/lib/python3.12/site-packages/networkx/algorithms/tests/test_broadcasting.py')
-rw-r--r--.venv/lib/python3.12/site-packages/networkx/algorithms/tests/test_broadcasting.py82
1 files changed, 82 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/networkx/algorithms/tests/test_broadcasting.py b/.venv/lib/python3.12/site-packages/networkx/algorithms/tests/test_broadcasting.py
new file mode 100644
index 00000000..73bf83c8
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/networkx/algorithms/tests/test_broadcasting.py
@@ -0,0 +1,82 @@
+"""Unit tests for the broadcasting module."""
+
+import math
+
+import networkx as nx
+
+
+def test_example_tree_broadcast():
+    """
+    Test the BROADCAST algorithm on the example in the paper titled: "Information Dissemination in Trees"
+    """
+    edge_list = [
+        (0, 1),
+        (1, 2),
+        (2, 7),
+        (3, 4),
+        (5, 4),
+        (4, 7),
+        (6, 7),
+        (7, 9),
+        (8, 9),
+        (9, 13),
+        (13, 14),
+        (14, 15),
+        (14, 16),
+        (14, 17),
+        (13, 11),
+        (11, 10),
+        (11, 12),
+        (13, 18),
+        (18, 19),
+        (18, 20),
+    ]
+    G = nx.Graph(edge_list)
+    b_T, b_C = nx.tree_broadcast_center(G)
+    assert b_T == 6
+    assert b_C == {13, 9}
+    # test broadcast time from specific vertex
+    assert nx.tree_broadcast_time(G, 17) == 8
+    assert nx.tree_broadcast_time(G, 3) == 9
+    # test broadcast time of entire tree
+    assert nx.tree_broadcast_time(G) == 10
+
+
+def test_path_broadcast():
+    for i in range(2, 12):
+        G = nx.path_graph(i)
+        b_T, b_C = nx.tree_broadcast_center(G)
+        assert b_T == math.ceil(i / 2)
+        assert b_C == {
+            math.ceil(i / 2),
+            math.floor(i / 2),
+            math.ceil(i / 2 - 1),
+            math.floor(i / 2 - 1),
+        }
+        assert nx.tree_broadcast_time(G) == i - 1
+
+
+def test_empty_graph_broadcast():
+    H = nx.empty_graph(1)
+    b_T, b_C = nx.tree_broadcast_center(H)
+    assert b_T == 0
+    assert b_C == {0}
+    assert nx.tree_broadcast_time(H) == 0
+
+
+def test_star_broadcast():
+    for i in range(4, 12):
+        G = nx.star_graph(i)
+        b_T, b_C = nx.tree_broadcast_center(G)
+        assert b_T == i
+        assert b_C == set(G.nodes())
+        assert nx.tree_broadcast_time(G) == b_T
+
+
+def test_binomial_tree_broadcast():
+    for i in range(2, 8):
+        G = nx.binomial_tree(i)
+        b_T, b_C = nx.tree_broadcast_center(G)
+        assert b_T == i
+        assert b_C == {0, 2 ** (i - 1)}
+        assert nx.tree_broadcast_time(G) == 2 * i - 1