< Summary - Code Coverage

Information
Class: Plainquire.Filter.Abstractions.RangeExtensions
Assembly: Plainquire.Filter.Abstractions
File(s): /home/runner/work/plainquire/plainquire/Plainquire.Filter/Plainquire.Filter.Abstractions/Extensions/RangeExtensions.cs
Tag: 64_13932151703
Line coverage
88%
Covered lines: 32
Uncovered lines: 4
Coverable lines: 36
Total lines: 118
Line coverage: 88.8%
Branch coverage
91%
Covered branches: 42
Total branches: 46
Branch coverage: 91.3%
Method coverage
100%
Covered methods: 6
Total methods: 6
Method coverage: 100%

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
Intersect(...)100%1212100%
Intersection(...)100%66100%
Union(...)100%44100%
Contains(...)100%1212100%
Min(...)66.66%6660%
Max(...)66.66%6660%

File(s)

/home/runner/work/plainquire/plainquire/Plainquire.Filter/Plainquire.Filter.Abstractions/Extensions/RangeExtensions.cs

#LineLine coverage
 1using System;
 2using System.Diagnostics.CodeAnalysis;
 3
 4namespace Plainquire.Filter.Abstractions;
 5
 6/// <summary>
 7/// Extension methods for <see cref="Range"/>.
 8/// </summary>
 9[SuppressMessage("ReSharper", "MemberCanBePrivate.Global", Justification = "Provided as library, can be used from outsid
 10public static class RangeExtensions
 11{
 12    /// <summary>
 13    /// Checks if two <see name="Range{TType}"/> intersects with each other.
 14    /// </summary>
 15    /// <param name="val1">The first of two <see name="Range{TType}"/> to compare.</param>
 16    /// <param name="val2">The second of two <see name="Range{TType}"/> to compare.</param>
 17    public static bool Intersect<TType>(this Range<TType>? val1, Range<TType>? val2)
 18        where TType : IComparable<TType>
 19    {
 3720        if (val1 == null || val2 == null)
 321            return false;
 22
 3423        var val1StartIsLowerOrEqualThanVal2End = val1.Start == null || val2.End == null || val1.Start.CompareTo(val2.End
 3424        var val2StartIsLowerOrEqualThanVal1End = val2.Start == null || val1.End == null || val2.Start.CompareTo(val1.End
 3425        return val1StartIsLowerOrEqualThanVal2End && val2StartIsLowerOrEqualThanVal1End;
 26    }
 27
 28    /// <summary>
 29    /// Returns the intersected range of two <see name="Range{TType}"/>.
 30    /// </summary>
 31    /// <param name="val1">The first of two <see name="Range{TType}"/> to compare.</param>
 32    /// <param name="val2">The second of two <see name="Range{TType}"/> to compare.</param>
 33    public static Range<TType>? Intersection<TType>(this Range<TType>? val1, Range<TType>? val2)
 34        where TType : IComparable<TType>
 35    {
 1136        if (val1 == null)
 237            return val2;
 38
 939        if (val2 == null)
 140            return val1;
 41
 842        if (!Intersect(val1, val2))
 243            return default;
 44
 645        var start = Max(val1.Start, val2.Start);
 646        var end = Min(val1.End, val2.End);
 647        return new Range<TType>(start, end);
 48    }
 49
 50    /// <summary>
 51    /// Returns the union range of two <see name="Range{TType}"/>.
 52    /// </summary>
 53    /// <param name="val1">The first of two <see name="Range{TType}"/> to compare.</param>
 54    /// <param name="val2">The second of two <see name="Range{TType}"/> to compare.</param>
 55    public static Range<TType>? Union<TType>(this Range<TType>? val1, Range<TType>? val2)
 56        where TType : IComparable<TType>
 57    {
 1158        if (val1 == null)
 259            return val2;
 60
 961        if (val2 == null)
 162            return val1;
 63
 864        var start = Min(val1.Start, val2.Start);
 865        var end = Max(val1.End, val2.End);
 866        return new Range<TType>(start, end);
 67    }
 68
 69    /// <summary>
 70    /// Checks if one <see name="Range{TType}"/> contains another.
 71    /// </summary>
 72    /// <param name="val1">The first of two <see name="Range{TType}"/> to compare.</param>
 73    /// <param name="val2">The second of two <see name="Range{TType}"/> to compare.</param>
 74    public static bool Contains<TType>(this Range<TType>? val1, Range<TType>? val2)
 75        where TType : IComparable<TType>
 76    {
 2477        if (val1 == null || val2 == null)
 378            return false;
 79
 2180        var val1StartIsLowerOrEqualThanVal2Start = val1.Start == null || (val2.Start != null && val1.Start.CompareTo(val
 2181        var val1EndIsGreaterOrEqualThanVal2End = val1.End == null || (val2.End != null && val1.End.CompareTo(val2.End) >
 2182        return val1StartIsLowerOrEqualThanVal2Start && val1EndIsGreaterOrEqualThanVal2End;
 83    }
 84
 85    /// <summary>
 86    /// Returns the lower of two <typeparamref name="TType"/>.
 87    /// </summary>
 88    /// <param name="val1">The first of two <typeparamref name="TType"/> to compare.</param>
 89    /// <param name="val2">The second of two <typeparamref name="TType"/> to compare.</param>
 90    public static TType? Min<TType>(TType? val1, TType? val2)
 91        where TType : IComparable<TType>
 92    {
 1493        if (val1 == null)
 094            return val1;
 95
 1496        if (val2 == null)
 097            return val2;
 98
 1499        return val1.CompareTo(val2) <= 0 ? val1 : val2;
 100    }
 101
 102    /// <summary>
 103    /// Returns the greater of two <typeparamref name="TType"/>.
 104    /// </summary>
 105    /// <param name="val1">The first of two <typeparamref name="TType"/> to compare.</param>
 106    /// <param name="val2">The second of two <typeparamref name="TType"/> to compare.</param>
 107    public static TType? Max<TType>(TType? val1, TType? val2)
 108        where TType : IComparable<TType>
 109    {
 14110        if (val1 == null)
 0111            return val2;
 112
 14113        if (val2 == null)
 0114            return val1;
 115
 14116        return val1.CompareTo(val2) >= 0 ? val1 : val2;
 117    }
 118}