< Summary

Class:Itinero.MapMatching.Model.GraphModel
Assembly:Itinero.MapMatching
File(s):/home/runner/work/routing2/routing2/src/Itinero.MapMatching/Model/GraphModel.cs
Covered lines:40
Uncovered lines:2
Coverable lines:42
Total lines:73
Line coverage:95.2% (40 of 42)
Covered branches:8
Total branches:10
Branch coverage:80% (8 of 10)
Tag:251_23667616543

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
get_Track()100%10%
get_Count()100%1100%
get_FirstNode()100%1100%
get_LastNode()100%1100%
AddNode(...)100%1100%
AddEdge(...)100%2100%
GetNode(...)100%1100%
GetNeighbours(...)100%2100%
GetEdge(...)66.66%687.5%

File(s)

/home/runner/work/routing2/routing2/src/Itinero.MapMatching/Model/GraphModel.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3
 4namespace Itinero.MapMatching.Model;
 5
 6public class GraphModel
 7{
 408    private readonly List<GraphNode> _nodes = new();
 409    private readonly Dictionary<int, List<GraphEdge>> _edges = new();
 10
 4011    public GraphModel(Track track)
 4012    {
 4013        this.Track = track;
 4014    }
 15
 016    public Track Track { get; }
 17
 8818    public int Count => _nodes.Count;
 19
 2826820    public int? FirstNode { get; private set; }
 21
 2324322    public int? LastNode { get; private set; }
 23
 24    public int AddNode(GraphNode node)
 1304525    {
 1304526        var id = _nodes.Count;
 1304527        _nodes.Add(node);
 28
 1304529        this.FirstNode = this.FirstNode ?? id;
 1304530        this.LastNode = id;
 1304531        return id;
 1304532    }
 33
 34    public void AddEdge(GraphEdge edge)
 12910935    {
 12910936        if (!_edges.TryGetValue(edge.Node1, out var edges))
 1116037        {
 1116038            edges = new List<GraphEdge>();
 1116039            _edges.Add(edge.Node1, edges);
 1116040        }
 12910941        edges.Add(edge);
 12910942    }
 43
 44    public GraphNode GetNode(int node)
 2766045    {
 2766046        return _nodes[node];
 2766047    }
 48
 49    public IEnumerable<GraphEdge> GetNeighbours(int node)
 1014250    {
 1014251        if (!_edges.TryGetValue(node, out var neighbours))
 17052        {
 17053            return ArraySegment<GraphEdge>.Empty;
 54        }
 55
 997256        return neighbours;
 1014257    }
 58
 59    /// <summary>
 60    /// Gets the edge between two specific nodes, or null if not found.
 61    /// </summary>
 62    public GraphEdge? GetEdge(int node1, int node2)
 203063    {
 203064        if (!_edges.TryGetValue(node1, out var edges)) return null;
 65
 1428466        foreach (var edge in edges)
 511267        {
 714268            if (edge.Node2 == node2) return edge;
 308269        }
 70
 071        return null;
 203072    }
 73}