< Summary

Class:GDX.Mathematics.Random.RandomAdaptor
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Mathematics/Random/RandomAdaptor.cs
Covered lines:30
Uncovered lines:0
Coverable lines:30
Total lines:84
Line coverage:100% (30 of 30)
Covered branches:0
Total branches:0
Covered methods:7
Total methods:7
Method coverage:100% (7 of 7)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
RandomAdaptor(...)0%110100%
HasProvider()0%110100%
Next()0%110100%
Next(...)0%220100%
Next(...)0%220100%
NextDouble()0%110100%
NextBytes(...)0%110100%

File(s)

./Packages/com.dotbunny.gdx/GDX/Mathematics/Random/RandomAdaptor.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
 5using System.Diagnostics.CodeAnalysis;
 6
 7namespace GDX.Mathematics.Random
 8{
 9    // ReSharper disable CommentTypo
 10    /// <summary>
 11    ///     Adapter to utilize a <see cref="IRandomProvider" /> with <see cref="System.Random" /> based systems, wrappin
 12    ///     provider in a class object with expected overrides.
 13    /// </summary>
 14    /// <remarks>This will create IL <c>callvert</c> operation codes! Try not to use this.</remarks>
 15    // ReSharper restore CommentTypo
 16    [VisualScriptingCompatible(4)]
 17    public class RandomAdaptor : System.Random
 18    {
 19        readonly IRandomProvider m_Provider;
 20
 21        /// <summary>
 22        ///     Create an adaptor object which behaves like <see cref="System.Random" />.
 23        /// </summary>
 24        /// <remarks>
 25        ///     Will cause boxing of <see langword="struct" /> based types like <see cref="WELL1024a" />.
 26        ///     This adaptor really should only be used where a method is expecting a <see cref="System.Random" />.
 27        /// </remarks>
 28        /// <param name="provider">A qualified <see cref="IRandomProvider" />.</param>
 729        public RandomAdaptor(IRandomProvider provider)
 730        {
 731            m_Provider = provider;
 732        }
 33
 34        /// <summary>
 35        ///     Is the provider present, and not null?
 36        /// </summary>
 37        /// <returns>true/false a provider is not null.</returns>
 38        public bool HasProvider()
 139        {
 140            return m_Provider != null;
 141        }
 42
 43        [ExcludeFromCodeCoverage]
 44        protected override double Sample()
 45        {
 46            return m_Provider.Sample();
 47        }
 48
 49        public override int Next()
 650        {
 651            return m_Provider.NextInteger();
 652        }
 53
 54        public override int Next(int minValue, int maxValue)
 355        {
 356            if (maxValue != int.MaxValue)
 357            {
 358                maxValue++;
 359            }
 60
 361            return m_Provider.NextInteger(minValue, maxValue);
 362        }
 63
 64        public override int Next(int maxValue)
 365        {
 366            if (maxValue != int.MaxValue)
 367            {
 368                maxValue++;
 369            }
 70
 371            return m_Provider.NextInteger(0, maxValue);
 372        }
 73
 74        public override double NextDouble()
 275        {
 276            return m_Provider.NextDouble();
 277        }
 78
 79        public override void NextBytes(byte[] buffer)
 180        {
 181            m_Provider.NextBytes(buffer);
 182        }
 83    }
 84}

Coverage by test methods







Methods/Properties

RandomAdaptor(GDX.Mathematics.Random.IRandomProvider)
HasProvider()
Next()
Next(System.Int32, System.Int32)
Next(System.Int32)
NextDouble()
NextBytes(System.Byte[])