< Summary - Combined Code Coverage

Information
Class: NLightning.Domain.Protocol.Tlv.BaseTlv
Assembly: NLightning.Domain
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Domain/Protocol/Tlv/BaseTlv.cs
Tag: 30_15166811759
Line coverage
82%
Covered lines: 14
Uncovered lines: 3
Coverable lines: 17
Total lines: 77
Line coverage: 82.3%
Branch coverage
50%
Covered branches: 3
Total branches: 6
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Type()100%11100%
get_Length()100%11100%
get_Value()100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
GetHashCode()100%210%
Equals(...)50%22100%
Equals(...)50%44100%
op_Equality(...)100%210%
op_Inequality(...)100%210%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Domain/Protocol/Tlv/BaseTlv.cs

#LineLine coverage
 1namespace NLightning.Domain.Protocol.Tlv;
 2
 3using ValueObjects;
 4
 5public class BaseTlv
 6{
 7    /// <summary>
 8    /// The type of the TLV
 9    /// </summary>
 72810    public BigSize Type { get; }
 11
 12    /// <summary>
 13    /// The length of the value
 14    /// </summary>
 110815    public BigSize Length { get; protected init; }
 16
 17    /// <summary>
 18    /// The value
 19    /// </summary>
 131220    public byte[] Value { get; internal set; }
 21
 44822    public BaseTlv(BigSize type, BigSize length, byte[] value)
 23    {
 44824        Type = type;
 44825        Length = length;
 44826        Value = value;
 44827    }
 28
 29    /// <summary>
 30    /// Create a new TLV
 31    /// </summary>
 32    /// <param name="type">The type of the TLV</param>
 33    /// <param name="value">The value of the TLV</param>
 34    /// <remarks>
 35    /// The length of the value is automatically calculated
 36    /// </remarks>
 37237    public BaseTlv(BigSize type, byte[] value) : this(type, value.Length, value)
 37238    { }
 39
 40    /// <summary>
 41    /// Create a new TLV
 42    /// </summary>
 43    /// <param name="type">The type of the TLV</param>
 44    /// <remarks>
 45    /// Used internally to create a TLV with a length of 0 and an empty value.
 46    /// </remarks>
 29247    internal BaseTlv(BigSize type) : this(type, [])
 29248    { }
 49
 50    /// <inheritdoc />
 51    public override int GetHashCode()
 52    {
 53        // ReSharper disable once NonReadonlyMemberInGetHashCode
 054        return HashCode.Combine(Type, Length, Value.GetHashCode());
 55    }
 56
 57    /// <inheritdoc />
 58    public override bool Equals(object? obj)
 59    {
 10060        return obj is BaseTlv tlv && Equals(tlv);
 61    }
 62
 63    private bool Equals(BaseTlv other)
 64    {
 10065        return Type.Equals(other.Type) && Length.Equals(other.Length) && Value.SequenceEqual(other.Value);
 66    }
 67
 68    public static bool operator ==(BaseTlv left, BaseTlv right)
 69    {
 070        return left.Equals(right);
 71    }
 72
 73    public static bool operator !=(BaseTlv left, BaseTlv right)
 74    {
 075        return !(left == right);
 76    }
 77}