< Summary

Class:Itinero.Profiles.Profile
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Profiles/Profile.cs
Covered lines:2
Uncovered lines:11
Coverable lines:13
Total lines:81
Line coverage:15.3% (2 of 13)
Covered branches:0
Total branches:2
Branch coverage:0% (0 of 2)
Tag:284_38118444584

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_TurnCostFactorEnabled()100%1100%
get_MinFactor()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>
 6238    public virtual bool TurnCostFactorEnabled => false;
 39
 40    /// <summary>
 41    /// A lower bound on the factor returned for any traversable edge, used by
 42    /// goal-directed search: bound × straight-line distance is a cost no route can
 43    /// undercut. Too high a value silently returns worse routes, so 0 (the default)
 44    /// means no bound declared and no goal-direction.
 45    /// </summary>
 1164746    public virtual uint MinFactor => 0;
 47
 48    /// <summary>
 49    /// Gets a stable hashcode, this hashcode doesn't change between runs.
 50    /// </summary>
 51    /// <remarks>
 52    /// This uses the name property by default, if using profiles with unique names this default implementation is fine.
 53    /// </remarks>
 54    /// <returns>The stable hash code.</returns>
 55    public override int GetHashCode()
 056    {
 57        // TODO: a slow hash, this can be better.
 58        // on the other hand this hash should only be computed once when the profile is added to a router db.
 059        var hash = Hasher.ComputeHash(System.Text.Encoding.Default.GetBytes(this.Name));
 060        return BitConverter.ToInt32(hash, 0);
 061    }
 62
 63    /// <summary>
 64    /// Compares this profiles to the given profile. Returns true if the profiles are identical functionally.
 65    /// </summary>
 66    /// <remarks>
 67    /// This uses the name property by default, if using profiles with unique names this default implementation is fine.
 68    /// </remarks>
 69    /// <returns>True if the profiles have the same name.</returns>
 70    public override bool Equals(object obj)
 071    {
 072        if (obj is Profile profile)
 073        {
 074            return profile.Name.Equals(this.Name);
 75        }
 76
 077        return false;
 078    }
 79
 080    private static readonly MD5 Hasher = MD5.Create();
 81}