PseudoRandomTests ClassDelta Engine Documentation
Inheritance Hierarchy

System Object
  DeltaEngine.Tests.Core PseudoRandomTests

Namespace: DeltaEngine.Tests.Core
Assembly: DeltaEngine.Tests (in DeltaEngine.Tests.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public class PseudoRandomTests

The PseudoRandomTests type exposes the following members.

Constructors

  NameDescription
Public methodPseudoRandomTests
Initializes a new instance of the PseudoRandomTests class
Top
Methods

  NameDescription
Public methodGetRandomBrightColorUsingFixedRandomValues
Public methodRandomFloatSanityTest
Public methodRandomIntSanityTest
Public methodUseDefaultRandomizer
Top
Examples

[Test]
public void UseDefaultRandomizer()
{
    Assert.Less(Randomizer.Current.Get(1, 100), 100);
}
[Test]
public void GetRandomBrightColorUsingFixedRandomValues()
{
    using (Randomizer.Use(new FixedRandom(new[] { 0.0f, 0.5f})))
    {
        Assert.AreEqual(0, Randomizer.Current.Get(0, 10));
        Assert.AreEqual(5, Randomizer.Current.Get(0, 10));
        Assert.AreEqual(2, Randomizer.Current.Get(2, 4));
    }
}
[Test, Category("Slow")]
public void RandomIntSanityTest()
{
    var random = new PseudoRandom();
    const int Max = 10;
    var wasChosen = new bool[Max];
    const int Trials = Max * 1000;
    for (int i = 0; i < Trials; i++)
        wasChosen[random.Get(0, Max)] = true;
    for (int i = 0; i < Max; i++)
        Assert.IsTrue(wasChosen[i]);
}
[Test, Category("Slow")]
public void RandomFloatSanityTest()
{
    var random = new PseudoRandom();
    const int Max = 10;
    var wasChosen = new bool[Max];
    const int Trials = Max * 1000;
    for (int i = 0; i < Trials; i++)
        wasChosen[(int)random.Get(0.0f, Max)] = true;
    for (int i = 0; i < Max; i++)
        Assert.IsTrue(wasChosen[i]);
}
See Also