DAG test org
This commit is contained in:
@@ -18,7 +18,8 @@ class TestDAGInit:
|
|||||||
assert g.on_remove is None
|
assert g.on_remove is None
|
||||||
|
|
||||||
|
|
||||||
class TestDAGAddEdge:
|
class TestDAGOps:
|
||||||
|
class TestDAGAddEdge:
|
||||||
"""Test adding edges."""
|
"""Test adding edges."""
|
||||||
|
|
||||||
def test_add_single_edge(self) -> None:
|
def test_add_single_edge(self) -> None:
|
||||||
@@ -53,8 +54,7 @@ class TestDAGAddEdge:
|
|||||||
g.add_edge("a", "b")
|
g.add_edge("a", "b")
|
||||||
assert len(g["a"]) == 1
|
assert len(g["a"]) == 1
|
||||||
|
|
||||||
|
class TestDAGRemoveEdge:
|
||||||
class TestDAGRemoveEdge:
|
|
||||||
"""Test removing edges."""
|
"""Test removing edges."""
|
||||||
|
|
||||||
def test_remove_existing_edge(self) -> None:
|
def test_remove_existing_edge(self) -> None:
|
||||||
@@ -73,8 +73,7 @@ class TestDAGRemoveEdge:
|
|||||||
with pytest.raises(KeyError):
|
with pytest.raises(KeyError):
|
||||||
g.remove_edge("a", "b", missing_ok=False)
|
g.remove_edge("a", "b", missing_ok=False)
|
||||||
|
|
||||||
|
class TestDAGDiscardNode:
|
||||||
class TestDAGDiscardNode:
|
|
||||||
"""Test node removal."""
|
"""Test node removal."""
|
||||||
|
|
||||||
def test_discard_node_removes_outgoing_edges(self) -> None:
|
def test_discard_node_removes_outgoing_edges(self) -> None:
|
||||||
@@ -100,7 +99,39 @@ class TestDAGDiscardNode:
|
|||||||
g.discard_node("z") # should not raise
|
g.discard_node("z") # should not raise
|
||||||
|
|
||||||
|
|
||||||
class TestDAGGetItem:
|
class TestDAGBasicOps:
|
||||||
|
class TestSetItem:
|
||||||
|
"""Test dictionary-style assignment."""
|
||||||
|
|
||||||
|
def test_with_set(self) -> None:
|
||||||
|
g = DAG[str]()
|
||||||
|
g["a"] = {"b", "c"}
|
||||||
|
assert "b" in g["a"]
|
||||||
|
assert "c" in g["a"]
|
||||||
|
|
||||||
|
def test_with_list(self) -> None:
|
||||||
|
g = DAG[str]()
|
||||||
|
g["a"] = ["b", "c"]
|
||||||
|
assert "b" in g["a"]
|
||||||
|
assert "c" in g["a"]
|
||||||
|
|
||||||
|
def test_with_string(self) -> None:
|
||||||
|
g = DAG[str]()
|
||||||
|
g["a"] = "b"
|
||||||
|
assert "b" in g["a"]
|
||||||
|
|
||||||
|
def test_with_single_item(self) -> None:
|
||||||
|
g = DAG[int]()
|
||||||
|
g[1] = 2
|
||||||
|
assert 2 in g[1]
|
||||||
|
|
||||||
|
def test_updates_reverse(self) -> None:
|
||||||
|
g = DAG[str]()
|
||||||
|
g["a"] = {"b", "c"}
|
||||||
|
assert "a" in g.reverse["b"]
|
||||||
|
assert "a" in g.reverse["c"]
|
||||||
|
|
||||||
|
class TestGetItem:
|
||||||
"""Test dictionary-style access."""
|
"""Test dictionary-style access."""
|
||||||
|
|
||||||
def test_getitem_returns_dagset(self) -> None:
|
def test_getitem_returns_dagset(self) -> None:
|
||||||
@@ -127,66 +158,31 @@ class TestDAGGetItem:
|
|||||||
g["a"].add("b")
|
g["a"].add("b")
|
||||||
assert ("a", "b") in added
|
assert ("a", "b") in added
|
||||||
|
|
||||||
|
class TestDAGDelItem:
|
||||||
class TestDAGSetItem:
|
|
||||||
"""Test dictionary-style assignment."""
|
|
||||||
|
|
||||||
def test_setitem_with_set(self) -> None:
|
|
||||||
g = DAG[str]()
|
|
||||||
g["a"] = {"b", "c"}
|
|
||||||
assert "b" in g["a"]
|
|
||||||
assert "c" in g["a"]
|
|
||||||
|
|
||||||
def test_setitem_with_list(self) -> None:
|
|
||||||
g = DAG[str]()
|
|
||||||
g["a"] = ["b", "c"]
|
|
||||||
assert "b" in g["a"]
|
|
||||||
assert "c" in g["a"]
|
|
||||||
|
|
||||||
def test_setitem_with_string(self) -> None:
|
|
||||||
g = DAG[str]()
|
|
||||||
g["a"] = "b"
|
|
||||||
assert "b" in g["a"]
|
|
||||||
|
|
||||||
def test_setitem_with_single_item(self) -> None:
|
|
||||||
g = DAG[int]()
|
|
||||||
g[1] = 2
|
|
||||||
assert 2 in g[1]
|
|
||||||
|
|
||||||
def test_setitem_updates_reverse(self) -> None:
|
|
||||||
g = DAG[str]()
|
|
||||||
g["a"] = {"b", "c"}
|
|
||||||
assert "a" in g.reverse["b"]
|
|
||||||
assert "a" in g.reverse["c"]
|
|
||||||
|
|
||||||
|
|
||||||
class TestDAGDelItem:
|
|
||||||
"""Test del operation."""
|
"""Test del operation."""
|
||||||
|
|
||||||
def test_delitem_removes_node(self) -> None:
|
def test_removes_node(self) -> None:
|
||||||
g = DAG[str]()
|
g = DAG[str]()
|
||||||
g.add_edge("a", "b")
|
g.add_edge("a", "b")
|
||||||
del g["a"]
|
del g["a"]
|
||||||
assert "a" not in g._succ
|
assert "a" not in g._succ
|
||||||
|
|
||||||
|
|
||||||
class TestDAGIter:
|
class TestDAGIterOps:
|
||||||
|
class TestIter:
|
||||||
"""Test iteration."""
|
"""Test iteration."""
|
||||||
|
|
||||||
def test_iter_empty(self) -> None:
|
def test_empty(self) -> None:
|
||||||
g = DAG[str]()
|
g = DAG[str]()
|
||||||
assert list(g) == []
|
assert list(g) == []
|
||||||
|
|
||||||
def test_iter_returns_nodes(self) -> None:
|
def test_returns_nodes(self) -> None:
|
||||||
g = DAG[str]()
|
g = DAG[str]()
|
||||||
g.add_edge("a", "b")
|
g.add_edge("a", "b")
|
||||||
g.add_edge("b", "c")
|
g.add_edge("b", "c")
|
||||||
nodes = set(g)
|
assert {"a", "b"} == set(g)
|
||||||
assert "a" in nodes
|
|
||||||
assert "b" in nodes
|
|
||||||
|
|
||||||
|
class TestLen:
|
||||||
class TestDAGLen:
|
|
||||||
"""Test length (edge count)."""
|
"""Test length (edge count)."""
|
||||||
|
|
||||||
def test_len_empty(self) -> None:
|
def test_len_empty(self) -> None:
|
||||||
@@ -252,24 +248,6 @@ class TestDAGCallbacks:
|
|||||||
assert ("a", "b") in removed
|
assert ("a", "b") in removed
|
||||||
|
|
||||||
|
|
||||||
class TestDAGRepr:
|
|
||||||
"""Test string representation."""
|
|
||||||
|
|
||||||
def test_repr_empty(self) -> None:
|
|
||||||
g = DAG[str]()
|
|
||||||
r = repr(g)
|
|
||||||
assert "DAG" in r
|
|
||||||
assert "{}" in r
|
|
||||||
|
|
||||||
def test_repr_with_edges(self) -> None:
|
|
||||||
g = DAG[str]()
|
|
||||||
g.add_edge("a", "b")
|
|
||||||
r = repr(g)
|
|
||||||
assert "DAG" in r
|
|
||||||
assert "a" in r
|
|
||||||
assert "b" in r
|
|
||||||
|
|
||||||
|
|
||||||
class TestDAGComplexScenarios:
|
class TestDAGComplexScenarios:
|
||||||
"""Test complex usage patterns."""
|
"""Test complex usage patterns."""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user