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