about summary refs log tree commit diff
path: root/.venv/lib/python3.12/site-packages/networkx/algorithms/tree/tests/test_decomposition.py
diff options
context:
space:
mode:
Diffstat (limited to '.venv/lib/python3.12/site-packages/networkx/algorithms/tree/tests/test_decomposition.py')
-rw-r--r--.venv/lib/python3.12/site-packages/networkx/algorithms/tree/tests/test_decomposition.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/networkx/algorithms/tree/tests/test_decomposition.py b/.venv/lib/python3.12/site-packages/networkx/algorithms/tree/tests/test_decomposition.py
new file mode 100644
index 00000000..8c376053
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/networkx/algorithms/tree/tests/test_decomposition.py
@@ -0,0 +1,79 @@
+import networkx as nx
+from networkx.algorithms.tree.decomposition import junction_tree
+
+
+def test_junction_tree_directed_confounders():
+    B = nx.DiGraph()
+    B.add_edges_from([("A", "C"), ("B", "C"), ("C", "D"), ("C", "E")])
+
+    G = junction_tree(B)
+    J = nx.Graph()
+    J.add_edges_from(
+        [
+            (("C", "E"), ("C",)),
+            (("C",), ("A", "B", "C")),
+            (("A", "B", "C"), ("C",)),
+            (("C",), ("C", "D")),
+        ]
+    )
+
+    assert nx.is_isomorphic(G, J)
+
+
+def test_junction_tree_directed_unconnected_nodes():
+    B = nx.DiGraph()
+    B.add_nodes_from([("A", "B", "C", "D")])
+    G = junction_tree(B)
+
+    J = nx.Graph()
+    J.add_nodes_from([("A", "B", "C", "D")])
+
+    assert nx.is_isomorphic(G, J)
+
+
+def test_junction_tree_directed_cascade():
+    B = nx.DiGraph()
+    B.add_edges_from([("A", "B"), ("B", "C"), ("C", "D")])
+    G = junction_tree(B)
+
+    J = nx.Graph()
+    J.add_edges_from(
+        [
+            (("A", "B"), ("B",)),
+            (("B",), ("B", "C")),
+            (("B", "C"), ("C",)),
+            (("C",), ("C", "D")),
+        ]
+    )
+    assert nx.is_isomorphic(G, J)
+
+
+def test_junction_tree_directed_unconnected_edges():
+    B = nx.DiGraph()
+    B.add_edges_from([("A", "B"), ("C", "D"), ("E", "F")])
+    G = junction_tree(B)
+
+    J = nx.Graph()
+    J.add_nodes_from([("A", "B"), ("C", "D"), ("E", "F")])
+
+    assert nx.is_isomorphic(G, J)
+
+
+def test_junction_tree_undirected():
+    B = nx.Graph()
+    B.add_edges_from([("A", "C"), ("A", "D"), ("B", "C"), ("C", "E")])
+    G = junction_tree(B)
+
+    J = nx.Graph()
+    J.add_edges_from(
+        [
+            (("A", "D"), ("A",)),
+            (("A",), ("A", "C")),
+            (("A", "C"), ("C",)),
+            (("C",), ("B", "C")),
+            (("B", "C"), ("C",)),
+            (("C",), ("C", "E")),
+        ]
+    )
+
+    assert nx.is_isomorphic(G, J)