< Summary

Information
Class: MyNet.Primitives.Intervals.NumericInterval<T1, T2>
Assembly: MyNet.Primitives
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Intervals/NumericInterval.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 6
Uncovered lines: 0
Coverable lines: 6
Total lines: 44
Line coverage: 100%
Branch coverage
75%
Covered branches: 15
Total branches: 20
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Length()100%44100%
get_IsPositive()50%44100%
get_IsNegative()50%22100%
Clamp(...)75%88100%
Normalize(...)100%22100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Intervals/NumericInterval.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="NumericInterval.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Numerics;
 9
 10namespace MyNet.Primitives.Intervals;
 11
 12/// <summary>
 13/// Represents a numeric interval where the type of the values is a numeric type that implements the <see cref="INumber{
 14/// </summary>
 4215public abstract class NumericInterval<T, TSelf>(IntervalBoundary<T>? start, IntervalBoundary<T>? end) : Interval<T, TSel
 16    where T : struct, INumber<T>, IMinMaxValue<T>
 17    where TSelf : NumericInterval<T, TSelf>
 18{
 19    /// <summary>
 20    /// Gets the length of the interval, calculated as the difference between the end and start values. If either the st
 21    /// </summary>
 3322    public T? Length => !HasStart || !HasEnd ? null : End!.Value.Value - Start!.Value.Value;
 23
 24    /// <summary>
 25    /// Gets a value indicating whether the interval is positive, which is determined by checking if the length of the i
 26    /// </summary>
 627    public bool IsPositive => Length is null || Length > T.Zero;
 28
 29    /// <summary>
 30    /// Gets a value indicating whether the interval is negative, which is determined by checking if the length of the i
 31    /// </summary>
 632    public bool IsNegative => Length < T.Zero;
 33
 34    /// <summary>
 35    /// Clamps a value to the interval, ensuring that it falls within the defined boundaries. If the value is less than 
 36    /// </summary>
 937    public T Clamp(T value) => HasStart && value.CompareTo(Start!.Value.Value) < 0 ? Start.Value.Value : HasEnd && value
 38
 39    /// <summary>
 40    /// Normalizes a value within the interval, converting it to a value between 0 and 1 based on its position relative 
 41    /// </summary>
 642    public T Normalize(T value) => Length is null ? throw new InvalidOperationException("Cannot normalize unbounded inte
 43}
 44