< Summary

Information
Class: AmbientServices.Extensions.ArrayExtensions
Assembly: AmbientServices
File(s): /home/runner/work/AmbientServices/AmbientServices/AmbientServices/Extensions/ArrayExtensions.cs
Tag: 332_35464845198
Line coverage
100%
Covered lines: 3
Uncovered lines: 0
Coverable lines: 3
Total lines: 42
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ValueEquals<TYPE>(...)100%11100%
ValueHashCode<TYPE>(...)100%11100%

File(s)

/home/runner/work/AmbientServices/AmbientServices/AmbientServices/Extensions/ArrayExtensions.cs

#LineLine coverage
 1using AmbientServices.Utilities;
 2using System;
 3
 4namespace AmbientServices.Extensions;
 5
 6/// <summary>
 7/// A static class that extends <see cref="System.Array"/>.
 8/// </summary>
 9/// <remarks>
 10/// <pitch>Value semantics for arrays: compare two arrays by their contents and hash an array by its contents, for use i
 11/// <pledge>Equality is deep: element order is significant, and elements that are themselves arrays are compared by valu
 12/// </remarks>
 13public static class ArrayExtensions
 14{
 15    /// <summary>
 16    /// Compares two arrays of arbitrary type to see if the contents are the same.
 17    /// </summary>
 18    /// <typeparam name="TYPE">The type of item in the array.</typeparam>
 19    /// <param name="array1">The first array to compare.</param>
 20    /// <param name="array2">The second array to compare.</param>
 21    /// <returns><b>true</b> if the contents of the arrays are the same, <b>false</b> if the contents of the arrays are 
 22    public static bool ValueEquals<TYPE>(this TYPE[] array1, TYPE[] array2)
 23    {
 224        return ArrayUtilities.ValueEquals(typeof(TYPE), array1, array2);
 25    }
 26    /// <summary>
 27    /// Gets a hash code for the array based on the value of the array.
 28    /// </summary>
 29    /// <typeparam name="TYPE">The type of item in the array.</typeparam>
 30    /// <param name="array">The array to get the value hash code for.</param>
 31    /// <returns>A hash code based on the values in the array.</returns>
 32    public static int ValueHashCode<TYPE>(this TYPE[] array)
 33    {
 34#if NET5_0_OR_GREATER
 235        ArgumentNullException.ThrowIfNull(array);
 36#else
 37        if (array is null) throw new ArgumentNullException(nameof(array));
 38#endif
 39        // delegate to the shared engine so the hash recurses into nested arrays exactly where ValueEquals does (jagged 
 240        return ArrayUtilities.ValueHashCode(typeof(TYPE), array);
 41    }
 42}