< Summary

Information
Class: Trailblazer.Pathing.TraversalIntent
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Traversal/TraversalIntent.cs
Line coverage
100%
Covered lines: 32
Uncovered lines: 0
Coverable lines: 32
Total lines: 91
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%22100%
Equals(...)100%22100%
Equals(...)100%22100%
GetHashCode()100%11100%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%
Validate(...)100%11100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Traversal/TraversalIntent.cs

#LineLine coverage
 1//=======================================================================
 2// TraversalIntent.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2024-present David Oravsky (mrdav30)
 5// See LICENSE file in the project root for full license information.
 6//=======================================================================
 7
 8using System;
 9using SwiftCollections.Utility;
 10
 11namespace Trailblazer.Pathing;
 12
 13/// <summary>
 14/// Defines the exact starting medium and allowed target media for a path query.
 15/// </summary>
 16public readonly struct TraversalIntent : IEquatable<TraversalIntent>
 17{
 18    /// <summary>
 19    /// Gets the exact traversal medium at the query start.
 20    /// </summary>
 21    public TraversalMedium StartMedium { get; }
 22
 23    /// <summary>
 24    /// Gets the nonempty set of known traversal media allowed at the target.
 25    /// </summary>
 26    public TraversalMedia TargetMedia { get; }
 27
 28    /// <summary>
 29    /// Creates immutable traversal intent.
 30    /// </summary>
 31    /// <exception cref="ArgumentException">Thrown when target media are empty or contain an unknown bit.</exception>
 32    /// <exception cref="ArgumentOutOfRangeException">Thrown when the start medium is unknown.</exception>
 33    public TraversalIntent(
 34        TraversalMedium startMedium,
 35        TraversalMedia targetMedia)
 36    {
 119837        SwiftThrowHelper.ThrowIfArgumentOutOfRange(
 119838            !TraversalTransitionDefinition.IsKnownMedium(startMedium),
 119839            (int)startMedium,
 119840            nameof(startMedium),
 119841            "Start medium must identify one known traversal medium.");
 119642        SwiftThrowHelper.ThrowIfArgument(
 119643            targetMedia == TraversalMedia.None
 119644                || (targetMedia & ~NavigationCell.KnownMedia) != 0,
 119645            nameof(targetMedia),
 119646            "Target media must contain at least one known traversal-medium bit.");
 47
 119448        StartMedium = startMedium;
 119449        TargetMedia = targetMedia;
 119450    }
 51
 52    /// <inheritdoc/>
 53    public bool Equals(TraversalIntent other) =>
 270554        StartMedium == other.StartMedium
 270555        && TargetMedia == other.TargetMedia;
 56
 57    /// <inheritdoc/>
 20658    public override bool Equals(object? obj) => obj is TraversalIntent other && Equals(other);
 59
 60    /// <inheritdoc/>
 61    public override int GetHashCode()
 62    {
 337263        return SwiftHashTools.CombineHashCodes((int)StartMedium, (int)TargetMedia);
 64    }
 65
 66    /// <summary>
 67    /// Returns whether two traversal intents have exactly equal values.
 68    /// </summary>
 249869    public static bool operator ==(TraversalIntent left, TraversalIntent right) => left.Equals(right);
 70
 71    /// <summary>
 72    /// Returns whether two traversal intents differ.
 73    /// </summary>
 174    public static bool operator !=(TraversalIntent left, TraversalIntent right) => !left.Equals(right);
 75
 76    internal void Validate(string parameterName)
 77    {
 203078        SwiftThrowHelper.ThrowIfArgument(
 203079            !TraversalTransitionDefinition.IsKnownMedium(StartMedium),
 203080            parameterName,
 203081            "Traversal intent must contain an exact known start medium and nonempty known target media.");
 203082        SwiftThrowHelper.ThrowIfArgument(
 203083            TargetMedia == TraversalMedia.None,
 203084            parameterName,
 203085            "Traversal intent must contain an exact known start medium and nonempty known target media.");
 203086        SwiftThrowHelper.ThrowIfArgument(
 203087            (TargetMedia & ~NavigationCell.KnownMedia) != 0,
 203088            parameterName,
 203089            "Traversal intent must contain an exact known start medium and nonempty known target media.");
 203090    }
 91}