< Summary

Class:Itinero.Network.Tiles.Standalone.Global.GlobalRestriction
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Network/Tiles/Standalone/Global/GlobalRestriction.cs
Covered lines:12
Uncovered lines:6
Coverable lines:18
Total lines:67
Line coverage:66.6% (12 of 18)
Covered branches:1
Total branches:2
Branch coverage:50% (1 of 2)
Tag:263_26948838820

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)50%2100%
get_IsProhibitory()100%1100%
get_Attributes()100%1100%
GetEnumerator()100%10%
System.Collections.IEnumerable.GetEnumerator()100%10%
get_Count()100%1100%
get_Item(...)100%1100%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Network/Tiles/Standalone/Global/GlobalRestriction.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using System.Linq;
 5
 6namespace Itinero.Network.Tiles.Standalone.Global;
 7
 8/// <summary>
 9/// A global restriction.
 10///
 11/// This contains:
 12/// - The sequence of edges that incurs the cost.
 13/// - A prohibitory flag:
 14///   - true : only this specific turn with the prefix edges is forbidden,
 15///   - false: only this turn is allowed, all other turns at the vertex are forbidden.
 16///
 17/// Assumptions:
 18/// - The restriction occurs at the vertex between the last two edges in the sequence.
 19/// </summary>
 20/// <remarks>
 21/// Why model restrictions like this:
 22/// We do not know the full structure of the network at the time this is defined only the part within the tile.
 23/// </remarks>
 24public class GlobalRestriction : IReadOnlyList<GlobalEdgeId>
 25{
 26    private readonly IReadOnlyList<GlobalEdgeId> _edges;
 27
 28    /// <summary>
 29    /// Creates a new network restriction.
 30    /// </summary>
 31    /// <param name="sequence">The sequence that is either prohibited or mandatory.</param>
 32    /// <param name="isProhibitory">Flag to set the restriction to prohibited or mandatory.</param>
 33    /// <param name="attributes">The attributes.</param>
 482934    public GlobalRestriction(IEnumerable<GlobalEdgeId> sequence, bool isProhibitory,
 482935        IEnumerable<(string key, string value)> attributes)
 482936    {
 482937        _edges = sequence.ToList();
 482938        if (_edges.Count < 2) throw new ArgumentException("A restriction has to have at least 2 edges");
 39
 482940        this.IsProhibitory = isProhibitory;
 482941        this.Attributes = attributes;
 482942    }
 43
 44    /// <summary>
 45    /// Returns true if the restriction is negative.
 46    /// </summary>
 480847    public bool IsProhibitory { get; }
 48
 49    /// <summary>
 50    /// The attributes associated with the restriction.
 51    /// </summary>
 480652    public IEnumerable<(string key, string value)> Attributes { get; }
 53
 54    public IEnumerator<GlobalEdgeId> GetEnumerator()
 055    {
 056        return _edges.GetEnumerator();
 057    }
 58
 59    IEnumerator IEnumerable.GetEnumerator()
 060    {
 061        return ((IEnumerable)_edges).GetEnumerator();
 062    }
 63
 1450664    public int Count => _edges.Count;
 65
 971466    public GlobalEdgeId this[int index] => _edges[index];
 67}