IGLib
1.7.2
The IGLib base library EXTENDED - with other lilbraries and applications.
|
Randomizer returns a set of random _values in a repeatable way, to allow re-running of tests if necessary. It extends the .NET Random class, providing random values for a much wider range of types. More...
Public Member Functions | |
Randomizer () | |
Default constructor More... | |
Randomizer (int seed) | |
Construct based on seed value More... | |
uint | NextUInt () |
Returns a random unsigned int. More... | |
uint | NextUInt (uint max) |
Returns a random unsigned int less than the specified maximum. More... | |
uint | NextUInt (uint min, uint max) |
Returns a random unsigned int within a specified range. More... | |
short | NextShort () |
Returns a non-negative random short. More... | |
short | NextShort (short max) |
Returns a non-negative random short less than the specified maximum. More... | |
short | NextShort (short min, short max) |
Returns a non-negative random short within a specified range. More... | |
ushort | NextUShort () |
Returns a random unsigned short. More... | |
ushort | NextUShort (ushort max) |
Returns a random unsigned short less than the specified maximum. More... | |
ushort | NextUShort (ushort min, ushort max) |
Returns a random unsigned short within a specified range. More... | |
long | NextLong () |
Returns a random long. More... | |
long | NextLong (long max) |
Returns a random long less than the specified maximum. More... | |
long | NextLong (long min, long max) |
Returns a non-negative random long within a specified range. More... | |
ulong | NextULong () |
Returns a random ulong. More... | |
ulong | NextULong (ulong max) |
Returns a random ulong less than the specified maximum. More... | |
ulong | NextULong (ulong min, ulong max) |
Returns a non-negative random long within a specified range. More... | |
byte | NextByte () |
Returns a random Byte More... | |
byte | NextByte (byte max) |
Returns a random Byte less than the specified maximum. More... | |
byte | NextByte (byte min, byte max) |
Returns a random Byte within a specified range More... | |
sbyte | NextSByte () |
Returns a random SByte More... | |
sbyte | NextSByte (sbyte max) |
Returns a random sbyte less than the specified maximum. More... | |
sbyte | NextSByte (sbyte min, sbyte max) |
Returns a random sbyte within a specified range More... | |
bool | NextBool () |
Returns a random bool More... | |
bool | NextBool (double probability) |
Returns a random bool based on the probablility a true result More... | |
double | NextDouble (double max) |
Returns a random double between 0.0 and the specified maximum. More... | |
double | NextDouble (double min, double max) |
Returns a random double within a specified range. More... | |
float | NextFloat () |
Returns a random float. More... | |
float | NextFloat (float max) |
Returns a random float between 0.0 and the specified maximum. More... | |
float | NextFloat (float min, float max) |
Returns a random float within a specified range. More... | |
object | NextEnum (Type type) |
Returns a random enum value of the specified Type as an object. More... | |
T | NextEnum< T > () |
Returns a random enum value of the specified Type. More... | |
string | GetString (int outputLength, string allowedChars) |
Generate a random string based on the characters from the input string. More... | |
string | GetString (int outputLength) |
Generate a random string based on the characters from the input string. More... | |
string | GetString () |
Generate a random string based on the characters from the input string. More... | |
decimal | NextDecimal () |
Returns a random decimal. More... | |
decimal | NextDecimal (decimal max) |
Returns a random decimal between positive zero and the specified maximum. More... | |
decimal | NextDecimal (decimal min, decimal max) |
Returns a random decimal within a specified range, which is not permitted to exceed decimal.MaxVal in the current implementation. More... | |
Static Public Member Functions | |
static Randomizer | GetRandomizer (MemberInfo member) |
Get a Randomizer for a particular member, returning one that has already been created if it exists. This ensures that the same _values are generated each time the tests are reloaded. More... | |
static Randomizer | GetRandomizer (ParameterInfo parameter) |
Get a randomizer for a particular parameter, returning one that has already been created if it exists. This ensures that the same values are generated each time the tests are reloaded. More... | |
static Randomizer | CreateRandomizer () |
Create a new Randomizer using the next seed available to ensure that each randomizer gives a unique sequence of values. More... | |
Public Attributes | |
const string | DefaultStringChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789_" |
Default characters for random functions. More... | |
Properties | |
static int | InitialSeed [get, set] |
Initial seed used to create randomizers for this run More... | |
static Random | SeedGenerator [get] |
Private Member Functions | |
uint | RawUInt () |
uint | RawUShort () |
ulong | RawULong () |
long | RawLong () |
decimal | RawDecimal () |
Private Attributes | |
const int | DefaultStringLength = 25 |
Static Private Attributes | |
static Random | _seedGenerator |
static Dictionary< MemberInfo, Randomizer > | Randomizers = new Dictionary<MemberInfo, Randomizer>() |
Randomizer returns a set of random _values in a repeatable way, to allow re-running of tests if necessary. It extends the .NET Random class, providing random values for a much wider range of types.
The class is used internally by the framework to generate test case data and is also exposed for use by users through the TestContext.Random property.
For consistency with the underlying Random Type, methods returning a single value use the prefix "Next..." Those without an argument return a non-negative value up to the full positive range of the Type. Overloads are provided for specifying a maximum or a range. Methods that return arrays or strings use the prefix "Get..." to avoid confusion with the single-value methods.
|
inline |
Default constructor
|
inline |
Construct based on seed value
seed |
|
inlinestatic |
Get a Randomizer for a particular member, returning one that has already been created if it exists. This ensures that the same _values are generated each time the tests are reloaded.
Referenced by NUnit.Framework.RandomAttribute.RandomDataSource< T >.GetData(), NUnit.Framework.RandomAttribute.EnumDataSource.GetData(), NUnit.Framework.Internal.RandomizerTests.Repeatability.ReturnsDifferentRandomizersForDifferentMethods(), NUnit.Framework.Internal.RandomizerTests.Repeatability.ReturnsSameRandomizerForDifferentParametersOfSameMethod(), NUnit.Framework.Internal.RandomizerTests.Repeatability.ReturnsSameRandomizerForSameMethod(), and NUnit.Framework.Internal.RandomizerTests.Repeatability.ReturnsSameRandomizerForSameParameter().
|
inlinestatic |
Get a randomizer for a particular parameter, returning one that has already been created if it exists. This ensures that the same values are generated each time the tests are reloaded.
|
inlinestatic |
Create a new Randomizer using the next seed available to ensure that each randomizer gives a unique sequence of values.
|
inline |
Returns a random unsigned int.
Referenced by NUnit.Framework.Internal.RandomizerTests.RandomUInt(), NUnit.Framework.Internal.RandomizerTests.RandomUIntInRange(), NUnit.Framework.Internal.RandomizerTests.RandomUintInRange_MinEqualsMax(), NUnit.Framework.Internal.RandomizerTests.RandomUintInRange_Reversed(), NUnit.Framework.Internal.RandomizerTests.RandomUIntsAreUnique(), NUnit.Framework.Internal.RandomizerTests.RandomUIntsInRangeAreUnique(), and NUnit.Framework.Internal.RandomizerTests.RandomUIntWithMaximum().
|
inline |
Returns a random unsigned int less than the specified maximum.
|
inline |
Returns a random unsigned int within a specified range.
|
inline |
Returns a non-negative random short.
Referenced by NUnit.Framework.Internal.RandomizerTests.RandomShort(), NUnit.Framework.Internal.RandomizerTests.RandomShortInRange(), NUnit.Framework.Internal.RandomizerTests.RandomShortInRange_MinEqualsMax(), NUnit.Framework.Internal.RandomizerTests.RandomShortInRange_Reversed(), NUnit.Framework.Internal.RandomizerTests.RandomShortsAreUnique(), NUnit.Framework.Internal.RandomizerTests.RandomShortsInRangeAreUnique(), and NUnit.Framework.Internal.RandomizerTests.RandomShortWithMaximum().
|
inline |
Returns a non-negative random short less than the specified maximum.
|
inline |
Returns a non-negative random short within a specified range.
|
inline |
Returns a random unsigned short.
Referenced by NUnit.Framework.Internal.RandomizerTests.RandomUShort(), NUnit.Framework.Internal.RandomizerTests.RandomUShortInRange(), NUnit.Framework.Internal.RandomizerTests.RandomUShortInRange_MinEqualsMax(), NUnit.Framework.Internal.RandomizerTests.RandomUShortInRange_Reversed(), NUnit.Framework.Internal.RandomizerTests.RandomUShortsAreUnique(), NUnit.Framework.Internal.RandomizerTests.RandomUShortsInRangeAreUnique(), and NUnit.Framework.Internal.RandomizerTests.RandomUShortWithMaximum().
|
inline |
Returns a random unsigned short less than the specified maximum.
|
inline |
Returns a random unsigned short within a specified range.
|
inline |
Returns a random long.
Referenced by NUnit.Framework.Internal.RandomizerTests.RandomLong(), NUnit.Framework.Internal.RandomizerTests.RandomLongInRange(), NUnit.Framework.Internal.RandomizerTests.RandomLongInRange_MinEqualsMax(), NUnit.Framework.Internal.RandomizerTests.RandomLongInRange_Reversed(), NUnit.Framework.Internal.RandomizerTests.RandomLongsAreUnique(), NUnit.Framework.Internal.RandomizerTests.RandomLongsInRangeAreUnique(), and NUnit.Framework.Internal.RandomizerTests.RandomLongWithMaximum().
|
inline |
Returns a random long less than the specified maximum.
|
inline |
Returns a non-negative random long within a specified range.
|
inline |
Returns a random ulong.
Referenced by NUnit.Framework.Internal.RandomizerTests.RandomULong(), NUnit.Framework.Internal.RandomizerTests.RandomULongInRange(), NUnit.Framework.Internal.RandomizerTests.RandomULongInRange_MinEqualsMax(), NUnit.Framework.Internal.RandomizerTests.RandomULongInRange_Reversed(), NUnit.Framework.Internal.RandomizerTests.RandomULongsAreUnique(), NUnit.Framework.Internal.RandomizerTests.RandomULongsInRangeAreUnique(), and NUnit.Framework.Internal.RandomizerTests.RandomULongWithMaximum().
|
inline |
Returns a random ulong less than the specified maximum.
|
inline |
Returns a non-negative random long within a specified range.
|
inline |
Returns a random Byte
Referenced by NUnit.Framework.Internal.RandomizerTests.RandomByte(), NUnit.Framework.Internal.RandomizerTests.RandomByteInRange(), NUnit.Framework.Internal.RandomizerTests.RandomByteInRange_MinEqualsMax(), NUnit.Framework.Internal.RandomizerTests.RandomByteInRange_Reversed(), NUnit.Framework.Internal.RandomizerTests.RandomBytesAreUnique(), NUnit.Framework.Internal.RandomizerTests.RandomBytesInRangeAreUnique(), and NUnit.Framework.Internal.RandomizerTests.RandomByteWithMaximum().
|
inline |
Returns a random Byte less than the specified maximum.
|
inline |
Returns a random Byte within a specified range
|
inline |
Returns a random SByte
Referenced by NUnit.Framework.Internal.RandomizerTests.RandomSByte(), NUnit.Framework.Internal.RandomizerTests.RandomSByteInRange(), NUnit.Framework.Internal.RandomizerTests.RandomSbyteInRange_MinEqualsMax(), NUnit.Framework.Internal.RandomizerTests.RandomSByteInRange_Reversed(), NUnit.Framework.Internal.RandomizerTests.RandomSBytesAreUnique(), NUnit.Framework.Internal.RandomizerTests.RandomSBytesInRangeAreUnique(), and NUnit.Framework.Internal.RandomizerTests.RandomSByteWithMaximum().
|
inline |
Returns a random sbyte less than the specified maximum.
|
inline |
Returns a random sbyte within a specified range
|
inline |
Returns a random bool
Referenced by NUnit.Framework.Internal.RandomizerTests.RandomBool(), NUnit.Framework.Internal.RandomizerTests.RandomBoolWithProbability(), NUnit.Framework.Internal.RandomizerTests.RandomBoolWithProbabilityOneIsAlwaysTrue(), NUnit.Framework.Internal.RandomizerTests.RandomBoolWithProbabilityOutOfRange(), and NUnit.Framework.Internal.RandomizerTests.RandomBoolWithProbabilityZeroIsAlwaysFalse().
|
inline |
Returns a random bool based on the probablility a true result
|
inline |
Returns a random double between 0.0 and the specified maximum.
Referenced by NUnit.Framework.Internal.RandomizerTests.RandomDouble(), NUnit.Framework.Internal.RandomizerTests.RandomDoubleInRange(), NUnit.Framework.Internal.RandomizerTests.RandomDoubleInRange_MinEqualsMax(), NUnit.Framework.Internal.RandomizerTests.RandomDoubleInRange_Reversed(), NUnit.Framework.Internal.RandomizerTests.RandomDoublesAreUnique(), NUnit.Framework.Internal.RandomizerTests.RandomDoublesInRangeAreUnique(), and NUnit.Framework.Internal.RandomizerTests.RandomDoubleWithMaximum().
|
inline |
Returns a random double within a specified range.
|
inline |
Returns a random float.
Referenced by NUnit.Framework.Internal.RandomizerTests.GetFloats(), NUnit.Framework.Internal.RandomizerTests.RandomFloat(), NUnit.Framework.Internal.RandomizerTests.RandomFloatInRange(), NUnit.Framework.Internal.RandomizerTests.RandomFloatInRange_MinEqualsMax(), NUnit.Framework.Internal.RandomizerTests.RandomFloatInRange_Reversed(), NUnit.Framework.Internal.RandomizerTests.RandomFloatsAreUnique(), NUnit.Framework.Internal.RandomizerTests.RandomFloatsInRangeAreUnique(), and NUnit.Framework.Internal.RandomizerTests.RandomFloatWithMaximum().
|
inline |
Returns a random float between 0.0 and the specified maximum.
|
inline |
Returns a random float within a specified range.
|
inline |
Returns a random enum value of the specified Type as an object.
References NUnit.Framework.Internal.TypeHelper.GetEnumValues().
Referenced by NUnit.Framework.RandomAttribute.EnumDataSource.GetData(), NUnit.Framework.Internal.RandomizerTests.RandomEnum(), and NUnit.Framework.Internal.RandomizerTests.RandomEnum_Generic().
|
inline |
Returns a random enum value of the specified Type.
|
inline |
Generate a random string based on the characters from the input string.
outputLength | desired length of output string. |
allowedChars | string representing the set of characters from which to construct the resulting string |
Referenced by NUnit.Framework.Internal.RandomizerTests.RandomStringsAreUnique().
|
inline |
Generate a random string based on the characters from the input string.
outputLength | desired length of output string. |
Uses DefaultStringChars as the input character set
|
inline |
Generate a random string based on the characters from the input string.
Uses DefaultStringChars as the input character set
|
inline |
Returns a random decimal.
Referenced by NUnit.Framework.Internal.RandomizerTests.RandomDecimal(), NUnit.Framework.Internal.RandomizerTests.RandomDecimalInRange(), NUnit.Framework.Internal.RandomizerTests.RandomDecimalInRange_MinEqualsMax(), NUnit.Framework.Internal.RandomizerTests.RandomDecimalInRange_Reversed(), NUnit.Framework.Internal.RandomizerTests.RandomDecimalRangeTooGreat(), NUnit.Framework.Internal.RandomizerTests.RandomDecimalsAreUnique(), NUnit.Framework.Internal.RandomizerTests.RandomDecimalsInRangeAreUnique(), and NUnit.Framework.Internal.RandomizerTests.RandomDecimalWithMaximum().
|
inline |
Returns a random decimal between positive zero and the specified maximum.
|
inline |
Returns a random decimal within a specified range, which is not permitted to exceed decimal.MaxVal in the current implementation.
A limitation of this implementation is that the range from min to max must not exceed decimal.MaxVal.
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
staticprivate |
|
staticprivate |
const string NUnit.Framework.Internal.Randomizer.DefaultStringChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789_" |
Default characters for random functions.
Default characters are the English alphabet (uppercase & lowercase), arabic numerals, and underscore
|
private |
|
staticgetset |
Initial seed used to create randomizers for this run
Referenced by NUnit.Framework.Api.NUnitTestAssemblyRunner.Load(), and NUnitLite.NUnit3XmlOutputWriter.MakeTestRunElement().
|
staticgetprivate |