< Summary - Combined Code Coverage

Information
Class: NLightning.Domain.ValueObjects.ChainHash
Assembly: NLightning.Domain
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Domain/ValueObjects/ChainHash.cs
Tag: 30_15166811759
Line coverage
71%
Covered lines: 10
Uncovered lines: 4
Coverable lines: 14
Total lines: 73
Line coverage: 71.4%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
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%11100%
Equals(...)0%620%
GetHashCode()100%210%
op_Implicit(...)100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)100%11100%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Domain/ValueObjects/ChainHash.cs

#LineLine coverage
 1namespace NLightning.Domain.ValueObjects;
 2
 3using Interfaces;
 4
 5/// <summary>
 6/// Represents a chain hash.
 7/// </summary>
 8/// <remarks>
 9/// A chain hash is a 32-byte hash used to identify a chain.
 10/// </remarks>
 11public readonly struct ChainHash : IValueObject, IEquatable<ChainHash>
 12{
 13    /// <summary>
 14    /// The length of a chain hash.
 15    /// </summary>
 16    public const int LENGTH = 32;
 17
 18    private readonly byte[] _value;
 19
 20    /// <summary>
 21    /// Initializes a new instance of the <see cref="ChainHash"/> struct.
 22    /// </summary>
 23    /// <param name="value">The value of the chain hash.</param>
 24    /// <exception cref="ArgumentOutOfRangeException">Thrown when the value is not 32 bytes.</exception>
 25    public ChainHash(ReadOnlySpan<byte> value)
 26    {
 8427        if (value.Length != 32)
 28        {
 429            throw new ArgumentOutOfRangeException(nameof(value), "ChainHash must be 32 bytes");
 30        }
 31
 8032        _value = value.ToArray();
 8033    }
 34
 35    /// <summary>
 36    /// Compares two chain hashes for equality.
 37    /// </summary>
 38    /// <param name="other">The chain hash to compare to.</param>
 39    /// <returns>True if the chain hashes are equal, otherwise false.</returns>
 40    public bool Equals(ChainHash other)
 41    {
 6442        return _value.SequenceEqual(other._value);
 43    }
 44
 45    public override bool Equals(object? obj)
 46    {
 047        if (obj is ChainHash other)
 48        {
 049            return Equals(other);
 50        }
 51
 052        return false;
 53    }
 54
 55    public override int GetHashCode()
 56    {
 057        return BitConverter.ToInt32(_value, 0);
 58    }
 59
 7260    public static implicit operator byte[](ChainHash c) => c._value;
 1261    public static implicit operator ReadOnlyMemory<byte>(ChainHash c) => c._value;
 862    public static implicit operator ChainHash(byte[] value) => new(value);
 63
 64    public static bool operator ==(ChainHash left, ChainHash right)
 65    {
 1666        return left.Equals(right);
 67    }
 68
 69    public static bool operator !=(ChainHash left, ChainHash right)
 70    {
 871        return !(left == right);
 72    }
 73}