dyng.testing.strategies#
Hypothesis strategies for random graphs, hypergraphs and their batches (needs the
hypothesis package). Every strategy shrinks: a failing case is reduced to a small graph or
hypergraph and short batches.
Example
>>> from hypothesis import given
>>> from dyng.testing import strategies as dst
>>> @given(dst.graphs())
... def test_builds(g):
... assert g.to_graph().num_vertices == g.num_vertices
A hypergraph’s batches name its current ids, which depend on the ids earlier batches got, so
hyperedge_batches() draws from the state of a HypergraphModel
(use st.data() and draw one batch per step):
@given(dst.hypergraphs(), st.data())
def test_ids(h, data):
hg, model = h.to_hypergraph(), h.model()
for _ in range(3):
b = data.draw(dst.hyperedge_batches(model))
s = hg.apply(b.to_batch())
model.apply(b.delete_hyperedges, b.insert_hyperedges, b.insert_weights,
s.inserted_ids)
Classes#
A drawn batch: deletions (existing or missing edges) and insertions (new edges, existing |
|
A drawn edge list (with repeated pairs and self-loops unless excluded). |
|
A drawn hyperedge batch: deletions (live, dead, repeated or out-of-range ids) and |
|
A drawn hypergraph: member lists (with repeated members unless excluded) and weights. |
Functions#
|
Random batches for |
|
Random directed graphs with integer weights in [1, max_weight] (or none). |
|
Random batches for the current state of |
|
Random hypergraphs: up to |
Module Contents#
- class dyng.testing.strategies.RandomBatch#
A drawn batch: deletions (existing or missing edges) and insertions (new edges, existing ones, and edges naming new vertices when growth is allowed).
- apply_to(model: dyng.testing.oracles.GraphModel) None#
Apply the batch to a model (default semantics).
- to_batch() dyng.batch.EdgeBatch#
The dynG batch.
- class dyng.testing.strategies.RandomGraph#
A drawn edge list (with repeated pairs and self-loops unless excluded).
- model() dyng.testing.oracles.GraphModel#
The pure-Python model of the graph.
- to_graph(**kwargs: object) dyng.graph.Graph#
The dynG graph (
Graph.from_edgeswithkwargs).
- class dyng.testing.strategies.RandomHyperedgeBatch#
A drawn hyperedge batch: deletions (live, dead, repeated or out-of-range ids) and insertions (member lists, with repeated members unless excluded).
- to_batch() dyng.hypergraph.HyperedgeBatch#
The dynG batch.
- class dyng.testing.strategies.RandomHypergraph#
A drawn hypergraph: member lists (with repeated members unless excluded) and weights.
- model(reuse: str = 'erase_first') dyng.testing.oracles.HypergraphModel#
The pure-Python model of the hypergraph (under the
id_reuseorderreuse).
- to_hypergraph(**kwargs: object) dyng.hypergraph.Hypergraph#
The dynG hypergraph (
Hypergraph.from_listswithkwargs).
- dyng.testing.strategies.batches(graph: RandomGraph, *, max_insertions: int = 8, max_deletions: int = 8, weighted: bool = True, max_weight: int = 20, grow: bool = True, self_loops: bool = True) RandomBatch#
Random batches for
graph: deletions of existing or missing edges, insertions of new or existing edges and (withgrow) of edges naming up to two new vertices.
- dyng.testing.strategies.graphs(*, min_vertices: int = 1, max_vertices: int = 10, max_edges: int = 30, weighted: bool = True, max_weight: int = 20, self_loops: bool = True) RandomGraph#
Random directed graphs with integer weights in [1, max_weight] (or none).
- dyng.testing.strategies.hyperedge_batches(model: dyng.testing.oracles.HypergraphModel, *, max_insertions: int = 6, max_deletions: int = 6, max_cardinality: int = 5, weighted: bool | None = None, max_weight: int = 20, repeated_members: bool = True, skipped_deletions: bool = True) RandomHyperedgeBatch#
Random batches for the current state of
model: deletions of live ids (and, withskipped_deletions, of dead, repeated and out-of-range ids, whichapply()skips and counts) and insertions of member lists over the model’s vertices.weighteddefaults to whether the model has weights.
- dyng.testing.strategies.hypergraphs(*, min_vertices: int = 1, max_vertices: int = 12, max_hyperedges: int = 20, max_cardinality: int = 5, weighted: bool = False, max_weight: int = 20, repeated_members: bool = True) RandomHypergraph#
Random hypergraphs: up to
max_hyperedgesnon-empty member lists overnvertices (parallel hyperedges allowed; repeated members unlessrepeated_members=False), with integer weights in [1, max_weight] whenweighted.