当前位置: 首页>>代码示例>>C#>>正文


C# RandomGenerator.NextValue方法代码示例

本文整理汇总了C#中RandomGenerator.NextValue方法的典型用法代码示例。如果您正苦于以下问题:C# RandomGenerator.NextValue方法的具体用法?C# RandomGenerator.NextValue怎么用?C# RandomGenerator.NextValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RandomGenerator的用法示例。


在下文中一共展示了RandomGenerator.NextValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NextValueThrowsExceptionWithUnsupportedTypeTest

        public void NextValueThrowsExceptionWithUnsupportedTypeTest()
        {
            var target = new RandomGenerator();

            Action action = () => target.NextValue('C', 'C');

            action.ShouldThrow<NotSupportedException>();
        }
开发者ID:roryprimrose,项目名称:ModelBuilder,代码行数:8,代码来源:RandomGeneratorExtensionTests.cs

示例2: NextMale

        /// <summary>
        /// Returns a random male from the test data set.
        /// </summary>
        /// <returns>A random male.</returns>
        public static Person NextMale()
        {
            var generator = new RandomGenerator();

            var index = generator.NextValue(0, Males.Count - 1);

            return Males[index];
        }
开发者ID:roryprimrose,项目名称:ModelBuilder,代码行数:12,代码来源:TestData.cs

示例3: NextValueThrowsExceptionWhenMinimumGreaterThanMaximumTest

        public void NextValueThrowsExceptionWhenMinimumGreaterThanMaximumTest()
        {
            var target = new RandomGenerator();

            Action action = () => target.NextValue(1, 0);

            action.ShouldThrow<ArgumentOutOfRangeException>();
        }
开发者ID:roryprimrose,项目名称:ModelBuilder,代码行数:8,代码来源:RandomGeneratorExtensionTests.cs

示例4: NextPerson

        /// <summary>
        /// Returns a random person from the test data set.
        /// </summary>
        /// <returns>A random person.</returns>
        public static Person NextPerson()
        {
            var generator = new RandomGenerator();

            var index = generator.NextValue(0, People.Count - 1);

            return People[index];
        }
开发者ID:roryprimrose,项目名称:ModelBuilder,代码行数:12,代码来源:TestData.cs

示例5: NextValueReturnsRandomValueUsingSpecifiedRangeTest

        public void NextValueReturnsRandomValueUsingSpecifiedRangeTest(double min, double max)
        {
            var target = new RandomGenerator();

            var actual = target.NextValue(min, max);

            var converted = Convert.ToDouble(actual);

            converted.Should().BeGreaterOrEqualTo(min);
            converted.Should().BeLessOrEqualTo(max);
        }
开发者ID:roryprimrose,项目名称:ModelBuilder,代码行数:11,代码来源:RandomGeneratorExtensionTests.cs

示例6: NextValueWithTypeReturnsRandomValueTest

        public void NextValueWithTypeReturnsRandomValueTest(Type type, bool typeSupported, double min, double max)
        {
            if (typeSupported == false)
            {
                return;
            }

            var target = new RandomGenerator();

            var actual = target.NextValue(type, min, max);

            var converted = Convert.ToDouble(actual);

            converted.Should().BeGreaterOrEqualTo(min);
            converted.Should().BeLessOrEqualTo(max);
        }
开发者ID:roryprimrose,项目名称:ModelBuilder,代码行数:16,代码来源:RandomGeneratorTests.cs

示例7: NextValueByteArrayPopulatesBufferTest

        public void NextValueByteArrayPopulatesBufferTest()
        {
            var buffer = new byte[1024];

            var target = new RandomGenerator();

            target.NextValue(buffer);

            buffer.Any(x => x != default(byte)).Should().BeTrue();
        }
开发者ID:roryprimrose,项目名称:ModelBuilder,代码行数:10,代码来源:RandomGeneratorTests.cs

示例8: NextValueWithTypeValidatesRequestedTypeTest

        public void NextValueWithTypeValidatesRequestedTypeTest(Type type, bool typeSupported, double min, double max)
        {
            var target = new RandomGenerator();

            Action action = () => target.NextValue(type, min, max);

            if (typeSupported)
            {
                action.ShouldNotThrow();
            }
            else
            {
                action.ShouldThrow<NotSupportedException>();
            }
        }
