< Summary

Class:Itinero.Profiles.Profile
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Profiles/Profile.cs
Covered lines:1
Uncovered lines:11
Coverable lines:12
Total lines:73
Line coverage:8.3% (1 of 12)
Covered branches:0
Total branches:2
Branch coverage:0% (0 of 2)
Tag:251_23667616543

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_TurnCostFactorEnabled()100%1100%
GetHashCode()100%10%
Equals(...)0%20%
.cctor()100%10%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Profiles/Profile.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Security.Cryptography;
 4
 5namespace Itinero.Profiles;
 6
 7/// <summary>
 8/// Abstract representation of a profile.
 9/// </summary>
 10/// <remarks>
 11/// This is a single possible behaviour of a vehicle (e.g. 'bicycle.fastest').
 12/// </remarks>
 13public abstract class Profile
 14{
 15    /// <summary>
 16    /// Gets the name of this profile.
 17    /// </summary>
 18    public abstract string Name { get; }
 19
 20    /// <summary>
 21    /// Gets the edge factor for the given attributes.
 22    /// </summary>
 23    /// <param name="attributes">The attributes.</param>
 24    /// <returns>An edge factor.</returns>
 25    public abstract EdgeFactor Factor(IEnumerable<(string key, string value)> attributes);
 26
 27    /// <summary>
 28    /// Gets a factor for the turn costs for the given attributes.
 29    /// </summary>
 30    /// <param name="attributes">The attributes.</param>
 31    /// <returns>A turn cost factor.</returns>
 32    public abstract TurnCostFactor TurnCostFactor(IEnumerable<(string key, string value)> attributes);
 33
 34    /// <summary>
 35    /// Gets whether turn cost factors are enabled for this profile.
 36    /// When true, edge-based routing is used to properly handle turn restrictions.
 37    /// </summary>
 5738    public virtual bool TurnCostFactorEnabled => false;
 39
 40    /// <summary>
 41    /// Gets a stable hashcode, this hashcode doesn't change between runs.
 42    /// </summary>
 43    /// <remarks>
 44    /// This uses the name property by default, if using profiles with unique names this default implementation is fine.
 45    /// </remarks>
 46    /// <returns>The stable hash code.</returns>
 47    public override int GetHashCode()
 048    {
 49        // TODO: a slow hash, this can be better.
 50        // on the other hand this hash should only be computed once when the profile is added to a router db.
 051        var hash = Hasher.ComputeHash(System.Text.Encoding.Default.GetBytes(this.Name));
 052        return BitConverter.ToInt32(hash, 0);
 053    }
 54
 55    /// <summary>
 56    /// Compares this profiles to the given profile. Returns true if the profiles are identical functionally.
 57    /// </summary>
 58    /// <remarks>
 59    /// This uses the name property by default, if using profiles with unique names this default implementation is fine.
 60    /// </remarks>
 61    /// <returns>True if the profiles have the same name.</returns>
 62    public override bool Equals(object obj)
 063    {
 064        if (obj is Profile profile)
 065        {
 066            return profile.Name.Equals(this.Name);
 67        }
 68
 069        return false;
 070    }
 71
 072    private static readonly MD5 Hasher = MD5.Create();
 73}