本文整理汇总了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>();
}
示例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];
}
示例3: NextValueThrowsExceptionWhenMinimumGreaterThanMaximumTest
public void NextValueThrowsExceptionWhenMinimumGreaterThanMaximumTest()
{
var target = new RandomGenerator();
Action action = () => target.NextValue(1, 0);
action.ShouldThrow<ArgumentOutOfRangeException>();
}
示例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];
}
示例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);
}
示例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);
}
示例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();
}
示例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>();
}
}
示例9: NextValueWithTypeThrowsExceptionWithNullTypeTest
public void NextValueWithTypeThrowsExceptionWithNullTypeTest()
{
var target = new RandomGenerator();
Action action = () => target.NextValue(null, 0, 0);
action.ShouldThrow<ArgumentNullException>();
}
示例10: NextValueWithTypeThrowsExceptionWithNullMaximumTest
public void NextValueWithTypeThrowsExceptionWithNullMaximumTest()
{
var target = new RandomGenerator();
Action action = () => target.NextValue(typeof(int), 0, null);
action.ShouldThrow<ArgumentNullException>();
}
示例11: NextValueWithTypeThrowsExceptionWithNonNumericMinimumTest
public void NextValueWithTypeThrowsExceptionWithNonNumericMinimumTest()
{
var target = new RandomGenerator();
Action action = () => target.NextValue(typeof(int), Guid.NewGuid().ToString(), 0);
action.ShouldThrow<FormatException>();
}
示例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);
}
}
示例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();
}
示例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();
}
示例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();
}