2010-03-05 Rodrigo Kumpera <rkumpera@novell.com>
[mcs.git] / class / System.Numerics / Test / System.Numerics / BigIntegerTest.cs
blob7bf6c7fe8b369bc9d0e8a86ad23749bbb3f995ad
1 // BigIntegerTest.cs
2 //
3 // Authors:
4 // Rodrigo Kumpera <rkumpera@novell.com>
5 //
6 // Copyright (C) 2010 Novell, Inc (http://www.novell.com)
7 //
9 using System;
10 using System.Numerics;
11 using NUnit.Framework;
14 namespace MonoTests.System.Numerics
16 [TestFixture]
17 public class BigIntegerTest
19 static byte[] huge_a = new byte[] {0x1D, 0x33, 0xFB, 0xFE, 0xB1, 0x2, 0x85, 0x44, 0xCA, 0xDC, 0xFB, 0x70, 0xD, 0x39, 0xB1, 0x47, 0xB6, 0xE6, 0xA2, 0xD1, 0x19, 0x1E, 0x9F, 0xE4, 0x3C, 0x1E, 0x16, 0x56, 0x13, 0x9C, 0x4D, 0xD3, 0x5C, 0x74, 0xC9, 0xBD, 0xFA, 0x56, 0x40, 0x58, 0xAC, 0x20, 0x6B, 0x55, 0xA2, 0xD5, 0x41, 0x38, 0xA4, 0x6D, 0xF6, 0x8C, };
21 static byte[] huge_b = new byte[] {0x96, 0x5, 0xDA, 0xFE, 0x93, 0x17, 0xC1, 0x93, 0xEC, 0x2F, 0x30, 0x2D, 0x8F, 0x28, 0x13, 0x99, 0x70, 0xF4, 0x4C, 0x60, 0xA6, 0x49, 0x24, 0xF9, 0xB3, 0x4A, 0x41, 0x67, 0xDC, 0xDD, 0xB1, 0xA5, 0xA6, 0xC0, 0x3D, 0x57, 0x9A, 0xCB, 0x29, 0xE2, 0x94, 0xAC, 0x6C, 0x7D, 0xEF, 0x3E, 0xC6, 0x7A, 0xC1, 0xA8, 0xC8, 0xB0, 0x20, 0x95, 0xE6, 0x4C, 0xE1, 0xE0, 0x4B, 0x49, 0xD5, 0x5A, 0xB7, };
23 static byte[] huge_add = new byte[] {0xB3, 0x38, 0xD5, 0xFD, 0x45, 0x1A, 0x46, 0xD8, 0xB6, 0xC, 0x2C, 0x9E, 0x9C, 0x61, 0xC4, 0xE0, 0x26, 0xDB, 0xEF, 0x31, 0xC0, 0x67, 0xC3, 0xDD, 0xF0, 0x68, 0x57, 0xBD, 0xEF, 0x79, 0xFF, 0x78, 0x3, 0x35, 0x7, 0x15, 0x95, 0x22, 0x6A, 0x3A, 0x41, 0xCD, 0xD7, 0xD2, 0x91, 0x14, 0x8, 0xB3, 0x65, 0x16, 0xBF, 0x3D, 0x20, 0x95, 0xE6, 0x4C, 0xE1, 0xE0, 0x4B, 0x49, 0xD5, 0x5A, 0xB7, };
25 static byte[] a_m_b = new byte[] { 0x87, 0x2D, 0x21, 0x0, 0x1E, 0xEB, 0xC3, 0xB0, 0xDD, 0xAC, 0xCB, 0x43, 0x7E, 0x10, 0x9E, 0xAE, 0x45, 0xF2, 0x55, 0x71, 0x73, 0xD4, 0x7A, 0xEB, 0x88, 0xD3, 0xD4, 0xEE, 0x36, 0xBE, 0x9B, 0x2D, 0xB6, 0xB3, 0x8B, 0x66, 0x60, 0x8B, 0x16, 0x76, 0x17, 0x74, 0xFE, 0xD7, 0xB2, 0x96, 0x7B, 0xBD, 0xE2, 0xC4, 0x2D, 0xDC, 0xDE, 0x6A, 0x19, 0xB3, 0x1E, 0x1F, 0xB4, 0xB6, 0x2A, 0xA5, 0x48, };
26 static byte[] b_m_a = new byte[] { 0x79, 0xD2, 0xDE, 0xFF, 0xE1, 0x14, 0x3C, 0x4F, 0x22, 0x53, 0x34, 0xBC, 0x81, 0xEF, 0x61, 0x51, 0xBA, 0xD, 0xAA, 0x8E, 0x8C, 0x2B, 0x85, 0x14, 0x77, 0x2C, 0x2B, 0x11, 0xC9, 0x41, 0x64, 0xD2, 0x49, 0x4C, 0x74, 0x99, 0x9F, 0x74, 0xE9, 0x89, 0xE8, 0x8B, 0x1, 0x28, 0x4D, 0x69, 0x84, 0x42, 0x1D, 0x3B, 0xD2, 0x23, 0x21, 0x95, 0xE6, 0x4C, 0xE1, 0xE0, 0x4B, 0x49, 0xD5, 0x5A, 0xB7, };
28 static byte[][] add_a = new byte[][] {
29 new byte[] {1},
30 new byte[] {0xFF},
31 huge_a
34 static byte[][] add_b = new byte[][] {
35 new byte[] {1},
36 new byte[] {1},
37 huge_b
40 static byte[][] add_c = new byte[][] {
41 new byte[] {2},
42 new byte[] {0},
43 huge_add
46 [Test]
47 public void TestAdd () {
48 for (int i = 0; i < add_a.Length; ++i) {
49 var a = new BigInteger (add_a [i]);
50 var b = new BigInteger (add_b [i]);
51 var c = new BigInteger (add_c [i]);
53 Assert.AreEqual (c, a + b, "#" + i + "a");
54 Assert.AreEqual (c, b + a, "#" + i + "b");
55 Assert.AreEqual (c, BigInteger.Add (a, b), "#" + i + "c");
56 Assert.AreEqual (add_c [i], (a + b).ToByteArray (), "#" + i + "d");
60 [Test]
61 public void TestAdd2 () {
62 long[] values = new long [] { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L };
63 for (int i = 0; i < values.Length; ++i) {
64 for (int j = 0; j < values.Length; ++j) {
65 var a = new BigInteger (values [i]);
66 var b = new BigInteger (values [j]);
67 var c = a + b;
68 Assert.AreEqual (values [i] + values [j], (long)c, "#_" + i + "_" + j);
73 [Test]
74 public void TestHugeSub () {
75 var a = new BigInteger (huge_a);
76 var b = new BigInteger (huge_b);
77 Assert.AreEqual (a_m_b, (a - b).ToByteArray (), "#1");
78 Assert.AreEqual (b_m_a, (b - a).ToByteArray (), "#2");
81 [Test]
82 public void TestSub () {
83 long[] values = new long [] { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L };
84 for (int i = 0; i < values.Length; ++i) {
85 for (int j = 0; j < values.Length; ++j) {
86 var a = new BigInteger (values [i]);
87 var b = new BigInteger (values [j]);
88 var c = a - b;
89 var d = BigInteger.Subtract (a, b);
91 Assert.AreEqual (values [i] - values [j], (long)c, "#_" + i + "_" + j);
92 Assert.AreEqual (values [i] - values [j], (long)d, "#_" + i + "_" + j);
97 [Test]
98 public void TestMin () {
99 long[] values = new long [] { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L };
100 for (int i = 0; i < values.Length; ++i) {
101 for (int j = 0; j < values.Length; ++j) {
102 var a = new BigInteger (values [i]);
103 var b = new BigInteger (values [j]);
104 var c = BigInteger.Min (a, b);
106 Assert.AreEqual (Math.Min (values [i], values [j]), (long)c, "#_" + i + "_" + j);
111 [Test]
112 public void TestMax () {
113 long[] values = new long [] { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L };
114 for (int i = 0; i < values.Length; ++i) {
115 for (int j = 0; j < values.Length; ++j) {
116 var a = new BigInteger (values [i]);
117 var b = new BigInteger (values [j]);
118 var c = BigInteger.Max (a, b);
120 Assert.AreEqual (Math.Max (values [i], values [j]), (long)c, "#_" + i + "_" + j);
125 [Test]
126 public void TestAbs () {
127 long[] values = new long [] { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L };
128 for (int i = 0; i < values.Length; ++i) {
129 var a = new BigInteger (values [i]);
130 var c = BigInteger.Abs (a);
132 Assert.AreEqual (Math.Abs (values [i]), (long)c, "#_" + i);
136 [Test]
137 public void TestNegate () {
138 long[] values = new long [] { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L };
139 for (int i = 0; i < values.Length; ++i) {
140 var a = new BigInteger (values [i]);
141 var c = -a;
142 var d = BigInteger.Negate (a);
144 Assert.AreEqual (-values [i], (long)c, "#_" + i);
145 Assert.AreEqual (-values [i], (long)d, "#_" + i);
149 [Test]
150 public void CompareOps () {
151 long[] values = new long [] { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L };
152 for (int i = 0; i < values.Length; ++i) {
153 for (int j = 0; j < values.Length; ++j) {
154 var a = new BigInteger (values [i]);
155 var b = new BigInteger (values [j]);
157 Assert.AreEqual (values [i].CompareTo (values [j]), a.CompareTo (b), "#a_" + i + "_" + j);
158 Assert.AreEqual (values [i].CompareTo (values [j]), BigInteger.Compare (a, b), "#b_" + i + "_" + j);
160 Assert.AreEqual (values [i] < values [j], a < b, "#c_" + i + "_" + j);
161 Assert.AreEqual (values [i] <= values [j], a <= b, "#d_" + i + "_" + j);
162 Assert.AreEqual (values [i] == values [j], a == b, "#e_" + i + "_" + j);
163 Assert.AreEqual (values [i] != values [j], a != b, "#f_" + i + "_" + j);
164 Assert.AreEqual (values [i] >= values [j], a >= b, "#g_" + i + "_" + j);
165 Assert.AreEqual (values [i] > values [j], a > b, "#h_" + i + "_" + j);
170 [Test]
171 public void CompareOps2 () {
172 BigInteger a = new BigInteger (100000000000L);
173 BigInteger b = new BigInteger (28282828282UL);
175 Assert.IsTrue (a >= b, "#1");
176 Assert.IsTrue (a >= b, "#2");
177 Assert.IsFalse (a < b, "#3");
178 Assert.IsFalse (a <= b, "#4");
179 Assert.AreEqual (1, a.CompareTo (b), "#5");
182 [Test]
183 public void CompareULong () {
184 long[] values = new long [] { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L, 0xAA00000000L };
185 ulong[] uvalues = new ulong [] {0, 1, 1000, 100000000000L, 999999, 28282828282, 0xAA00000000, ulong.MaxValue };
186 for (int i = 0; i < values.Length; ++i) {
187 for (int j = 0; j < uvalues.Length; ++j) {
188 var a = new BigInteger (values [i]);
189 var b = uvalues [j];
190 var c = new BigInteger (b);
192 Assert.AreEqual (a.CompareTo (c), a.CompareTo (b), "#a_" + i + "_" + j);
194 Assert.AreEqual (a > c, a > b, "#b_" + i + "_" + j);
195 Assert.AreEqual (a < c, a < b, "#c_" + i + "_" + j);
196 Assert.AreEqual (a <= c, a <= b, "#d_" + i + "_" + j);
197 Assert.AreEqual (a == c, a == b, "#e_" + i + "_" + j);
198 Assert.AreEqual (a != c, a != b, "#f_" + i + "_" + j);
199 Assert.AreEqual (a >= c, a >= b, "#g_" + i + "_" + j);
201 Assert.AreEqual (c > a, b > a, "#ib_" + i + "_" + j);
202 Assert.AreEqual (c < a, b < a, "#ic_" + i + "_" + j);
203 Assert.AreEqual (c <= a, b <= a, "#id_" + i + "_" + j);
204 Assert.AreEqual (c == a, b == a, "#ie_" + i + "_" + j);
205 Assert.AreEqual (c != a, b != a, "#if_" + i + "_" + j);
206 Assert.AreEqual (c >= a, b >= a, "#ig_" + i + "_" + j);
211 [Test]
212 public void CompareLong () {
213 long[] values = new long [] { -100000000000L, -1000, -1, 0, 1, 1000, 9999999, 100000000000L, 0xAA00000000, long.MaxValue, long.MinValue };
215 for (int i = 0; i < values.Length; ++i) {
216 for (int j = 0; j < values.Length; ++j) {
217 var a = new BigInteger (values [i]);
218 var b = values [j];
219 var c = new BigInteger (b);
221 Assert.AreEqual (a.CompareTo (c), a.CompareTo (b), "#a_" + i + "_" + j);
223 Assert.AreEqual (a > c, a > b, "#b_" + i + "_" + j);
224 Assert.AreEqual (a < c, a < b, "#c_" + i + "_" + j);
225 Assert.AreEqual (a <= c, a <= b, "#d_" + i + "_" + j);
226 Assert.AreEqual (a == c, a == b, "#e_" + i + "_" + j);
227 Assert.AreEqual (a != c, a != b, "#f_" + i + "_" + j);
228 Assert.AreEqual (a >= c, a >= b, "#g_" + i + "_" + j);
230 Assert.AreEqual (c > a, b > a, "#ib_" + i + "_" + j);
231 Assert.AreEqual (c < a, b < a, "#ic_" + i + "_" + j);
232 Assert.AreEqual (c <= a, b <= a, "#id_" + i + "_" + j);
233 Assert.AreEqual (c == a, b == a, "#ie_" + i + "_" + j);
234 Assert.AreEqual (c != a, b != a, "#if_" + i + "_" + j);
235 Assert.AreEqual (c >= a, b >= a, "#ig_" + i + "_" + j);
240 [Test]
241 public void TestEquals () {
242 var a = new BigInteger (10);
243 var b = new BigInteger (10);
244 var c = new BigInteger (-10);
246 Assert.AreEqual (a, b, "#1");
247 Assert.AreNotEqual (a, c, "#2");
248 Assert.AreNotEqual (a, 10, "#3");
251 [Test]
252 public void ByteArrayCtor ()
254 try {
255 new BigInteger (null);
256 Assert.Fail ("#1");
257 } catch (ArgumentNullException) {}
259 Assert.AreEqual (0, (int)new BigInteger (new byte [0]), "#2");
262 [Test]
263 public void IntCtorRoundTrip ()
265 int[] values = new int [] {
266 int.MinValue, -0x2F33BB, -0x1F33, -0x33, 0, 0x33,
267 0x80, 0x8190, 0xFF0011, 0x1234, 0x11BB99, 0x44BB22CC,
268 int.MaxValue };
269 foreach (var val in values) {
270 var a = new BigInteger (val);
271 var b = new BigInteger (a.ToByteArray ());
273 Assert.AreEqual (val, (int)a, "#a_" + val);
274 Assert.AreEqual (val, (int)b, "#b_" + val);
278 [Test]
279 public void LongCtorRoundTrip ()
281 long[] values = new long [] {
282 0, long.MinValue, long.MaxValue, -1, 1L + int.MaxValue, -1L + int.MinValue, 0x1234, 0xFFFFFFFFL, 0x1FFFFFFFFL, -0xFFFFFFFFL, -0x1FFFFFFFFL,
283 0x100000000L, -0x100000000L, 0x100000001L, -0x100000001L };
284 foreach (var val in values) {
285 var a = new BigInteger (val);
286 var b = new BigInteger (a.ToByteArray ());
288 Assert.AreEqual (val, (long)a, "#a_" + val);
289 Assert.AreEqual (val, (long)b, "#b_" + val);
293 [Test]
294 public void ByteArrayCtorRoundTrip ()
296 var arr = new byte [] { 1,2,3,4,5,6,7,8,9 };
297 Assert.AreEqual (arr, new BigInteger (arr).ToByteArray (), "#1");
299 arr = new byte [] { 1,2,3,4,5,6,7,8,0xFF, 0x0};
300 Assert.AreEqual (arr, new BigInteger (arr).ToByteArray (), "#2");
302 arr = new byte [] { 1,2,3,4,5,6,7,8,9, 0xF0 };
303 Assert.AreEqual (arr, new BigInteger (arr).ToByteArray (), "#3");
305 arr = new byte [] { 1};
306 Assert.AreEqual (arr, new BigInteger (arr).ToByteArray (), "#4");
308 arr = new byte [] { 1,2 };
309 Assert.AreEqual (arr, new BigInteger (arr).ToByteArray (), "#5");
311 arr = new byte [] { 1,2,3 };
312 Assert.AreEqual (arr, new BigInteger (arr).ToByteArray (), "#6");
314 arr = new byte [] { 1,2,3,4 };
315 Assert.AreEqual (arr, new BigInteger (arr).ToByteArray (), "#7");
317 arr = new byte [] { 1,2,3,4,5 };
318 Assert.AreEqual (arr, new BigInteger (arr).ToByteArray (), "#8");
320 arr = new byte [] { 1,2,3,4,5,6 };
321 Assert.AreEqual (arr, new BigInteger (arr).ToByteArray (), "#9");
323 arr = new byte [] { 1,2,3,4,5,6,7 };
324 Assert.AreEqual (arr, new BigInteger (arr).ToByteArray (), "#10");
326 arr = new byte [] { 1,2,3,4,5 };
327 Assert.AreEqual (arr, new BigInteger (arr).ToByteArray (), "#11");
329 arr = new byte [] { 0 };
330 Assert.AreEqual (arr, new BigInteger (arr).ToByteArray (), "#12");
332 arr = new byte [] { 0xFF, 00 };
333 Assert.AreEqual (arr, new BigInteger (arr).ToByteArray (), "#13");
335 arr = new byte [] { 1, 0, 0, 0, 0, 0, };
336 Assert.AreEqual (new byte [1] {1}, new BigInteger (arr).ToByteArray (), "#14");
339 [Test]
340 public void TestIntCtorProperties ()
342 BigInteger a = new BigInteger (10);
343 Assert.IsTrue (a.IsEven, "#1");
344 Assert.IsFalse (a.IsOne, "#2");
345 Assert.IsFalse (a.IsPowerOfTwo, "#3");
346 Assert.IsFalse (a.IsZero, "#4");
347 Assert.AreEqual (1, a.Sign, "#5");
349 Assert.IsFalse (new BigInteger (11).IsEven, "#6");
350 Assert.IsTrue (new BigInteger (1).IsOne, "#7");
351 Assert.IsTrue (new BigInteger (32).IsPowerOfTwo, "#8");
352 Assert.IsTrue (new BigInteger (0).IsZero, "#9");
353 Assert.AreEqual (0, new BigInteger (0).Sign, "#10");
354 Assert.AreEqual (-1, new BigInteger (-99999).Sign, "#11");
356 Assert.IsFalse (new BigInteger (0).IsPowerOfTwo, "#12");
357 Assert.IsFalse (new BigInteger (-16).IsPowerOfTwo, "#13");
358 Assert.IsTrue (new BigInteger (1).IsPowerOfTwo, "#14");
361 /*[Test]
362 public void TestIntCtorToString ()
364 Assert.AreEqual ("5555", new BigInteger (5555).ToString (), "#1");
365 Assert.AreEqual ("-99999", new BigInteger (-99999).ToString (), "#2");
368 [Test]
369 public void TestToIntOperator ()
371 try {
372 int v = (int)new BigInteger (huge_a);
373 Assert.Fail ("#1");
374 } catch (OverflowException) {}
376 try {
377 int v = (int)new BigInteger (1L + int.MaxValue);
378 Assert.Fail ("#2");
379 } catch (OverflowException) {}
381 try {
382 int v = (int)new BigInteger (-1L + int.MinValue);
383 Assert.Fail ("#3");
384 } catch (OverflowException) {}
386 Assert.AreEqual (int.MaxValue, (int)new BigInteger (int.MaxValue), "#4");
387 Assert.AreEqual (int.MinValue, (int)new BigInteger (int.MinValue), "#5");
391 [Test]
392 public void TestToLongOperator ()
394 try {
395 long v = (long)new BigInteger (huge_a);
396 Assert.Fail ("#1");
397 } catch (OverflowException) {}
399 //long.MaxValue + 1
400 try {
401 long v = (long)new BigInteger (new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00 });
402 Assert.Fail ("#2");
403 } catch (OverflowException) {}
405 //TODO long.MinValue - 1
406 try {
407 long v = (long)new BigInteger (new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF });
408 Assert.Fail ("#3");
409 } catch (OverflowException) {}
411 Assert.AreEqual (long.MaxValue, (long)new BigInteger (long.MaxValue), "#4");
412 Assert.AreEqual (long.MinValue, (long)new BigInteger (long.MinValue), "#5");
415 [Test]
416 public void TestIntCtorToByteArray ()
418 Assert.AreEqual (new byte[] { 0xFF }, new BigInteger (-1).ToByteArray (), "#1");
419 Assert.AreEqual (new byte[] { 0xD4, 0xFE }, new BigInteger (-300).ToByteArray (), "#2");
420 Assert.AreEqual (new byte[] { 0x80, 0x00 }, new BigInteger (128).ToByteArray (), "#3");
421 Assert.AreEqual (new byte[] { 0x00, 0x60 }, new BigInteger (0x6000).ToByteArray (), "#4");
422 Assert.AreEqual (new byte[] { 0x00, 0x80, 0x00 }, new BigInteger (0x8000).ToByteArray (), "#5");
423 Assert.AreEqual (new byte[] { 0xDD, 0xBC, 0x00, 0x7A }, new BigInteger (0x7A00BCDD).ToByteArray (), "#6");
424 Assert.AreEqual (new byte[] { 0xFF, 0xFF, 0xFF, 0x7F }, new BigInteger (int.MaxValue).ToByteArray (), "#7");
425 Assert.AreEqual (new byte[] { 0x00, 0x00, 0x00, 0x80 }, new BigInteger (int.MinValue).ToByteArray (), "#8");
426 Assert.AreEqual (new byte[] { 0x01, 0x00, 0x00, 0x80 }, new BigInteger (int.MinValue + 1).ToByteArray (), "#9");
427 Assert.AreEqual (new byte[] { 0x7F }, new BigInteger (0x7F).ToByteArray (), "#10");
428 Assert.AreEqual (new byte[] { 0x45, 0xCC, 0xD0 }, new BigInteger (-0x2F33BB).ToByteArray (), "#11");
429 Assert.AreEqual (new byte[] { 0 }, new BigInteger (0).ToByteArray (), "#12");
432 [Test]
433 public void TestLongCtorToByteArray ()
435 Assert.AreEqual (new byte[] { 0x01 }, new BigInteger (0x01L).ToByteArray (), "#1");
436 Assert.AreEqual (new byte[] { 0x02, 0x01 }, new BigInteger (0x0102L).ToByteArray (), "#2");
437 Assert.AreEqual (new byte[] { 0x03, 0x02, 0x01 }, new BigInteger (0x010203L).ToByteArray (), "#3");
438 Assert.AreEqual (new byte[] { 0x04, 0x03, 0x2, 0x01 }, new BigInteger (0x01020304L).ToByteArray (), "#4");
439 Assert.AreEqual (new byte[] { 0x05, 0x04, 0x03, 0x2, 0x01 }, new BigInteger (0x0102030405L).ToByteArray (), "#5");
440 Assert.AreEqual (new byte[] { 0x06, 0x05, 0x04, 0x03, 0x2, 0x01 }, new BigInteger (0x010203040506L).ToByteArray (), "#6");
441 Assert.AreEqual (new byte[] { 0x07, 0x06, 0x05, 0x04, 0x03, 0x2, 0x01 }, new BigInteger (0x01020304050607L).ToByteArray (), "#7");
442 Assert.AreEqual (new byte[] { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x2, 0x01 }, new BigInteger (0x0102030405060708L).ToByteArray (), "#8");
444 Assert.AreEqual (new byte[] { 0xFF }, new BigInteger (-0x01L).ToByteArray (), "#1m");
445 Assert.AreEqual (new byte[] { 0xFE, 0xFE}, new BigInteger (-0x0102L).ToByteArray (), "#2m");
446 Assert.AreEqual (new byte[] { 0xFD, 0xFD, 0xFE }, new BigInteger (-0x010203L).ToByteArray (), "#3m");
447 Assert.AreEqual (new byte[] { 0xFC, 0xFC, 0xFD, 0xFE}, new BigInteger (-0x01020304L).ToByteArray (), "#4m");
448 Assert.AreEqual (new byte[] { 0xFB, 0xFB, 0xFC, 0xFD, 0xFE }, new BigInteger (-0x0102030405L).ToByteArray (), "#5m");
449 Assert.AreEqual (new byte[] { 0xFA, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE }, new BigInteger (-0x010203040506L).ToByteArray (), "#6m");
450 Assert.AreEqual (new byte[] { 0xF9, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE }, new BigInteger (-0x01020304050607L).ToByteArray (), "#7m");
451 Assert.AreEqual (new byte[] { 0xF8, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE }, new BigInteger (-0x0102030405060708L).ToByteArray (), "#8m");
454 Assert.AreEqual (new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, new BigInteger (long.MaxValue).ToByteArray (), "#9");
455 Assert.AreEqual (new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, new BigInteger (long.MinValue).ToByteArray (), "#10");
457 Assert.AreEqual (new byte[] { 0xFF, 0xFF, 0xFF, 0x7F, 0xFF }, new BigInteger (-2147483649L).ToByteArray (), "11");
462 [Test]
463 public void IComparable () {
464 var a = new BigInteger (99);
465 Assert.AreEqual (-1, a.CompareTo (100), "#1");
466 Assert.AreEqual (1, a.CompareTo (null), "#2");