< Summary

Class:GDX.ByteExtensions
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/ByteExtensions.cs
Covered lines:34
Uncovered lines:0
Coverable lines:34
Total lines:77
Line coverage:100% (34 of 34)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:2
Method coverage:100% (2 of 2)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetStableHashCode(...)0%220100%
IsSame(...)0%7.996061.9%

File(s)

./Packages/com.dotbunny.gdx/GDX/ByteExtensions.cs

#LineLine coverage
 1// Copyright (c) 2020-2024 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5namespace GDX
 6{
 7    /// <summary>
 8    ///     <see cref="byte" /> Based Extension Methods
 9    /// </summary>
 10    [VisualScriptingCompatible(2)]
 11    public static class ByteExtensions
 12    {
 13        /// <summary>
 14        ///     <para>Get the stable hash code of <paramref name="targetBytes" />, an array of <see cref="System.Byte" /
 15        /// </summary>
 16        /// <remarks>Does NOT get the object's hashcode.</remarks>
 17        /// <param name="targetBytes">The target array of <see cref="byte" />.</param>
 18        /// <returns>A <see cref="System.Int32" /> value.</returns>
 19        public static int GetStableHashCode(this byte[] targetBytes)
 120        {
 21            unchecked
 122            {
 23                const int k_P = 16777619;
 124                int hash = (int)2166136261;
 125                int length = targetBytes.Length;
 26
 2427                for (int i = 0; i < length; i++)
 1128                {
 1129                    hash = (hash ^ targetBytes[i]) * k_P;
 1130                }
 31
 132                hash += hash << 13;
 133                hash ^= hash >> 7;
 134                hash += hash << 3;
 135                hash ^= hash >> 17;
 136                hash += hash << 5;
 37
 138                return hash;
 39            }
 140        }
 41
 42        /// <summary>
 43        ///     Are the two provided <see cref="byte" /> arrays the same.
 44        /// </summary>
 45        /// <param name="sourceBytes">The left hand side <see cref="byte" /> array to compare.</param>
 46        /// <param name="targetBytes">The right hand side <see cref="byte" /> array to compare.</param>
 47        /// <returns>true if they are identical, will also return true if both are null.</returns>
 48        public static bool IsSame(this byte[] sourceBytes, byte[] targetBytes)
 549        {
 550            if (sourceBytes == null)
 151            {
 152                return targetBytes == null;
 53            }
 54
 455            if (targetBytes == null)
 156            {
 157                return false;
 58            }
 59
 360            if (sourceBytes.Length != targetBytes.Length)
 161            {
 162                return false;
 63            }
 64
 265            int count = sourceBytes.Length;
 2066            for (int i = 0; i < count; i++)
 967            {
 968                if (sourceBytes[i] != targetBytes[i])
 169                {
 170                    return false;
 71                }
 872            }
 73
 174            return true;
 575        }
 76    }
 77}

Coverage by test methods







Methods/Properties

GetStableHashCode(System.Byte[])
IsSame(System.Byte[], System.Byte[])