< Summary

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

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
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 a stable hashcode, this hashcode doesn't change between runs.
 36    /// </summary>
 37    /// <remarks>
 38    /// This uses the name property by default, if using profiles with unique names this default implementation is fine.
 39    /// </remarks>
 40    /// <returns>The stable hash code.</returns>
 41    public override int GetHashCode()
 042    {
 43        // TODO: a slow hash, this can be better.
 44        // on the other hand this hash should only be computed once when the profile is added to a router db.
 045        var hash = Hasher.ComputeHash(System.Text.Encoding.Default.GetBytes(this.Name));
 046        return BitConverter.ToInt32(hash, 0);
 047    }
 48
 49    /// <summary>
 50    /// Compares this profiles to the given profile. Returns true if the profiles are identical functionally.
 51    /// </summary>
 52    /// <remarks>
 53    /// This uses the name property by default, if using profiles with unique names this default implementation is fine.
 54    /// </remarks>
 55    /// <returns>True if the profiles have the same name.</returns>
 56    public override bool Equals(object obj)
 057    {
 058        if (obj is Profile profile)
 059        {
 060            return profile.Name.Equals(this.Name);
 61        }
 62
 063        return false;
 064    }
 65
 066    private static readonly MD5 Hasher = MD5.Create();
 67}

Methods/Properties

GetHashCode()
Equals(...)
.cctor()