< Summary

Class:GDX.Collections.Generic.DictionaryPrimes
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Collections/Generic/DictionaryPrimes.cs
Covered lines:36
Uncovered lines:5
Coverable lines:41
Total lines:115
Line coverage:87.8% (36 of 41)
Covered branches:0
Total branches:0
Covered methods:5
Total methods:6
Method coverage:83.3% (5 of 6)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetPrime(...)0%44093.75%
GetPrimeAtIndex(...)0%110100%
GetPrimesLength()0%2100%
GetNextSize(...)0%5.015093.75%
SetDefaultPrimes()0%110100%
SetPrimes(...)0%110100%

File(s)

./Packages/com.dotbunny.gdx/GDX/Collections/Generic/DictionaryPrimes.cs

#LineLine coverage
 1namespace GDX.Collections.Generic
 2{
 3    /// <summary>
 4    ///     A default selection of prime numbers used with different collections.
 5    /// </summary>
 6    public static class DictionaryPrimes
 7    {
 8        /// <summary>
 9        ///     The cached array of prime numbers.
 10        /// </summary>
 11        static int[] s_Primes;
 12
 13        /// <summary>
 14        ///     The number of predetermined prime numbers in <see cref="s_Primes" />.
 15        /// </summary>
 16        static int s_PrimesLength;
 17
 18        /// <summary>
 19        ///     Get the nearest prime number greater then or equal to the provided <paramref name="minimum" />.
 20        /// </summary>
 21        /// <param name="minimum">The lowest possible value.</param>
 22        /// <returns>A prime number.</returns>
 23        public static int GetPrime(int minimum)
 15724        {
 15725            if (s_PrimesLength == 0)
 226            {
 227                SetDefaultPrimes();
 228            }
 29
 44230            for (int i = 0; i < s_PrimesLength; i++)
 22131            {
 22132                int prime = s_Primes[i];
 22133                if (prime >= minimum)
 15734                {
 15735                    return prime;
 36                }
 6437            }
 38
 039            return int.MaxValue;
 15740        }
 41
 42        /// <summary>
 43        ///     Get the prime number in <see cref="s_Primes" /> at index.
 44        /// </summary>
 45        /// <remarks>No out of bounds detection.</remarks>
 46        /// <param name="index">The valid array index requested.</param>
 47        /// <returns>A prime number.</returns>
 48        public static int GetPrimeAtIndex(int index)
 649        {
 650            return s_Primes[index];
 651        }
 52
 53        /// <summary>
 54        ///     Get the number of prime numbers
 55        /// </summary>
 56        /// <returns></returns>
 57        public static int GetPrimesLength()
 058        {
 059            return s_PrimesLength;
 060        }
 61
 62        /// <summary>
 63        ///     Returns size of hashtable to grow to.
 64        /// </summary>
 65        /// <param name="oldSize"></param>
 66        /// <returns></returns>
 67        public static int GetNextSize(int oldSize)
 1768        {
 1769            uint newSize = 2U * unchecked((uint)oldSize);
 70
 71            const int k_MaxPrime = int.MaxValue;
 1772            newSize = newSize > k_MaxPrime ? k_MaxPrime : newSize;
 73
 1774            int primesLength = s_PrimesLength;
 1775            int[] primes = s_Primes;
 76
 16477            for (int i = 0; i < primesLength; i++)
 8278            {
 8279                int prime = primes[i];
 8280                if (prime >= newSize)
 1781                {
 1782                    return prime;
 83                }
 6584            }
 85
 086            return k_MaxPrime;
 1787        }
 88
 89        /// <summary>
 90        ///     Establish the default prime numbers in <see cref="s_Primes" />.
 91        /// </summary>
 92        public static void SetDefaultPrimes()
 293        {
 294            SetPrimes(new[]
 95            {
 96                17, 23, 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293, 353, 431, 521, 631, 761, 919, 1103,
 97                1327, 1597, 1931, 2333, 2801, 3371, 4049, 4861, 5839, 7013, 8419, 10103, 12143, 14591, 17519, 21023,
 98                25229, 30293, 36353, 43627, 52361, 62851, 75431, 90523, 108631, 130363, 156437, 187751, 225307,
 99                270371, 324449, 389357, 467237, 560689, 672827, 807403, 968897, 1162687, 1395263, 1674319, 2009191,
 100                2411033, 2893249, 3471899, 4166287, 4999559, 5999471, 7199369, 12582917, 25165843, 50331653,
 101                100663319, 201326611, 402653189, 805306457, 1610612741
 102            });
 2103        }
 104
 105        /// <summary>
 106        ///     Set the <see cref="s_Primes" /> array with the provided <paramref name="primes" />.
 107        /// </summary>
 108        /// <param name="primes">An array of prime numbers.</param>
 109        public static void SetPrimes(int[] primes)
 2110        {
 2111            s_Primes = primes;
 2112            s_PrimesLength = primes.Length;
 2113        }
 114    }
 115}

Coverage by test methods








































































Methods/Properties

GetPrime(System.Int32)
GetPrimeAtIndex(System.Int32)
GetPrimesLength()
GetNextSize(System.Int32)
SetDefaultPrimes()
SetPrimes(System.Int32[])