IGLib  1.7.2
The IGLib base library EXTENDED - with other lilbraries and applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
NUnit.Framework.Internal.Randomizer Class Reference

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...

+ Inheritance diagram for NUnit.Framework.Internal.Randomizer:
+ Collaboration diagram for NUnit.Framework.Internal.Randomizer:

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...
 
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>()
 

Detailed Description

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.

Constructor & Destructor Documentation

NUnit.Framework.Internal.Randomizer.Randomizer ( )
inline

Default constructor

NUnit.Framework.Internal.Randomizer.Randomizer ( int  seed)
inline

Construct based on seed value

Parameters
seed

Member Function Documentation

static Randomizer NUnit.Framework.Internal.Randomizer.GetRandomizer ( ParameterInfo  parameter)
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.

static Randomizer NUnit.Framework.Internal.Randomizer.CreateRandomizer ( )
inlinestatic

Create a new Randomizer using the next seed available to ensure that each randomizer gives a unique sequence of values.

Returns
uint NUnit.Framework.Internal.Randomizer.NextUInt ( uint  max)
inline

Returns a random unsigned int less than the specified maximum.

uint NUnit.Framework.Internal.Randomizer.NextUInt ( uint  min,
uint  max 
)
inline

Returns a random unsigned int within a specified range.

short NUnit.Framework.Internal.Randomizer.NextShort ( short  max)
inline

Returns a non-negative random short less than the specified maximum.

short NUnit.Framework.Internal.Randomizer.NextShort ( short  min,
short  max 
)
inline

Returns a non-negative random short within a specified range.

ushort NUnit.Framework.Internal.Randomizer.NextUShort ( ushort  max)
inline

Returns a random unsigned short less than the specified maximum.

ushort NUnit.Framework.Internal.Randomizer.NextUShort ( ushort  min,
ushort  max 
)
inline

Returns a random unsigned short within a specified range.

long NUnit.Framework.Internal.Randomizer.NextLong ( long  max)
inline

Returns a random long less than the specified maximum.

long NUnit.Framework.Internal.Randomizer.NextLong ( long  min,
long  max 
)
inline

Returns a non-negative random long within a specified range.

ulong NUnit.Framework.Internal.Randomizer.NextULong ( ulong  max)
inline

Returns a random ulong less than the specified maximum.

ulong NUnit.Framework.Internal.Randomizer.NextULong ( ulong  min,
ulong  max 
)
inline

Returns a non-negative random long within a specified range.

byte NUnit.Framework.Internal.Randomizer.NextByte ( byte  max)
inline

Returns a random Byte less than the specified maximum.

byte NUnit.Framework.Internal.Randomizer.NextByte ( byte  min,
byte  max 
)
inline

Returns a random Byte within a specified range

sbyte NUnit.Framework.Internal.Randomizer.NextSByte ( sbyte  max)
inline

Returns a random sbyte less than the specified maximum.

sbyte NUnit.Framework.Internal.Randomizer.NextSByte ( sbyte  min,
sbyte  max 
)
inline

Returns a random sbyte within a specified range

bool NUnit.Framework.Internal.Randomizer.NextBool ( double  probability)
inline

Returns a random bool based on the probablility a true result

double NUnit.Framework.Internal.Randomizer.NextDouble ( double  min,
double  max 
)
inline

Returns a random double within a specified range.

float NUnit.Framework.Internal.Randomizer.NextFloat ( float  max)
inline

Returns a random float between 0.0 and the specified maximum.

float NUnit.Framework.Internal.Randomizer.NextFloat ( float  min,
float  max 
)
inline

Returns a random float within a specified range.

object NUnit.Framework.Internal.Randomizer.NextEnum ( Type  type)
inline

Returns a random enum value of the specified Type.

string NUnit.Framework.Internal.Randomizer.GetString ( int  outputLength,
string  allowedChars 
)
inline

Generate a random string based on the characters from the input string.

Parameters
outputLengthdesired length of output string.
allowedCharsstring representing the set of characters from which to construct the resulting string
Returns
A random string of arbitrary length

Referenced by NUnit.Framework.Internal.RandomizerTests.RandomStringsAreUnique().

string NUnit.Framework.Internal.Randomizer.GetString ( int  outputLength)
inline

Generate a random string based on the characters from the input string.

Parameters
outputLengthdesired length of output string.
Returns
A random string of arbitrary length

Uses DefaultStringChars as the input character set

string NUnit.Framework.Internal.Randomizer.GetString ( )
inline

Generate a random string based on the characters from the input string.

Returns
A random string of the default length

Uses DefaultStringChars as the input character set

decimal NUnit.Framework.Internal.Randomizer.NextDecimal ( decimal  max)
inline

Returns a random decimal between positive zero and the specified maximum.

decimal NUnit.Framework.Internal.Randomizer.NextDecimal ( decimal  min,
decimal  max 
)
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.

uint NUnit.Framework.Internal.Randomizer.RawUInt ( )
inlineprivate
uint NUnit.Framework.Internal.Randomizer.RawUShort ( )
inlineprivate
ulong NUnit.Framework.Internal.Randomizer.RawULong ( )
inlineprivate
long NUnit.Framework.Internal.Randomizer.RawLong ( )
inlineprivate
decimal NUnit.Framework.Internal.Randomizer.RawDecimal ( )
inlineprivate

Member Data Documentation

Random NUnit.Framework.Internal.Randomizer._seedGenerator
staticprivate
Dictionary<MemberInfo, Randomizer> NUnit.Framework.Internal.Randomizer.Randomizers = new Dictionary<MemberInfo, Randomizer>()
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

const int NUnit.Framework.Internal.Randomizer.DefaultStringLength = 25
private

Property Documentation

int NUnit.Framework.Internal.Randomizer.InitialSeed
staticgetset

Initial seed used to create randomizers for this run

Referenced by NUnit.Framework.Api.NUnitTestAssemblyRunner.Load(), and NUnitLite.NUnit3XmlOutputWriter.MakeTestRunElement().

Random NUnit.Framework.Internal.Randomizer.SeedGenerator
staticgetprivate

The documentation for this class was generated from the following file: