blob: faf07306a0aafbdd2e22a9aada479a49d6f84b45 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
//
// System.Random Test Cases
//
// Author: Bob Smith <bob@thestuff.net>
//
using NUnit.Framework;
using System;
namespace MonoTests.System {
public class RandomTest : TestCase
{
public static ITest Suite {
get {
return new TestSuite(typeof(RandomTest));
}
}
public RandomTest() : base ("MonoTests.System.RandomTest testcase") {}
public RandomTest(string name): base(name){}
public void TestDouble()
{
Random r = new Random();
int i;
double c=0;
for (i=0; i<20; i++) c+=r.NextDouble();
c/=i;
Assert (c.ToString() + " is out of range.", c < .7 && c > .3);
}
public void TestSeed()
{
Random r = new Random(42);
Random r2 = new Random(42);
int i;
double c=0, c2=0;
for (i=0; i<20; i++)
{
c += r.NextDouble();
c2 += r2.NextDouble();
}
AssertEquals(c, c2);
}
public void TestNext()
{
Random r = new Random();
int i;
long c;
for (i=0; i<20; i++)
{
c = r.Next();
Assert (c < Int32.MaxValue && c >= 0);
}
}
public void TestNextMax()
{
Random r = new Random();
int i;
long c;
for (i=0; i<20; i++)
{
c = r.Next(10);
Assert (c < 10 && c >= 0);
}
}
public void TestNextMinMax()
{
Random r = new Random();
int i;
long c;
for (i=0; i<20; i++)
{
c = r.Next(1, 10);
Assert (c < 10 && c >= 1);
}
}
}
}
|