* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / corlib / Test / Mono.Math / PrimeTestingTest.cs
1 //
2 // MonoTests.Mono.Math.PrimeTestingTest.cs
3 //
4 // Authors:
5 //      Ben Maurer
6 //
7 // Copyright (c) 2003 Ben Maurer. All rights reserved
8 //
9
10 using System;
11 using Mono.Math;
12 using Mono.Math.Prime;
13 using NUnit.Framework;
14
15 namespace MonoTests.Mono.Math {
16
17         public abstract class PrimeTesting_Base : BigIntegerTestSet {
18
19                 BigInteger P1, P2, P3;
20
21                 public PrimeTesting_Base () 
22                 {
23                         P1 = new BigInteger (p1);
24                         P2 = new BigInteger (p2);
25                         P3 = new BigInteger (p3);
26                 }
27
28                 public abstract uint[] p1 {
29                         get;
30                 }
31
32                 public abstract uint[] p2 {
33                         get;
34                 }
35
36                 public abstract uint[] p3 {
37                         get;
38                 }
39                 
40                 [Test]
41                 public void p1prime ()
42                 {
43                         ExpectPrime (P1);
44                 }
45
46                 [Test]
47                 public void p2prime ()
48                 {
49                         ExpectPrime (P2);
50                 }
51
52                 [Test]
53                 public void p3prime ()
54                 {
55                         ExpectPrime (P3);
56                 }
57
58                 [Test]
59                 public void p1p2composite ()
60                 {
61                         ExpectComposite (P1 * P2);
62                 }
63
64                 [Test]
65                 public void p1p3composite ()
66                 {
67                         ExpectComposite (P1 * P3);
68                 }
69
70                 [Test]
71                 public void p2p3composite ()
72                 {
73                         ExpectComposite (P2 * P3);
74                 }
75
76                 [Test]
77                 public void p1p2p3composite ()
78                 {
79                         ExpectComposite (P1 * P2 * P3);
80                 }
81
82                 private void ExpectComposite (BigInteger bi)
83                 {
84                         Assertion.AssertEquals (false, bi.isProbablePrime ());
85                 }
86
87                 private void ExpectPrime (BigInteger bi)
88                 {
89                         Assertion.AssertEquals (true, bi.isProbablePrime ());
90                 }
91         }
92
93         public class PrimeTesting_Rand1024 : PrimeTesting_Base {
94
95                 public override uint[] p1 {
96                         get {
97                                 return new uint[] {
98                                         0x48595126, 0xd1e0c772, 0x87f352a7, 0xeb3c496c, 0xce17d7ff, 0xce260883,
99                                         0x4892835e, 0x4457170e, 0xb90a0893, 0x2a1bfd80, 0x56665a9c, 0x36b06f35,
100                                         0x61988d45, 0xa04e18c2, 0xa2308414, 0xa0be5e2c, 0x423fad73, 0x7117b883,
101                                         0x3977c11c, 0xf34c2c20, 0x045713c9, 0x0c82ea36, 0x3811b550, 0x7b03aafb,
102                                         0xbc31f3c4, 0x8667b5a5, 0x3a5697f7, 0x064169e8, 0xd70dbae4, 0x9bb2a4f8,
103                                         0xba6a1c1c, 0x7c6db863
104                                 };
105                         }
106                 }
107
108                 public override uint[] p2 {
109                         get {
110                                 return new uint[] {
111                                         0x884462b0, 0x8295cefd, 0x444cbcb7, 0xd3916039, 0x45b1e26d, 0x02b3d8d5,
112                                         0x3547b6ee, 0x0791ef10, 0x6da42d3e, 0xee537c9f, 0x339ee744, 0x97d328c7,
113                                         0xebc9055a, 0xf3e1835c, 0xd9cff3db, 0xfe5f33d8, 0x45234644, 0x4af5031b,
114                                         0x27f41403, 0x1d9d751b, 0xb711ddc7, 0xb331784f, 0x992b4148, 0x50a8ac7d,
115                                         0x5c3f1fbb, 0x209d76e3, 0xfbd05088, 0xacf87776, 0xad214d60, 0x1f2ab42d,
116                                         0xe9bc81fc, 0xe997d55b
117                                 };
118                         }
119                 }
120
121                 public override uint[] p3 {
122                         get {
123                                 return new uint[] {
124                                         0xf732ee, 0x019ec52e, 0xfc360881, 0x4fd07211, 0x77d44ed0, 0xc27a4b3d,
125                                         0xde2a9500, 0x2d4a2a70, 0x834e5d32, 0x715f5884, 0xc5922ca1, 0x94d48b60,
126                                         0xb0262fce, 0x72040eb9, 0x5a4fd41c, 0x4e095cba, 0x3a840a36, 0x0175b3b4,
127                                         0x64363623, 0xc03bd892, 0x39231a04, 0x521eee6c, 0x560e7c10, 0xa8476256,
128                                         0xeefc3f37, 0xadd4c5ee, 0xf8407afc, 0x30e9c52c, 0x026849d3, 0x040533df,
129                                         0xc286e00b, 0x9c377705
130                                 };
131                         }
132                 }
133         }
134
135         public class PrimeTesting_Rand512 : PrimeTesting_Base {
136
137                 public override uint[] p1 {
138                         get {
139                                 return new uint[] {
140                                         0x99d95780, 0xd02a33bb, 0x980c079b, 0xbc43c3c2, 0xca501ce0, 0x3fc4bd85,
141                                         0x51035dcc, 0x11dd4c8e, 0x59696b91, 0xcdc7cbc0, 0x29e5c884, 0xae628e88,
142                                         0x908855b7, 0xab6218f3, 0x6abd6fb5, 0x3ca12af7
143                                 };
144                         }
145                 }
146
147                 public override uint[] p2 {
148                         get {
149                                 return new uint[] {
150                                         0xc77a6a36, 0xfe547705, 0x98a57094, 0xc0dd1e8b, 0x78b62bc9, 0x19aea0da,
151                                         0xb91b141b, 0xe4d34402, 0xdd16b9c6, 0x0ec73ea4, 0x8ad59ae5, 0x0d4b0f09,
152                                         0x1fd1858d, 0xaac2891c, 0xbd56c29f, 0xb398ffa5
153                                 };
154                         }
155                 }
156
157                 public override uint[] p3 {
158                         get {
159                                 return new uint[] {
160                                         0xb98e9b3a, 0x197d7671, 0x104d6b15, 0xe8c76058, 0xed9fcb77, 0x65c38af7,
161                                         0xdd660b8e, 0x412c5bbb, 0x80b5f777, 0x70c1a458, 0xc9ad52ae, 0x489bae51,
162                                         0x795f99a7, 0x2f2cb4ae, 0xc902c3ad, 0x9d96456f
163                                 };
164                         }
165                 }
166         }
167         
168         public class PrimeTesting_Rand128 : PrimeTesting_Base {
169
170                 public override uint[] p1 {
171                         get {
172                                 return new uint[] {
173                                         0x28480536, 0xeaf326bc, 0x2957b03b, 0xa1549e59
174                                 };
175                         }
176                 }
177
178                 public override uint[] p2 {
179                         get {
180                                 return new uint[] {
181                                         0xd9ce28be, 0x6a279407, 0x8da0afbc, 0xa57eb9b3
182                                 };
183                         }
184                 }
185
186                 public override uint[] p3 {
187                         get {
188                                 return new uint[] {
189                                         0x1d777a45, 0x957a0fad, 0x25d049a7, 0x4f73383b
190                                 };
191                         }
192                 }
193         }
194 }