< Summary

Information
Class: MoreStructures.Graphs.Visitor.DirectionableVisit
Assembly: MoreStructures
File(s): /home/runner/work/MoreStructures/MoreStructures/MoreStructures/Graphs/Visitor/DirectionableVisit.cs
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
Total lines: 92
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_DirectedGraph()100%1100%
.ctor(...)100%1100%
RaiseVisitingVertex(...)100%1100%
RaiseVisitedVertex(...)100%1100%
RaiseAlreadyVisitedVertex(...)100%1100%
DepthFirstSearchOfGraph()100%2100%
ConnectedComponents(...)100%2100%

File(s)

/home/runner/work/MoreStructures/MoreStructures/MoreStructures/Graphs/Visitor/DirectionableVisit.cs

#LineLine coverage
 1namespace MoreStructures.Graphs.Visitor;
 2
 3/// <summary>
 4/// A <see cref="IVisitStrategy"/> implementation which can perform the visit taking into account or not the
 5/// direction of the edges of the graph, based on the <see cref="DirectedGraph"/> property.
 6/// </summary>
 7public abstract class DirectionableVisit : IVisitStrategy
 8{
 9    /// <summary>
 10    /// Whether the provided <see cref="IGraph"/> should be considered as directed (i.e. edges should be
 11    /// traversed from start to end) or inderected (i.e. edges should be traversed both from start to end and from
 12    /// end to start).
 13    /// </summary>
 423714    public bool DirectedGraph { get; }
 15
 16    /// <summary>
 17    ///     <inheritdoc cref="DirectionableVisit"/>
 18    /// </summary>
 19    /// <param name="directedGraph">
 20    ///     <inheritdoc cref="DirectedGraph" path="/summary"/>
 21    /// </param>
 117122    protected DirectionableVisit(bool directedGraph)
 117123    {
 117124        DirectedGraph = directedGraph;
 117125    }
 26
 27    /// <inheritdoc/>
 964528    public event EventHandler<VisitEventArgs> VisitingVertex = delegate { };
 29
 30    /// <summary>
 31    /// Invoke the <see cref="VisitingVertex"/> event with the provided <paramref name="args"/>.
 32    /// </summary>
 33    /// <param name="args">The arguments to be provided, when raising the event.</param>
 423734    protected virtual void RaiseVisitingVertex(VisitEventArgs args) => VisitingVertex.Invoke(this, args);
 35
 36    /// <inheritdoc/>
 958737    public event EventHandler<VisitEventArgs> VisitedVertex = delegate { };
 38
 39    /// <summary>
 40    /// Invoke the <see cref="VisitedVertex"/> event with the provided <paramref name="args"/>.
 41    /// </summary>
 42    /// <param name="args">The arguments to be provided, when raising the event.</param>
 420843    protected virtual void RaiseVisitedVertex(VisitEventArgs args) => VisitedVertex.Invoke(this, args);
 44
 45    /// <inheritdoc/>
 488746    public event EventHandler<VisitEventArgs> AlreadyVisitedVertex = delegate { };
 47
 48    /// <summary>
 49    /// Invoke the <see cref="AlreadyVisitedVertex"/> event with the provided <paramref name="args"/>.
 50    /// </summary>
 51    /// <param name="args">The arguments to be provided, when raising the event.</param>
 185852    protected virtual void RaiseAlreadyVisitedVertex(VisitEventArgs args) => AlreadyVisitedVertex.Invoke(this, args);
 53
 54    /// <summary>
 55    /// Runs a Depth First Search and returns vertices and related connected components.
 56    /// </summary>
 57    /// <param name="graph">The <see cref="IGraph"/> instance to be explored.</param>
 58    /// <returns>
 59    /// A sequence of couples of <see cref="int"/>, the first being the vertex id and the second being the label of the
 60    /// connected component, the vertex belongs to.
 61    /// </returns>
 62    /// <remarks>
 63    /// Generalizes both <see cref="DepthFirstSearchOfGraph(IGraph)"/> and <see cref="ConnectedComponents(IGraph)"/>
 64    /// methods, which have very similar implementations. Check those two methods for further information.
 65    /// </remarks>
 66    protected abstract IEnumerable<(int, int)> DepthFirstSearchAndConnectedComponentsOfGraph(IGraph graph);
 67
 68    /// <inheritdoc/>
 69    public virtual IEnumerable<int> DepthFirstSearchOfGraph(IGraph graph)
 23270    {
 275271        foreach (var (vertex, _) in DepthFirstSearchAndConnectedComponentsOfGraph(graph))
 102872            yield return vertex;
 22573    }
 74
 75    /// <inheritdoc/>
 76    public virtual IDictionary<int, int> ConnectedComponents(IGraph graph)
 5677    {
 5678        var connectedComponents = new Dictionary<int, int>();
 45279        foreach (var (vertex, connectedComponent) in DepthFirstSearchAndConnectedComponentsOfGraph(graph))
 14280            connectedComponents[vertex] = connectedComponent;
 5681        return connectedComponents;
 5682    }
 83
 84    /// <inheritdoc/>
 85    public abstract IEnumerable<int> DepthFirstSearchFromVertex(IGraph graph, int vertex);
 86
 87    /// <inheritdoc/>
 88    public abstract IEnumerable<int> BreadthFirstSearchFromVertex(IGraph graph, int vertex);
 89
 90    /// <inheritdoc/>
 91    public abstract IEnumerable<int> BreadthFirstSearchFromVertices(IGraph graph, IEnumerable<int> vertices);
 92}