DAG test org
This commit is contained in:
@@ -18,6 +18,7 @@ class TestDAGInit:
|
||||
assert g.on_remove is None
|
||||
|
||||
|
||||
class TestDAGOps:
|
||||
class TestDAGAddEdge:
|
||||
"""Test adding edges."""
|
||||
|
||||
@@ -53,7 +54,6 @@ class TestDAGAddEdge:
|
||||
g.add_edge("a", "b")
|
||||
assert len(g["a"]) == 1
|
||||
|
||||
|
||||
class TestDAGRemoveEdge:
|
||||
"""Test removing edges."""
|
||||
|
||||
@@ -73,7 +73,6 @@ class TestDAGRemoveEdge:
|
||||
with pytest.raises(KeyError):
|
||||
g.remove_edge("a", "b", missing_ok=False)
|
||||
|
||||
|
||||
class TestDAGDiscardNode:
|
||||
"""Test node removal."""
|
||||
|
||||
@@ -100,7 +99,39 @@ class TestDAGDiscardNode:
|
||||
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."""
|
||||
|
||||
def test_getitem_returns_dagset(self) -> None:
|
||||
@@ -127,66 +158,31 @@ class TestDAGGetItem:
|
||||
g["a"].add("b")
|
||||
assert ("a", "b") in added
|
||||
|
||||
|
||||
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."""
|
||||
|
||||
def test_delitem_removes_node(self) -> None:
|
||||
def test_removes_node(self) -> None:
|
||||
g = DAG[str]()
|
||||
g.add_edge("a", "b")
|
||||
del g["a"]
|
||||
assert "a" not in g._succ
|
||||
|
||||
|
||||
class TestDAGIter:
|
||||
class TestDAGIterOps:
|
||||
class TestIter:
|
||||
"""Test iteration."""
|
||||
|
||||
def test_iter_empty(self) -> None:
|
||||
def test_empty(self) -> None:
|
||||
g = DAG[str]()
|
||||
assert list(g) == []
|
||||
|
||||
def test_iter_returns_nodes(self) -> None:
|
||||
def test_returns_nodes(self) -> None:
|
||||
g = DAG[str]()
|
||||
g.add_edge("a", "b")
|
||||
g.add_edge("b", "c")
|
||||
nodes = set(g)
|
||||
assert "a" in nodes
|
||||
assert "b" in nodes
|
||||
assert {"a", "b"} == set(g)
|
||||
|
||||
|
||||
class TestDAGLen:
|
||||
class TestLen:
|
||||
"""Test length (edge count)."""
|
||||
|
||||
def test_len_empty(self) -> None:
|
||||
@@ -252,24 +248,6 @@ class TestDAGCallbacks:
|
||||
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:
|
||||
"""Test complex usage patterns."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user