开发者ID:roryprimrose,项目名称:ModelBuilder,代码行数:15,代码来源:RandomGeneratorTests.cs

示例9: NextValueWithTypeThrowsExceptionWithNullTypeTest

        public void NextValueWithTypeThrowsExceptionWithNullTypeTest()
        {
            var target = new RandomGenerator();

            Action action = () => target.NextValue(null, 0, 0);

            action.ShouldThrow<ArgumentNullException>();
        }
开发者ID:roryprimrose,项目名称:ModelBuilder,代码行数:8,代码来源:RandomGeneratorTests.cs

示例10: NextValueWithTypeThrowsExceptionWithNullMaximumTest

        public void NextValueWithTypeThrowsExceptionWithNullMaximumTest()
        {
            var target = new RandomGenerator();

            Action action = () => target.NextValue(typeof(int), 0, null);

            action.ShouldThrow<ArgumentNullException>();
        }
开发者ID:roryprimrose,项目名称:ModelBuilder,代码行数:8,代码来源:RandomGeneratorTests.cs

示例11: NextValueWithTypeThrowsExceptionWithNonNumericMinimumTest

        public void NextValueWithTypeThrowsExceptionWithNonNumericMinimumTest()
        {
            var target = new RandomGenerator();

            Action action = () => target.NextValue(typeof(int), Guid.NewGuid().ToString(), 0);

            action.ShouldThrow<FormatException>();
        }
开发者ID:roryprimrose,项目名称:ModelBuilder,代码行数:8,代码来源:RandomGeneratorTests.cs

示例12: NextValueWithTypeReturnsNewValueTest

        public void NextValueWithTypeReturnsNewValueTest(Type type, bool typeSupported, double min, double max)
        {
            if (typeSupported == false)
            {
                // Ignore this test
                return;
            }

            var target = new RandomGenerator();

            var value = target.NextValue(type, min, max);

            value.Should().NotBeNull();

            if (type.IsNullable())
            {
                value.Should().BeOfType(type.GetGenericArguments()[0]);
            }
            else
            {
                value.Should().BeOfType(type);
            }
        }
开发者ID:roryprimrose,项目名称:ModelBuilder,代码行数:23,代码来源:RandomGeneratorTests.cs

示例13: NextValueWithTypeReturnsDecimalValuesTest

        public void NextValueWithTypeReturnsDecimalValuesTest(Type type)
        {
            var decimalFound = false;

            var target = new RandomGenerator();

            for (var index = 0; index < 1000; index++)
            {
                var min = target.GetMin(type);
                var max = target.GetMax(type);

                var value = target.NextValue(type, min, max);

                var actual = Convert.ToDouble(value);

                if (unchecked(actual != (int) actual))
                {
                    decimalFound = true;

                    break;
                }
            }

            decimalFound.Should().BeTrue();
        }
开发者ID:roryprimrose,项目名称:ModelBuilder,代码行数:25,代码来源:RandomGeneratorTests.cs

示例14: NextValueWithTypeDoesNotReturnInfinityForDoubleTest

        public void NextValueWithTypeDoesNotReturnInfinityForDoubleTest()
        {
            var target = new RandomGenerator();

            var value = target.NextValue(typeof(double), double.MinValue, double.MaxValue);

            var actual = Convert.ToDouble(value);

            double.IsInfinity(actual).Should().BeFalse();
        }
开发者ID:roryprimrose,项目名称:ModelBuilder,代码行数:10,代码来源:RandomGeneratorTests.cs

示例15: NextValueWithTypeCanReturnNonMinValuesTest

        public void NextValueWithTypeCanReturnNonMinValuesTest()
        {
            var valueFound = false;

            var target = new RandomGenerator();

            for (var index = 0; index < 1000; index++)
            {
                var value = target.NextValue(typeof(double), double.MinValue, double.MaxValue);

                var actual = Convert.ToDouble(value);

                if (actual.Equals(double.MinValue) == false)
                {
                    valueFound = true;

                    break;
                }
            }

            valueFound.Should().BeTrue();
        }
开发者ID:roryprimrose,项目名称:ModelBuilder,代码行数:22,代码来源:RandomGeneratorTests.cs


注:本文中的RandomGenerator.NextValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。