< Summary

Class:Itinero.IO.Osm.Restrictions.NetworkRestriction
Assembly:Itinero.IO.Osm
File(s):/home/runner/work/routing2/routing2/src/Itinero.IO.Osm/Restrictions/NetworkRestriction.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:224_14471318300

Metrics

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

File(s)

/home/runner/work/routing2/routing2/src/Itinero.IO.Osm/Restrictions/NetworkRestriction.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using System.Runtime.CompilerServices;
 5using Itinero.Network;
 6
 7[assembly: InternalsVisibleTo("Itinero.Tests")]
 8
 9namespace Itinero.IO.Osm.Restrictions;
 10
 11/// <summary>
 12/// A restriction on the network.
 13/// </summary>
 14/// <remarks>
 15/// A sequence of restricted edges that can either be prohibitive or obligatory. This can be used to represent the class
 16/// </remarks>
 17public class NetworkRestriction : IEnumerable<(EdgeId edge, bool forward)>
 18{
 19    private readonly List<(EdgeId edge, bool forward)> _sequence;
 20
 21    /// <summary>
 22    /// Creates a new network turn restriction.
 23    /// </summary>
 24    /// <param name="sequence">The sequence that is either prohibited or mandatory.</param>
 25    /// <param name="isProhibitory">Flag to set the restriction to prohibited or mandatory.</param>
 26    /// <param name="attributes">The attributes.</param>
 127    public NetworkRestriction(IEnumerable<(EdgeId edge, bool forward)> sequence, bool isProhibitory,
 128        IEnumerable<(string key, string value)> attributes)
 129    {
 130        _sequence = new List<(EdgeId edge, bool forward)>(sequence);
 131        if (_sequence.Count < 2) throw new ArgumentException("A restriction has to have at least 2 edges");
 32
 133        this.IsProhibitory = isProhibitory;
 134        this.Attributes = attributes;
 135    }
 36
 37    /// <summary>
 38    /// Gets the number of edges.
 39    /// </summary>
 440    public int Count => _sequence.Count;
 41
 42    /// <summary>
 43    /// Gets the edge at the given index.
 44    /// </summary>
 45    /// <param name="index">The index.</param>
 246    public (EdgeId edge, bool forward) this[int index] => _sequence[index];
 47
 48    /// <summary>
 49    /// Returns true if the restriction is negative.
 50    /// </summary>
 151    public bool IsProhibitory { get; }
 52
 53    /// <summary>
 54    /// The attributes associated with the restriction.
 55    /// </summary>
 156    public IEnumerable<(string key, string value)> Attributes { get; }
 57
 58    public IEnumerator<(EdgeId edge, bool forward)> GetEnumerator()
 059    {
 060        return _sequence.GetEnumerator();
 061    }
 62
 63    IEnumerator IEnumerable.GetEnumerator()
 064    {
 065        return this.GetEnumerator();
 066    }
 67}