Facilitate the merge
[mono.git] / mcs / class / corlib / Test / System / ArrayTest.cs
1 // ArrayTest.cs - NUnit Test Cases for the System.Array class
2 //
3 // David Brandt (bucky@keystreams.com)
4 // Eduardo Garcia (kiwnix@yahoo.es)
5 // 
6 // (C) Ximian, Inc.  http://www.ximian.com
7 // Copyright (C) 2004 Novell (http://www.novell.com)
8 // 
9
10 using NUnit.Framework;
11 using System;
12 using System.Collections;
13 using System.Globalization;
14
15 #if NET_2_0
16 using System.Collections.Generic;
17 #endif
18
19 namespace MonoTests.System
20 {
21         //Auxiliary Things
22         enum enua  {hola,adios,mas,menos};
23
24         class AClass
25         {
26                 public AClass()
27                 {
28
29                 }
30         }
31
32         class BClass : AClass
33         {
34         }
35
36         class CClass : AClass
37         {
38         }
39
40         struct AStruct
41         {
42                 public string s;
43                 public string a;
44         }
45         
46         class DataEqual
47         {
48                 public override bool Equals (object obj)
49                 {
50                         return true;
51                 }
52
53                 public override int GetHashCode ()
54                 {
55                         return 0;
56                 }
57         }
58                 
59         //End Auxiliary Things
60
61 [TestFixture]
62 public class ArrayTest
63 {
64         char [] arrsort = {'d', 'b', 'f', 'e', 'a', 'c'};
65
66         public ArrayTest() {}
67
68         [Test]
69         public void TestIsFixedSize() {
70                 char[] a1 = {'a'};
71                 Assert.IsTrue (a1.IsFixedSize, "All arrays are fixed");
72         }
73         
74         [Test]
75         public void TestIsReadOnly() {
76                 char[] a1 = {'a'};
77                 Assert.IsTrue (!a1.IsReadOnly, "No array is readonly");
78         }
79
80         [Test]
81         public void TestIsSynchronized() {
82                 char[] a1 = {'a'};
83                 Assert.IsTrue (!a1.IsSynchronized, "No array is synchronized");
84         }
85
86         [Test]
87         public void TestLength() {
88                 {
89                         char[] a1 = { };
90                         Assert.AreEqual (0, a1.Length, "Zero length array");
91                 }
92                 {
93                         char[] a1 = {'c'};
94                         Assert.AreEqual (1, a1.Length, "One-length array");
95                 }
96                 {
97                         char[] a1 = {'c', 'c'};
98                         Assert.AreEqual (2, a1.Length, "Two-length array");
99                 }
100         }
101
102         [Test]
103         public void TestRank() {
104                 char[] a1 = { 'c', 'd', 'e' };
105                 Assert.AreEqual (1, a1.Rank, "Rank one");
106
107                 char[,] a2 = new Char[3,3];
108                 Assert.AreEqual (2, a2.Rank, "Rank two");
109
110                 char[,,] a3 = new Char[3,3,3];
111                 Assert.AreEqual (3, a3.Rank, "Rank three");
112         }
113
114         [Test]
115         public void TestBinarySearch1() {
116                 bool errorThrown = false;
117                 try {
118                         Array.BinarySearch(null, "blue");
119                 } catch (ArgumentNullException) {
120                         errorThrown = true;
121                 }
122                 Assert.IsTrue (errorThrown, "#B01");
123                 errorThrown = false;
124                 try {
125                         char[,] c1 = new Char[2,2];
126                         Array.BinarySearch(c1, "needle");
127                 } catch (RankException) {
128                         errorThrown = true;
129                 }
130                 Assert.IsTrue (errorThrown, "#B02");
131
132                 {
133                         char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
134                         Assert.IsTrue (Array.BinarySearch(arr, 'c') >= 3, "#B05");
135                         Assert.IsTrue (Array.BinarySearch(arr, 'c') < 6, "#B06");
136                 }
137                 {
138                         char[] arr = {'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
139                         Assert.AreEqual (-4, Array.BinarySearch(arr, 'c'), "#B07");
140                 }
141                 {
142                         char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
143                         Assert.AreEqual (-9, Array.BinarySearch(arr, 'e'), "#B08");
144                 }
145         }
146
147         [Test]
148         public void TestBinarySearch2() {
149                 bool errorThrown = false;
150                 try {
151                         Array.BinarySearch(null, 0, 1, "blue");
152                 } catch (ArgumentNullException) {
153                         errorThrown = true;
154                 }
155                 Assert.IsTrue (errorThrown, "#B20");
156                 errorThrown = false;
157                 try {
158                         char[,] c1 = new Char[2,2];
159                         Array.BinarySearch(c1, 0, 1, "needle");
160                 } catch (RankException) {
161                         errorThrown = true;
162                 }
163                 Assert.IsTrue (errorThrown, "#B21");
164                 errorThrown = false;
165                 try {
166                         char[] c1 = {'a'};
167                         Array.BinarySearch(c1, -1, 1, 'a');
168                 } catch (ArgumentOutOfRangeException) {
169                         errorThrown = true;
170                 }
171                 Assert.IsTrue (errorThrown, "#B22");
172                 errorThrown = false;
173                 try {
174                         char[] c1 = {'a'};
175                         Array.BinarySearch(c1, 0, -1, 'a');
176                 } catch (ArgumentOutOfRangeException) {
177                         errorThrown = true;
178                 }
179                 Assert.IsTrue (errorThrown, "#B23");
180                 errorThrown = false;
181                 try {
182                         char[] c1 = {'a'};
183                         Array.BinarySearch(c1, 0, 4, 'a');
184                 } catch (ArgumentException) {
185                         errorThrown = true;
186                 }
187                 Assert.IsTrue (errorThrown, "#B24");
188
189                 {
190                         char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
191                         Assert.IsTrue (Array.BinarySearch(arr, 2, 8, 'c') >= 5, "#B26");
192                         Assert.IsTrue (Array.BinarySearch(arr, 2, 8, 'c') < 8, "#B27");
193                 }
194                 {
195                         char[] arr = {'z', 'z', 'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
196                         Assert.AreEqual (-6, Array.BinarySearch(arr, 2, 8, 'c'), "#B28");
197                 }
198                 {
199                         char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
200                         Assert.AreEqual (-11, Array.BinarySearch(arr, 2, 8, 'e'), "#B29");
201                 }
202         }
203
204         public void TestBinarySearch3()
205         {
206                 int[] array = new int[100];
207
208                 for (int i = 0; i < 100; i++)
209                         array[i] = 10;
210
211                 Assert.AreEqual (49, Array.BinarySearch(array, 10), "#B30");
212         }
213
214         [Test]
215         public void BinarySearch_NullValue () 
216         {
217                 int[] array = new int[1];
218                 Assert.AreEqual (-1, Array.BinarySearch (array, null), "I=a,o");
219                 Assert.AreEqual (-1, Array.BinarySearch (array, null, null), "I=a,o,c");
220                 Assert.AreEqual (-1, Array.BinarySearch (array, 0, 1, null), "I=a,i,i,o");
221                 Assert.AreEqual (-1, Array.BinarySearch (array, 0, 1, null, null), "I=a,i,i,o,c");
222
223                 object[] o = new object [3] { this, this, null };
224                 Assert.AreEqual (-1, Array.BinarySearch (o, null), "O=a,o");
225                 Assert.AreEqual (-1, Array.BinarySearch (o, null, null), "O=a,o,c");
226                 Assert.AreEqual (-1, Array.BinarySearch (o, 0, 3, null), "O=a,i,i,o");
227                 Assert.AreEqual (-1, Array.BinarySearch (o, 0, 3, null, null), "O=a,i,i,o,c");
228         }
229
230         // TODO - testBinarySearch with explicit IComparer args
231
232         [Test]
233         public void TestClear() {
234                 bool errorThrown = false;
235                 try {
236                         Array.Clear(null, 0, 1);
237                 } catch (ArgumentNullException) {
238                         errorThrown = true;
239                 }
240                 Assert.IsTrue (errorThrown, "#C01");
241
242                 int[] i1 = { 1, 2, 3, 4 };
243                 {
244                         int[] compare = {1,2,3,4};
245                         Assert.AreEqual (compare[0], i1[0], "#C02");
246                         Assert.AreEqual (compare[1], i1[1], "#C03");
247                         Assert.AreEqual (compare[2], i1[2], "#C04");
248                         Assert.AreEqual (compare[3], i1[3], "#C05");
249                 }
250                 Array.Clear(i1, 3, 1);
251                 {
252                         int[] compare = {1,2,3,0};
253                         Assert.AreEqual (compare[0], i1[0], "#C06");
254                         Assert.AreEqual (compare[1], i1[1], "#C07");
255                         Assert.AreEqual (compare[2], i1[2], "#C08");
256                         Assert.AreEqual (compare[3], i1[3], "#C09");
257                 }
258                 Array.Clear(i1, 1, 1);
259                 {
260                         int[] compare = {1,0,3,0};
261                         Assert.AreEqual (compare[0], i1[0], "#C10");
262                         Assert.AreEqual (compare[1], i1[1], "#C11");
263                         Assert.AreEqual (compare[2], i1[2], "#C12");
264                         Assert.AreEqual (compare[3], i1[3], "#C13");
265                 }
266                 Array.Clear(i1, 1, 3);
267                 {
268                         int[] compare = {1,0,0,0};
269                         Assert.AreEqual (compare[0], i1[0], "#C14");
270                         Assert.AreEqual (compare[1], i1[1], "#C15");
271                         Assert.AreEqual (compare[2], i1[2], "#C16");
272                         Assert.AreEqual (compare[3], i1[3], "#C17");
273                 }
274
275                 string[] s1 = { "red", "green", "blue" };
276                 Array.Clear(s1, 0, 3);
277                 {
278                         string[] compare = {null, null, null};
279                         Assert.AreEqual (compare[0], s1[0], "#C18");
280                         Assert.AreEqual (compare[1], s1[1], "#C19");
281                         Assert.AreEqual (compare[2], s1[2], "#C20");
282                 }
283         }
284
285         [Test]
286         public void TestClone() {
287                 char[] c1 = {'a', 'b', 'c'};
288                 char[] c2 = (char[])c1.Clone();
289                 Assert.AreEqual (c1[0], c2[0], "#D01");
290                 Assert.AreEqual (c1[1], c2[1], "#D02");
291                 Assert.AreEqual (c1[2], c2[2], "#D03");
292
293                 char[] d10 = {'a', 'b'};
294                 char[] d11 = {'a', 'c'};
295                 char[] d12 = {'b', 'c'};
296                 char[][] d1 = {d10, d11, d12};
297                 char[][] d2 = (char[][])d1.Clone();
298                 Assert.AreEqual (d1[0], d2[0], "#D04");
299                 Assert.AreEqual (d1[1], d2[1], "#D05");
300                 Assert.AreEqual (d1[2], d2[2], "#D06");
301
302                 d1[0][0] = 'z';
303                 Assert.AreEqual (d1[0], d2[0], "#D07");
304         }
305
306         [Test] public void TestIndexer ()
307         {
308                 int [] a = new int [10];
309                 IList b = a;
310                 try {
311                         object c = b [-1];
312                         Assert.Fail ("IList.this [-1] should throw");
313                 } catch (IndexOutOfRangeException) {
314                         // Good
315                 } catch (Exception){
316                         Assert.Fail ("Should have thrown an IndexOutOfRangeException");
317                 }
318         }
319                 
320         [Test]
321         public void TestCopy() {
322                 {
323                         bool errorThrown = false;
324                         try {
325                                 Char[] c1 = {};
326                                 Array.Copy(c1, null, 1);
327                         } catch (ArgumentNullException) {
328                                 errorThrown = true;
329                         }
330                         Assert.IsTrue (errorThrown, "#E01");
331                 }
332                 {
333                         bool errorThrown = false;
334                         try {
335                                 Char[] c1 = {};
336                                 Array.Copy(null, c1, 1);
337                         } catch (ArgumentNullException) {
338                                 errorThrown = true;
339                         }
340                         Assert.IsTrue (errorThrown, "#E02");
341                 }
342                 {
343                         bool errorThrown = false;
344                         try {
345                                 Char[] c1 = new Char[1];
346                                 Char[,] c2 = new Char[1,1];
347                                 Array.Copy(c1, c2, 1);
348                         } catch (RankException) {
349                                 errorThrown = true;
350                         }
351                         Assert.IsTrue (errorThrown, "#E03");
352                 }
353                 {
354                         bool errorThrown = false;
355                         try {
356                                 Char[] c1 = new Char[1];
357                                 string[] s1 = new String[1];
358                                 Array.Copy(c1, s1, 1);
359                         } catch (ArrayTypeMismatchException) {
360                                 errorThrown = true;
361                         }
362                         Assert.IsTrue (errorThrown, "#E04");
363                 }
364                 {
365                         bool errorThrown = false;
366                         try {
367                                 Char[] c1 = new Char[1];
368                                 Object[] o1 = new Object[1];
369                                 o1[0] = "hello";
370                                 Array.Copy(o1, c1, 1);
371                         } catch (InvalidCastException) {
372                                 errorThrown = true;
373                         }
374                         Assert.IsTrue (errorThrown, "#E05");
375                 }
376                 {
377                         bool errorThrown = false;
378                         try {
379                                 Char[] c1 = new Char[1];
380                                 Char[] c2 = new Char[1];
381                                 Array.Copy(c1, c2, -1);
382                         } catch (ArgumentOutOfRangeException) {
383                                 errorThrown = true;
384                         }
385                         Assert.IsTrue (errorThrown, "#E06");
386                 }
387                 {
388                         bool errorThrown = false;
389                         try {
390                                 Char[] c1 = new Char[1];
391                                 Char[] c2 = new Char[2];
392                                 Array.Copy(c1, c2, 2);
393                         } catch (ArgumentException) {
394                                 errorThrown = true;
395                         }
396                         Assert.IsTrue (errorThrown, "#E07");
397                 }
398                 {
399                         bool errorThrown = false;
400                         try {
401                                 Char[] c1 = new Char[1];
402                                 Char[] c2 = new Char[2];
403                                 Array.Copy(c2, c1, 2);
404                         } catch (ArgumentException) {
405                                 errorThrown = true;
406                         }
407                         Assert.IsTrue (errorThrown, "#E08");
408                 }
409
410                 char[] orig = {'a', 'b', 'd', 'a'};
411                 char[] copy = new Char[4];
412                 Array.Copy(orig, copy, 4);
413                 for (int i = 0; i < orig.Length; i++) {
414                         Assert.AreEqual (orig[i], copy[i], "#E09(" + i + ")");
415                 }
416                 Array.Clear(copy, 0, copy.Length);
417                 for (int i = 0; i < orig.Length; i++) {
418                         Assert.AreEqual ((char)0, copy[i], "#E10(" + i + ")");
419                 }
420                 Array.Copy(orig, copy, 2);
421                 Assert.AreEqual (orig[0], copy[0], "#E11");
422                 Assert.AreEqual (orig[1], copy[1], "#E12");
423                 Assert.IsTrue (orig[2] != copy[2], "#E13");
424                 Assert.IsTrue (orig[3] != copy[3], "#E14");
425         }
426
427         [Test]
428         public void TestCopy2() {
429                 {
430                         bool errorThrown = false;
431                         try {
432                                 Char[] c1 = new Char[2];
433                                 Char[] c2 = new Char[2];
434                                 Array.Copy(c2, 1, c1, 0, 2);
435                         } catch (ArgumentException) {
436                                 errorThrown = true;
437                         }
438                         Assert.IsTrue (errorThrown, "#E31");
439                 }
440                 {
441                         bool errorThrown = false;
442                         try {
443                                 Char[] c1 = new Char[2];
444                                 Char[] c2 = new Char[2];
445                                 Array.Copy(c2, 0, c1, 1, 2);
446                         } catch (ArgumentException) {
447                                 errorThrown = true;
448                         }
449                         Assert.IsTrue (errorThrown, "#E32");
450                 }
451                 
452                 char[] orig = {'a', 'b', 'd', 'a'};
453                 char[] copy = new Char[4];
454                 Array.Copy(orig, 1, copy, 1, 3);
455                 Assert.IsTrue (copy[0] != orig[0], "#E33");
456                 for (int i = 1; i < orig.Length; i++) {
457                         Assert.AreEqual (orig[i], copy[i], "#E34(" + i + ")");
458                 }
459                 Array.Clear(copy, 0, copy.Length);
460                 Array.Copy(orig, 1, copy, 0, 2);
461                 Assert.AreEqual (orig[1], copy[0], "#E35");
462                 Assert.AreEqual (orig[2], copy[1], "#E36");
463                 Assert.IsTrue (copy[2] != orig[2], "#E37");
464                 Assert.IsTrue (copy[3] != orig[3], "#E38");
465         }
466
467         [Test]
468         [ExpectedException (typeof (InvalidCastException))]
469         public void Copy_InvalidCast () {
470                 object[] arr1 = new object [10];
471                 Type[] arr2 = new Type [10];
472
473                 arr1 [0] = new object ();
474
475                 Array.Copy (arr1, 0, arr2, 0, 10);
476         }
477
478         [Test]
479         public void TestCopyTo() {
480                 {
481                         bool errorThrown = false;
482                         try {
483                                 Char[] c1 = new Char[2];
484                                 c1.CopyTo(null, 2);
485                         } catch (ArgumentNullException) {
486                                 errorThrown = true;
487                         }
488                         Assert.IsTrue (errorThrown, "#E61");
489                 }
490                 {
491                         bool errorThrown = false;
492                         try {
493                                 Char[] c1 = new Char[2];
494                                 Char[,] c2 = new Char[2,2];
495                                 c1.CopyTo(c2, 2);
496                         } catch (ArgumentException) {
497                                 errorThrown = true;
498                         }
499 #if TARGET_JVM // This is really implementation dependent behaviour.
500                         catch (RankException) {
501                                 errorThrown = true;
502                         }
503 #endif // TARGET_JVM
504                         Assert.IsTrue (errorThrown, "#E62");
505                 }
506                 {
507                         bool errorThrown = false;
508                         try {
509                                 Char[,] c1 = new Char[2,2];
510                                 Char[] c2 = new Char[2];
511                                 c1.CopyTo(c2, -1);
512                         } catch (RankException) {
513                                 errorThrown = true;
514                         }
515                         Assert.IsTrue (errorThrown, "#E63");
516                 }
517                 {
518                         bool errorThrown = false;
519                         try {
520                                 Char[,] c1 = new Char[2,2];
521                                 Char[] c2 = new Char[2];
522                                 c1.CopyTo(c2, 2);
523                         } catch (RankException) {
524                                 errorThrown = true;
525                         }
526                         Assert.IsTrue (errorThrown, "#E64");
527                 }
528                 {
529                         bool errorThrown = false;
530                         try {
531                                 Char[] c1 = new Char[2];
532                                 Char[] c2 = new Char[2];
533                                 c1.CopyTo(c2, -1);
534                         } catch (ArgumentOutOfRangeException) {
535                                 errorThrown = true;
536                         }
537                         Assert.IsTrue (errorThrown, "#E65");
538                 }
539                 {
540                         bool errorThrown = false;
541                         try {
542                                 Char[] c1 = new Char[2];
543                                 Char[] c2 = new Char[2];
544                                 c1.CopyTo(c2, 3);
545                         } catch (ArgumentException) {
546                                 errorThrown = true;
547                         }
548                         Assert.IsTrue (errorThrown, "#E66");
549                 }
550                 {
551                         bool errorThrown = false;
552                         try {
553                                 Char[] c1 = new Char[2];
554                                 Char[] c2 = new Char[2];
555                                 c1.CopyTo(c2, 1);
556                         } catch (ArgumentException) {
557                                 errorThrown = true;
558                         }
559                         Assert.IsTrue (errorThrown, "#E67");
560                 }
561
562                 {
563                         bool errorThrown = false;
564                         try {
565                                 String[] c1 = new String[2];
566                                 // TODO: this crashes mono if there are null
567                                 // values in the array.
568                                 c1[1] = "hey";
569                                 c1[0] = "you";
570                                 Char[] c2 = new Char[2];
571                                 c2[1] = 'a';
572                                 c2[0] = 'z';
573                                 c1.CopyTo(c2, 0);
574                         } catch (ArrayTypeMismatchException) {
575                                 errorThrown = true;
576                         }
577                         Assert.IsTrue (errorThrown, "#E68");
578                 }
579
580                 Char[] orig = {'a', 'b', 'c', 'd'};
581                 Char[] copy = new Char[10];
582                 Array.Clear(copy, 0, copy.Length);
583                 orig.CopyTo(copy, 3);
584                 Assert.AreEqual ((char)0, copy[0], "#E69");
585                 Assert.AreEqual ((char)0, copy[1], "#E70");
586                 Assert.AreEqual ((char)0, copy[2], "#E71");
587                 Assert.AreEqual (orig[0], copy[3], "#E72");
588                 Assert.AreEqual (orig[1], copy[4], "#E73");
589                 Assert.AreEqual (orig[2], copy[5], "#E74");
590                 Assert.AreEqual (orig[3], copy[6], "#E75");
591                 Assert.AreEqual ((char)0, copy[7], "#E76");
592                 Assert.AreEqual ((char)0, copy[8], "#E77");
593                 Assert.AreEqual ((char)0, copy[9], "#E78");
594
595                 {
596                         // The following is valid and must not throw an exception.
597                         bool errorThrown = false;
598                         try {
599                                 int[] src = new int [0];
600                                 int[] dest = new int [0];
601                                 src.CopyTo (dest, 0);
602                         } catch (ArgumentException) {
603                                 errorThrown = true;
604                         }
605                         Assert.IsTrue (!errorThrown, "#E79");
606                 }
607
608                 {
609                         // bug #38812
610                         bool errorThrown = false;
611                         try {
612                                 CClass[] src = new CClass [] { new CClass () };
613                                 BClass[] dest = new BClass [1];
614
615                                 src.CopyTo (dest, 0);
616
617                         } catch (ArrayTypeMismatchException) {
618                                 errorThrown = true;
619                         }
620                         Assert.IsTrue (errorThrown, "#E80");
621                 }
622         }
623
624         [Test]
625         public void TestCreateInstance() {
626                 {
627                         bool errorThrown = false;
628                         try {
629                                 Array.CreateInstance(null, 12);
630                         } catch (ArgumentNullException) {
631                                 errorThrown = true;
632                         }
633                         Assert.IsTrue (errorThrown, "#F01");
634                 }
635                 {
636                         bool errorThrown = false;
637                         try {
638                                 Array.CreateInstance(Type.GetType("System.Char"), -3);
639                         } catch (ArgumentOutOfRangeException) {
640                                 errorThrown = true;
641                         }
642                         Assert.IsTrue (errorThrown, "#F02");
643                 }
644                 {
645                         bool errorThrown = false;
646                         try {
647                                 Array.CreateInstance(Type.GetType("System.Char"), (int [])null);
648                         } catch (ArgumentNullException) {
649                                 errorThrown = true;
650                         }
651                         Assert.IsTrue (errorThrown, "#F03a");
652                 }
653 #if NET_1_1
654                 {
655                         bool errorThrown = false;
656                         try {
657                                 Array.CreateInstance(Type.GetType("System.Char"), (int [])null);
658                         } catch (ArgumentNullException) {
659                                 errorThrown = true;
660                         }
661                         Assert.IsTrue (errorThrown, "#F03b");
662                 }
663 #endif
664 #if !TARGET_JVM // Arrays lower bounds are not supported for TARGET_JVM
665                 {
666                         bool errorThrown = false;
667                         try {
668                                 Array.CreateInstance(Type.GetType("System.Char"), null, null);
669                         } catch (ArgumentNullException) {
670                                 errorThrown = true;
671                         }
672                         Assert.IsTrue (errorThrown, "#F04");
673                 }
674 #endif // TARGET_JVM
675                 {
676                         bool errorThrown = false;
677                         try {
678                                 int[] lengths = new int [0];
679                                 Array.CreateInstance(Type.GetType("System.Char"), lengths);
680                         } catch (ArgumentException) {
681                                 errorThrown = true;
682                         }
683                         Assert.IsTrue (errorThrown, "#F05");
684                 }
685 #if !TARGET_JVM // CreateInstance with lower bounds not supported for TARGET_JVM
686                 {
687                         bool errorThrown = false;
688                         try {
689                                 int[] lengths = new int [1];
690                                 int[] bounds = new int [2];
691                                 Array.CreateInstance(Type.GetType("System.Char"), lengths, bounds);
692                                 errorThrown = true;
693                         } catch (ArgumentException) {
694                                 errorThrown = true;
695                         }
696                         Assert.IsTrue (errorThrown, "#F06");
697                 }
698
699                 char[] c1 = (char[])Array.CreateInstance(Type.GetType("System.Char"), 12);
700                 Assert.AreEqual (12, c1.Length, "#F07");
701
702                 Array c2 = Array.CreateInstance(Type.GetType("System.Char"), 12, 5);
703                 Assert.AreEqual (2, c2.Rank, "#F08");
704                 Assert.AreEqual (60, c2.Length, "#F09");
705
706
707                 {
708                         int[] lengths = { 3 };
709                         int[] bounds = { 5 };
710                         int[] src = { 512, 718, 912 };
711                         Array array = Array.CreateInstance(typeof(int), lengths, bounds);
712
713                         Assert.AreEqual (3, array.Length, "#F10");
714                         Assert.AreEqual (5, array.GetLowerBound(0), "#F11");
715                         Assert.AreEqual (7, array.GetUpperBound(0), "#F12");
716
717                         src.CopyTo (array, 5);
718
719                         for (int i = 0; i < src.Length; i++)
720                                 Assert.AreEqual (src[i], array.GetValue(i+5), "#F13(" + i + ")");
721                 }
722
723                 // Test that a 1 dimensional array with 0 lower bound is the
724                 // same as an szarray
725                 Type szarrayType = new int [10].GetType ();
726                 Assert.IsTrue (szarrayType == (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0})).GetType ());
727                 Assert.IsTrue (szarrayType != (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {1})).GetType ());
728 #endif // TARGET_JVM
729         }
730         
731         [Test]
732         [ExpectedException (typeof (ArgumentNullException))]
733         public void TestCreateInstance2 ()
734         {
735                 Array.CreateInstance (typeof (Int32), (int[])null);
736         }
737
738         [Test]
739 #if NET_2_0
740         [ExpectedException (typeof (ArgumentNullException))]
741 #else
742         [ExpectedException (typeof (NullReferenceException))]
743 #endif
744         public void TestCreateInstance2b ()
745         {
746                 Array.CreateInstance (typeof (Int32), (long[])null);
747         }
748
749         [Test]
750         public void TestGetEnumerator() {
751                 String[] s1 = {"this", "is", "a", "test"};
752                 IEnumerator en = s1.GetEnumerator ();
753                 Assert.IsNotNull (en, "#G01");
754
755                 Assert.IsTrue (en.MoveNext (), "#G02");
756                 Assert.AreEqual ("this", en.Current, "#G03");
757                 Assert.IsTrue (en.MoveNext (), "#G04");
758                 Assert.AreEqual ("is", en.Current, "#G05");
759                 Assert.IsTrue (en.MoveNext (), "#G06");
760                 Assert.AreEqual ("a", en.Current, "#G07");
761                 Assert.IsTrue (en.MoveNext (), "#G08");
762                 Assert.AreEqual ("test", en.Current, "#G09");
763                 Assert.IsTrue (!en.MoveNext (), "#G10");
764
765                 en.Reset ();
766                 Assert.IsTrue (en.MoveNext (), "#G11");
767                 Assert.AreEqual ("this", en.Current, "#G12");
768
769                 // mutation does not invalidate array enumerator!
770                 s1.SetValue ("change", 1);
771                 Assert.IsTrue (en.MoveNext (), "#G13");
772                 Assert.AreEqual ("change", en.Current, "#G14");
773         }
774
775         [Test]
776         public void TestGetEnumeratorMultipleDimension() {
777                 String[,] s1 = {{"this", "is"}, {"a", "test"}};
778                 IEnumerator en = s1.GetEnumerator ();
779                 Assert.IsNotNull (en, "#AA01");
780
781                 Assert.IsTrue (en.MoveNext (), "#AA02");
782                 Assert.AreEqual ("this", en.Current, "#AA03");
783                 Assert.IsTrue (en.MoveNext (), "#AA04");
784                 Assert.AreEqual ("is", en.Current, "#AA05");
785                 Assert.IsTrue (en.MoveNext (), "#AA06");
786                 Assert.AreEqual ("a", en.Current, "#AA07");
787                 Assert.IsTrue (en.MoveNext (), "#AA08");
788                 Assert.AreEqual ("test", en.Current, "#AA09");
789                 Assert.IsTrue (!en.MoveNext (), "#AA10");
790
791                 en.Reset ();
792                 Assert.IsTrue (en.MoveNext (), "#AA11");
793                 Assert.AreEqual ("this", en.Current, "#AA12");
794
795                 int[] idxs = {0,1};
796                 // mutation does not invalidate array enumerator!
797                 s1.SetValue ("change", idxs);
798                 Assert.IsTrue (en.MoveNext (), "#AA13");
799                 Assert.AreEqual ("change", en.Current, "#AA14");
800         }
801
802         [Test]
803         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
804         public void TestGetEnumeratorNonZeroLowerBounds() {
805                 int[] myLengthsArray = new int[2] { 3, 5 };
806                 int[] myBoundsArray = new int[2] { 2, 3 };
807
808                 Array myArray=Array.CreateInstance( typeof(String), myLengthsArray, myBoundsArray );
809                 for ( int i = myArray.GetLowerBound(0); i <= myArray.GetUpperBound(0); i++ )
810                         for ( int j = myArray.GetLowerBound(1); j <= myArray.GetUpperBound(1); j++ )  {
811                                 int[] myIndicesArray = new int[2] { i, j };
812                                 myArray.SetValue( Convert.ToString(i) + j, myIndicesArray );
813                         }
814                 IEnumerator en = myArray.GetEnumerator ();
815                 Assert.IsNotNull (en, "#AB01");
816
817                 // check the first couple of values
818                 Assert.IsTrue (en.MoveNext (), "#AB02");
819                 Assert.AreEqual ("23", en.Current, "#AB03");
820                 Assert.IsTrue (en.MoveNext (), "#AB04");
821                 Assert.AreEqual ("24", en.Current, "#AB05");
822
823                 // then check the last element's value
824                 string lastElement;
825                 do {  
826                         lastElement = (string)en.Current;
827                 } while (en.MoveNext());
828                 Assert.AreEqual ("47", lastElement, "#AB06");
829         }
830
831         [Test]
832         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
833         public void TestIList_Add () {
834                 int[] myLengthsArray = new int[2] { 3, 5 };
835                 int[] myBoundsArray = new int[2] { 2, 3 };
836
837                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
838                 try {
839                         ((IList)myArray).Add ("can not");
840                         Assert.Fail ("IList.Add should throw");
841                 }
842                 catch (NotSupportedException) {
843                         return;
844                 }
845                 catch (Exception) {
846                         Assert.Fail ("IList.Add threw wrong exception type");
847                 }
848
849                 Assert.Fail ("IList.Add shouldn't get this far");
850         }
851
852         [Test]
853         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
854         public void TestIList_Insert () {
855                 int[] myLengthsArray = new int[2] { 3, 5 };
856                 int[] myBoundsArray = new int[2] { 2, 3 };
857
858                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
859                 try {
860                         ((IList)myArray).Insert (0, "can not");
861                         Assert.Fail ("IList.Insert should throw");
862                 }
863                 catch (NotSupportedException) {
864                         return;
865                 }
866                 catch (Exception) {
867                         Assert.Fail ("IList.Insert threw wrong exception type");
868                 }
869
870                 Assert.Fail ("IList.Insert shouldn't get this far");
871         }
872
873         [Test]
874         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
875         public void TestIList_Remove () {
876                 int[] myLengthsArray = new int[2] { 3, 5 };
877                 int[] myBoundsArray = new int[2] { 2, 3 };
878
879                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
880                 try {
881                         ((IList)myArray).Remove ("can not");
882                         Assert.Fail ("IList.Remove should throw");
883                 }
884                 catch (NotSupportedException) {
885                         return;
886                 }
887                 catch (Exception) {
888                         Assert.Fail ("IList.Remove threw wrong exception type");
889                 }
890
891                 Assert.Fail ("IList.Remove shouldn't get this far");
892         }
893
894         [Test]
895         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
896         public void TestIList_RemoveAt () {
897                 int[] myLengthsArray = new int[2] { 3, 5 };
898                 int[] myBoundsArray = new int[2] { 2, 3 };
899
900                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
901                 try {
902                         ((IList)myArray).RemoveAt (0);
903                         Assert.Fail ("IList.RemoveAt should throw");
904                 }
905                 catch (NotSupportedException) {
906                         return;
907                 }
908                 catch (Exception) {
909                         Assert.Fail ("IList.RemoveAt threw wrong exception type");
910                 }
911
912                 Assert.Fail ("IList.RemoveAt shouldn't get this far");
913         }
914
915         [Test]
916         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
917         public void TestIList_Contains () {
918                 int[] myLengthsArray = new int[2] { 3, 5 };
919                 int[] myBoundsArray = new int[2] { 2, 3 };
920
921                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
922
923                 try {
924                         bool b = ((IList)myArray).Contains ("23");
925                         Assert.Fail ("IList.Contains should throw with multi-dimensional arrays");
926                 }
927                 catch (RankException) {
928                         int[] iArr = new int[3] { 1, 2, 3};
929                         // check the first and last items
930                         Assert.IsTrue (((IList)iArr).Contains (1), "AC01");
931                         Assert.IsTrue (((IList)iArr).Contains (3), "AC02");
932
933                         // and one that is definately not there
934                         Assert.IsTrue (!((IList)iArr).Contains (42), "AC03");
935                         return;
936                 }
937
938                 Assert.Fail ("Should not get here");
939         }
940
941         [Test]
942         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
943         public void TestIList_IndexOf () {
944                 int[] myLengthsArray = new int[2] { 3, 5 };
945                 int[] myBoundsArray = new int[2] { 2, 3 };
946
947                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
948
949                 try {
950                         bool b = ((IList)myArray).Contains ("23");
951                         Assert.Fail ("IList.Contains should throw with multi-dimensional arrays");
952                 }
953                 catch (RankException) {
954                         int[] iArr = new int[3] { 1, 2, 3};
955                         // check the first and last items
956                         Assert.AreEqual (0, ((IList)iArr).IndexOf (1), "AD01");
957                         Assert.AreEqual (2, ((IList)iArr).IndexOf (3), "AD02");
958
959                         // and one that is definately not there
960                         Assert.AreEqual (-1, ((IList)iArr).IndexOf (42), "AD03");
961                 }
962                 catch (Exception e) {
963                         Assert.Fail ("Unexpected exception: " + e.ToString());
964                 }
965
966                 // check that wierd case whem lowerbound is Int32.MinValue,
967                 // so that IndexOf() needs to return Int32.MaxValue when it cannot find the object
968                 int[] myLengthArray = new int[1] { 3 };
969                 int[] myBoundArray = new int[1] { Int32.MinValue };
970                 Array myExtremeArray=Array.CreateInstance ( typeof(String), myLengthArray, myBoundArray );
971                 Assert.AreEqual (Int32.MaxValue, ((IList)myExtremeArray).IndexOf (42), "AD04");
972
973         }
974
975         [Test]
976         public void TestGetLength() {
977                 {
978                         bool errorThrown = false;
979                         try {
980                                 char[] c1 = {'a', 'b', 'c'};
981                                 c1.GetLength(-1);
982                         } catch (IndexOutOfRangeException) {
983                                 errorThrown = true;
984                         }
985                         Assert.IsTrue (errorThrown, "#H01");
986                 }
987                 {
988                         bool errorThrown = false;
989                         try {
990                                 char[] c1 = {'a', 'b', 'c'};
991                                 c1.GetLength(1);
992                         } catch (IndexOutOfRangeException) {
993                                 errorThrown = true;
994                         }
995                         Assert.IsTrue (errorThrown, "#H02");
996                 }
997
998                 char[] c2 = new Char[5];
999                 Assert.AreEqual (5, c2.GetLength(0), "#H03");
1000
1001                 char[,] c3 = new Char[6,7];
1002                 Assert.AreEqual (6, c3.GetLength(0), "#H04");
1003                 Assert.AreEqual (7, c3.GetLength(1), "#H05");
1004         }
1005
1006         [Test]
1007         public void TestGetLowerBound() {
1008                 {
1009                         bool errorThrown = false;
1010                         try {
1011                                 char[] c = {'a', 'b', 'c'};
1012                                 c.GetLowerBound(-1);
1013                         } catch (IndexOutOfRangeException) {
1014                                 errorThrown = true;
1015                         }
1016                         Assert.IsTrue (errorThrown, "#H31");
1017                 }
1018                 {
1019                         bool errorThrown = false;
1020                         try {
1021                                 char[] c = {'a', 'b', 'c'};
1022                                 c.GetLowerBound(1);
1023                         } catch (IndexOutOfRangeException) {
1024                                 errorThrown = true;
1025                         }
1026                         Assert.IsTrue (errorThrown, "#H32");
1027                 }
1028
1029                 char[] c1 = new Char[5];
1030                 Assert.AreEqual (0, c1.GetLowerBound(0), "#H33");
1031
1032                 char[,] c2 = new Char[4,4];
1033                 Assert.AreEqual (0, c2.GetLowerBound(0), "#H34");
1034                 Assert.AreEqual (0, c2.GetLowerBound(1), "#H35");
1035         }
1036
1037         [Test]
1038         public void TestGetUpperBound() {
1039                 {
1040                         bool errorThrown = false;
1041                         try {
1042                                 char[] c = {'a', 'b', 'c'};
1043                                 c.GetUpperBound(-1);
1044                         } catch (IndexOutOfRangeException) {
1045                                 errorThrown = true;
1046                         }
1047                         Assert.IsTrue (errorThrown, "#H61");
1048                 }
1049                 {
1050                         bool errorThrown = false;
1051                         try {
1052                                 char[] c = {'a', 'b', 'c'};
1053                                 c.GetUpperBound(1);
1054                         } catch (IndexOutOfRangeException) {
1055                                 errorThrown = true;
1056                         }
1057                         Assert.IsTrue (errorThrown, "#H62");
1058                 }
1059
1060                 char[] c1 = new Char[5];
1061                 Assert.AreEqual (4, c1.GetUpperBound(0), "#H63");
1062
1063                 char[,] c2 = new Char[4,6];
1064                 Assert.AreEqual (3, c2.GetUpperBound(0), "#H64");
1065                 Assert.AreEqual (5, c2.GetUpperBound(1), "#H65");
1066         }
1067
1068         [Test]
1069         public void TestGetValue1() {
1070                 {
1071                         bool errorThrown = false;
1072                         try {
1073                                 char[,] c = new Char[2,2];
1074                                 c.GetValue(1);
1075                         } catch (ArgumentException) {
1076                                 errorThrown = true;
1077                         }
1078                         Assert.IsTrue (errorThrown, "#I01");
1079                 }
1080                 {
1081                         bool errorThrown = false;
1082                         try {
1083                                 char[] c = {'a', 'b', 'c'};
1084                                 c.GetValue(-1);
1085                         } catch (IndexOutOfRangeException) {
1086                                 errorThrown = true;
1087                         }
1088                         Assert.IsTrue (errorThrown, "#I02");
1089                 }
1090                 {
1091                         bool errorThrown = false;
1092                         try {
1093                                 char[] c = {'a', 'b', 'c'};
1094                                 c.GetValue(4);
1095                         } catch (IndexOutOfRangeException) {
1096                                 errorThrown = true;
1097                         }
1098                         Assert.IsTrue (errorThrown, "#I03");
1099                 }
1100
1101                 char[] c1 = {'a', 'b', 'c', 'd'};
1102                 for (int i = 0; i < c1.Length; i++) {
1103                         Assert.AreEqual (c1[i], c1.GetValue(i), "#I04(" + i + ")");
1104                 }
1105         }
1106
1107         [Test]
1108         public void TestGetValue2() {
1109                 {
1110                         bool errorThrown = false;
1111                         try {
1112                                 char[] c = new Char[2];
1113                                 c.GetValue(1,1);
1114                         } catch (ArgumentException) {
1115                                 errorThrown = true;
1116                         }
1117                         Assert.IsTrue (errorThrown, "#I21");
1118                 }
1119                 {
1120                         bool errorThrown = false;
1121                         try {
1122                                 char[,] c = new Char[2,2];
1123                                 c.GetValue(-1, 1);
1124                         } catch (IndexOutOfRangeException) {
1125                                 errorThrown = true;
1126                         }
1127                         Assert.IsTrue (errorThrown, "#I22");
1128                 }
1129                 {
1130                         bool errorThrown = false;
1131                         try {
1132                                 char[,] c = new Char[2,2];
1133                                 c.GetValue(4,1);
1134                         } catch (IndexOutOfRangeException) {
1135                                 errorThrown = true;
1136                         }
1137                         Assert.IsTrue (errorThrown, "#I23");
1138                 }
1139
1140                 char[,] c1 = new Char[4,6];
1141                 for (int i = 0; i < 24; i++) {
1142                         int first = i / 6;
1143                         int second = i % 6;
1144                         c1[first,second] = (char)(((int)'a')+i);
1145                 }
1146                 for (int i = 0; i < c1.GetLength(0); i++) {
1147                         for (int j = 0; j < c1.GetLength(1); j++) {
1148                                 Assert.AreEqual (c1[i, j], c1.GetValue(i, j), "#I24(" + i + "," + j + ")");
1149                         }
1150                 }
1151         }
1152
1153         [Test]
1154         public void TestGetValue3() {
1155                 {
1156                         bool errorThrown = false;
1157                         try {
1158                                 char[] c = new Char[2];
1159                                 c.GetValue(1,1,1);
1160                         } catch (ArgumentException) {
1161                                 errorThrown = true;
1162                         }
1163                         Assert.IsTrue (errorThrown, "#I41");
1164                 }
1165                 {
1166                         bool errorThrown = false;
1167                         try {
1168                                 char[,,] c = new Char[2,2,2];
1169                                 c.GetValue(-1, 1, 1);
1170                         } catch (IndexOutOfRangeException) {
1171                                 errorThrown = true;
1172                         }
1173                         Assert.IsTrue (errorThrown, "#I42");
1174                 }
1175                 {
1176                         bool errorThrown = false;
1177                         try {
1178                                 char[,,] c = new Char[2,2,2];
1179                                 c.GetValue(4,1,1);
1180                         } catch (IndexOutOfRangeException) {
1181                                 errorThrown = true;
1182                         }
1183                         Assert.IsTrue (errorThrown, "#I43");
1184                 }
1185
1186                 char[,,] c1 = new Char[4,2,3];
1187                 for (int i = 0; i < 24; i++) {
1188                         int first = i / 6;
1189                         int remains = i % 6;
1190                         int second = remains / 3;
1191                         int third = remains % 3;
1192                         c1[first,second, third] = (char)(((int)'a')+i);
1193                 }
1194                 for (int i = 0; i < c1.GetLength(0); i++) {
1195                         for (int j = 0; j < c1.GetLength(1); j++) {
1196                                 for (int k = 0; k < c1.GetLength(2); k++) {
1197                                         Assert.AreEqual (c1[i, j, k], c1.GetValue(i, j, k), "#I44(" + i + "," + j + ")");
1198                                 }
1199                         }
1200                 }
1201         }
1202
1203         [Test]
1204 #if NET_2_0
1205         [ExpectedException (typeof (ArgumentNullException))]
1206 #else
1207         [ExpectedException (typeof (NullReferenceException))]
1208 #endif
1209         public void TestGetValueLongArray ()
1210         {
1211                 char[] c = new Char[2];
1212                 c.GetValue((long [])null);
1213         }
1214
1215         [Test]
1216         public void TestGetValueN() {
1217                 {
1218                         bool errorThrown = false;
1219                         try {
1220                                 char[] c = new Char[2];
1221                                 c.GetValue((int [])null);
1222                         } catch (ArgumentNullException) {
1223                                 errorThrown = true;
1224                         }
1225                         Assert.IsTrue (errorThrown, "#I61a");
1226                 }
1227                 {
1228                         bool errorThrown = false;
1229                         try {
1230                                 char[] c = new Char[2];
1231                                 int[] coords = {1, 1};
1232                                 c.GetValue(coords);
1233                         } catch (ArgumentException) {
1234                                 errorThrown = true;
1235                         }
1236                         Assert.IsTrue (errorThrown, "#I62");
1237                 }
1238                 {
1239                         bool errorThrown = false;
1240                         try {
1241                                 char[,] c = new Char[2,2];
1242                                 int[] coords = {-1, 1};
1243                                 c.GetValue(coords);
1244                         } catch (IndexOutOfRangeException) {
1245                                 errorThrown = true;
1246                         }
1247                         Assert.IsTrue (errorThrown, "#I63");
1248                 }
1249                 {
1250                         bool errorThrown = false;
1251                         try {
1252                                 char[,] c = new Char[2,2];
1253                                 int[] coords = {4, 1};
1254                                 c.GetValue(coords);
1255                         } catch (IndexOutOfRangeException) {
1256                                 errorThrown = true;
1257                         }
1258                         Assert.IsTrue (errorThrown, "#I64");
1259                 }
1260
1261                 char[,] c1 = new Char[4,6];
1262                 for (int i = 0; i < 24; i++) {
1263                         int first = i / 6;
1264                         int second = i % 6;
1265                         c1[first,second] = (char)(((int)'a')+i);
1266                 }
1267                 for (int i = 0; i < c1.GetLength(0); i++) {
1268                         for (int j = 0; j < c1.GetLength(1); j++) {
1269                                 int[] coords = {i, j};
1270                                 Assert.AreEqual (c1[i, j], c1.GetValue(coords), "#I65(" + i + "," + j + ")");
1271                         }
1272                 }
1273         }
1274
1275         [Test]
1276         public void TestIndexOf1() {
1277                 {
1278                         bool errorThrown = false;
1279                         try {
1280                                 Array.IndexOf(null, "huh?");
1281                         } catch (ArgumentNullException) {
1282                                 errorThrown = true;
1283                         }
1284                         Assert.IsTrue (errorThrown, "#J01");
1285                 }
1286                 {
1287                         bool errorThrown = false;
1288                         try {
1289                                 char[,] c = new Char[2,2];
1290                                 Array.IndexOf(c, "huh?");
1291                         } catch (RankException) {
1292                                 errorThrown = true;
1293                         }
1294                         Assert.IsTrue (errorThrown, "#J02");
1295                 }
1296
1297                 String[] s1 = {"this", "is", "a", "test"};
1298                 Assert.AreEqual (-1, Array.IndexOf(s1, null), "#J03");
1299                 Assert.AreEqual (-1, Array.IndexOf(s1, "nothing"), "#J04");
1300                 Assert.AreEqual (0, Array.IndexOf(s1, "this"), "#J05");
1301                 Assert.AreEqual (3, Array.IndexOf(s1, "test"), "#J06");
1302         }
1303
1304         [Test]
1305         public void TestIndexOf2() {
1306                 {
1307                         bool errorThrown = false;
1308                         try {
1309                                 Array.IndexOf(null, "huh?", 0);
1310                         } catch (ArgumentNullException) {
1311                                 errorThrown = true;
1312                         }
1313                         Assert.IsTrue (errorThrown, "#J21");
1314                 }
1315                 {
1316                         bool errorThrown = false;
1317                         try {
1318                                 char[,] c = new Char[2,2];
1319                                 Array.IndexOf(c, "huh?", 0);
1320                         } catch (RankException) {
1321                                 errorThrown = true;
1322                         }
1323                         Assert.IsTrue (errorThrown, "#J22");
1324                 }
1325                 {
1326                         bool errorThrown = false;
1327                         try {
1328                                 char[] c = new Char[2];
1329                                 Array.IndexOf(c, "huh?", 3);
1330                         } catch (ArgumentOutOfRangeException) {
1331                                 errorThrown = true;
1332                         }
1333                         Assert.IsTrue (errorThrown, "#J23");
1334                 }
1335
1336                 String[] s1 = {"this", "is", "really", "a", "test"};
1337                 Assert.AreEqual (-1, Array.IndexOf(s1, null, 1), "#J24");
1338                 Assert.AreEqual (-1, Array.IndexOf(s1, "nothing", 1), "#J25");
1339                 Assert.AreEqual (-1, Array.IndexOf(s1, "this", 1), "#J26");
1340                 Assert.AreEqual (1, Array.IndexOf(s1, "is", 1), "#J27");
1341                 Assert.AreEqual (4, Array.IndexOf(s1, "test", 1), "#J28");
1342         }
1343
1344         [Test]
1345         public void TestIndexOf3() {
1346                 {
1347                         bool errorThrown = false;
1348                         try {
1349                                 Array.IndexOf(null, "huh?", 0, 1);
1350                         } catch (ArgumentNullException) {
1351                                 errorThrown = true;
1352                         }
1353                         Assert.IsTrue (errorThrown, "#J41");
1354                 }
1355                 {
1356                         bool errorThrown = false;
1357                         try {
1358                                 char[,] c = new Char[2,2];
1359                                 Array.IndexOf(c, "huh?", 0, 1);
1360                         } catch (RankException) {
1361                                 errorThrown = true;
1362                         }
1363                         Assert.IsTrue (errorThrown, "#J42");
1364                 }
1365                 {
1366                         bool errorThrown = false;
1367                         try {
1368                                 char[] c = new Char[2];
1369                                 Array.IndexOf(c, "huh?", 3, 1);
1370                         } catch (ArgumentOutOfRangeException) {
1371                                 errorThrown = true;
1372                         }
1373                         Assert.IsTrue (errorThrown, "#J43");
1374                 }
1375                 {
1376                         bool errorThrown = false;
1377                         try {
1378                                 char[] c = new Char[2];
1379                                 Array.IndexOf(c, "huh?", 0, 5);
1380                         } catch (ArgumentOutOfRangeException) {
1381                                 errorThrown = true;
1382                         }
1383                         Assert.IsTrue (errorThrown, "#J44");
1384                 }
1385
1386                 String[] s1 = {"this", "is", "really", "a", "test"};
1387                 Assert.AreEqual (-1, Array.IndexOf(s1, null, 1, 3), "#J45");
1388                 Assert.AreEqual (-1, Array.IndexOf(s1, "nothing", 1, 3), "#J46");
1389                 Assert.AreEqual (-1, Array.IndexOf(s1, "this", 1, 3), "#J47");
1390                 Assert.AreEqual (1, Array.IndexOf(s1, "is", 1, 3), "#J48");
1391                 Assert.AreEqual (-1, Array.IndexOf(s1, "test", 1, 3), "#J49");
1392                 Assert.AreEqual (3, Array.IndexOf(s1, "a", 1, 3), "#J50");
1393         }
1394         
1395         [Test]
1396         public void TestIndexOf_CustomEqual ()
1397         {
1398                 DataEqual[] test = new DataEqual [] { new DataEqual () };
1399                 Assert.AreEqual (0, Array.IndexOf (test, "asdfas", 0));
1400                 
1401                 IList array = (IList)test;
1402                 Assert.AreEqual (0, array.IndexOf ("asdfas"));
1403         }
1404         
1405         [Test]
1406         public void TestLastIndexOf1() {
1407                 {
1408                         bool errorThrown = false;
1409                         try {
1410                                 Array.LastIndexOf(null, "huh?");
1411                         } catch (ArgumentNullException) {
1412                                 errorThrown = true;
1413                         }
1414                         Assert.IsTrue (errorThrown, "#K01");
1415                 }
1416                 {
1417                         bool errorThrown = false;
1418                         try {
1419                                 char[,] c = new Char[2,2];
1420                                 Array.LastIndexOf(c, "huh?");
1421                         } catch (RankException) {
1422                                 errorThrown = true;
1423                         }
1424                         Assert.IsTrue (errorThrown, "#K02");
1425                 }
1426
1427                 String[] s1 = {"this", "is", "a", "a", "test"};
1428                 Assert.AreEqual (-1, Array.LastIndexOf(s1, null), "#K03");
1429                 Assert.AreEqual (-1, Array.LastIndexOf(s1, "nothing"), "#K04");
1430                 Assert.AreEqual (0, Array.LastIndexOf(s1, "this"), "#K05");
1431                 Assert.AreEqual (4, Array.LastIndexOf(s1, "test"), "#K06");
1432                 Assert.AreEqual (3, Array.LastIndexOf(s1, "a"), "#K07");
1433
1434                 Assert.AreEqual (-1, Array.LastIndexOf (new String [0], "foo"));
1435         }
1436
1437         [Test]
1438         public void TestLastIndexOf2() {
1439                 {
1440                         bool errorThrown = false;
1441                         try {
1442                                 Array.LastIndexOf(null, "huh?", 0);
1443                         } catch (ArgumentNullException) {
1444                                 errorThrown = true;
1445                         }
1446                         Assert.IsTrue (errorThrown, "#K21");
1447                 }
1448                 {
1449                         bool errorThrown = false;
1450                         try {
1451                                 char[,] c = new Char[2,2];
1452                                 Array.LastIndexOf(c, "huh?", 0);
1453                         } catch (RankException) {
1454                                 errorThrown = true;
1455                         }
1456                         Assert.IsTrue (errorThrown, "#K22");
1457                 }
1458                 {
1459                         bool errorThrown = false;
1460                         try {
1461                                 char[] c = new Char[2];
1462                                 Array.LastIndexOf(c, "huh?", 3);
1463                         } catch (ArgumentOutOfRangeException) {
1464                                 errorThrown = true;
1465                         }
1466                         Assert.IsTrue (errorThrown, "#K23");
1467                 }
1468
1469                 String[] s1 = {"this", "is", "really", "a", "test"};
1470                 Assert.AreEqual (-1, Array.LastIndexOf(s1, null, 3), "#K24");
1471                 Assert.AreEqual (-1, Array.LastIndexOf(s1, "nothing", 3), "#K25");
1472                 Assert.AreEqual (-1, Array.LastIndexOf(s1, "test", 3), "#K26");
1473                 Assert.AreEqual (3, Array.LastIndexOf(s1, "a", 3), "#K27");
1474                 Assert.AreEqual (0, Array.LastIndexOf(s1, "this", 3), "#K28");
1475         }
1476
1477         [Test]
1478         public void TestLastIndexOf3() {
1479                 {
1480                         bool errorThrown = false;
1481                         try {
1482                                 Array.LastIndexOf(null, "huh?", 0, 1);
1483                         } catch (ArgumentNullException) {
1484                                 errorThrown = true;
1485                         }
1486                         Assert.IsTrue (errorThrown, "#K41");
1487                 }
1488                 {
1489                         bool errorThrown = false;
1490                         try {
1491                                 char[,] c = new Char[2,2];
1492                                 Array.LastIndexOf(c, "huh?", 0, 1);
1493                         } catch (RankException) {
1494                                 errorThrown = true;
1495                         }
1496                         Assert.IsTrue (errorThrown, "#K42");
1497                 }
1498                 {
1499                         bool errorThrown = false;
1500                         try {
1501                                 char[] c = new Char[2];
1502                                 Array.LastIndexOf(c, "huh?", 3, 1);
1503                         } catch (ArgumentOutOfRangeException) {
1504                                 errorThrown = true;
1505                         }
1506                         Assert.IsTrue (errorThrown, "#K43");
1507                 }
1508                 {
1509                         bool errorThrown = false;
1510                         try {
1511                                 char[] c = new Char[2];
1512                                 Array.LastIndexOf(c, "huh?", 0, 5);
1513                         } catch (ArgumentOutOfRangeException) {
1514                                 errorThrown = true;
1515                         }
1516                         Assert.IsTrue (errorThrown, "#K44");
1517                 }
1518
1519                 String[] s1 = {"this", "is", "really", "a", "test"};
1520                 Assert.AreEqual (-1, Array.LastIndexOf(s1, null, 3, 3), "#K45");
1521                 Assert.AreEqual (-1, Array.LastIndexOf(s1, "nothing", 3, 3), "#K46");
1522                 Assert.AreEqual (-1, Array.LastIndexOf(s1, "this", 3, 3), "#K47");
1523                 Assert.AreEqual (1, Array.LastIndexOf(s1, "is", 3, 3), "#K48");
1524                 Assert.AreEqual (-1, Array.LastIndexOf(s1, "test", 3, 3), "#K49");
1525                 Assert.AreEqual (3, Array.LastIndexOf(s1, "a", 3, 3), "#K50");
1526         }
1527
1528         [Test]
1529         public void TestLastIndexOf4 ()
1530         {
1531                 short [] a = new short [] { 19, 238, 317, 6, 565, 0, -52, 60, -563, 753, 238, 238};
1532                 try {
1533                         Array.LastIndexOf (a, (object)16, -1);
1534                         NUnit.Framework.Assert.Fail ("#1");
1535                 } catch (ArgumentOutOfRangeException) { }
1536                 
1537 #if NET_2_0             
1538                 try {
1539                         Array.LastIndexOf<short> (a, 16, -1);
1540                         NUnit.Framework.Assert.Fail ("#2");
1541                 } catch (ArgumentOutOfRangeException) { }
1542 #endif          
1543         }
1544
1545         [Test]
1546         public void TestLastIndexOf5 ()
1547         {
1548                 char [] a = new char [] {'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a', 'j', 'i', 'h'};
1549                 string s;
1550                 int retval;
1551                 bool error = false;
1552
1553                 for (int i = a.Length - 1; i >= 0 ; i--) {
1554                         s = i.ToString ();
1555                         retval = Array.LastIndexOf(a, a [i], i, i + 1);
1556                         if (retval != i)
1557                                 error = true;
1558                 }
1559                 Assert.IsTrue (!error);
1560         }
1561
1562         [Test]
1563         [ExpectedException (typeof (ArgumentOutOfRangeException))]
1564         public void LastIndexOf_StartIndexOverflow ()
1565         {
1566                 // legal - no exception
1567                 byte[] array = new byte [16];
1568                 Array.LastIndexOf (array, this, Int32.MaxValue, 1);
1569         }
1570
1571         [Test]
1572         [ExpectedException (typeof (ArgumentOutOfRangeException))]
1573         public void LastIndexOf_CountOverflow ()
1574         {
1575                 // legal - no exception
1576                 byte[] array = new byte [16];
1577                 Array.LastIndexOf (array, this, 1, Int32.MaxValue);
1578         }
1579
1580         [Test]
1581         public void LastIndexOf_0LengthArray ()
1582         {
1583                 Array array = Array.CreateInstance (typeof (char), 0);
1584                 int idx = Array.LastIndexOf (array, (object) null, -1, 0);
1585                 Assert.IsTrue (idx == -1, "#01");
1586                 idx = Array.LastIndexOf (array, (object) null, -1, 10);
1587                 Assert.IsTrue (idx == -1, "#02");
1588                 idx = Array.LastIndexOf (array, (object) null, -100, 10);
1589                 Assert.IsTrue (idx == -1, "#02");
1590
1591                 array = Array.CreateInstance (typeof (char), 1);
1592                 try {
1593                         Array.LastIndexOf (array, (object) null, -1, 0);
1594                         Assert.Fail ("#04");
1595                 } catch (ArgumentOutOfRangeException e) {
1596                 }
1597                 try {
1598                         Array.LastIndexOf (array, (object) null, -1, 10);
1599                         Assert.Fail ("#05");
1600                 } catch (ArgumentOutOfRangeException e) {
1601                 }
1602                 try {
1603                         Array.LastIndexOf (array, (object) null, -100, 10);
1604                         Assert.Fail ("#06");
1605                 } catch (ArgumentOutOfRangeException e) {
1606                 }
1607         }
1608
1609         [Test]
1610         public void TestReverse() {
1611                 {
1612                         bool errorThrown = false;
1613                         try {
1614                                 Array.Reverse(null);
1615                         } catch (ArgumentNullException) {
1616                                 errorThrown = true;
1617                         }
1618                         Assert.IsTrue (errorThrown, "#L01");
1619                 }
1620                 {
1621                         bool errorThrown = false;
1622                         try {
1623                                 char[,] c = new Char[2,2];
1624                                 Array.Reverse(c);
1625                         } catch (RankException) {
1626                                 errorThrown = true;
1627                         }
1628                         Assert.IsTrue (errorThrown, "#L02");
1629                 }
1630                 
1631                 char[] c1 = {'a', 'b', 'c', 'd'};
1632                 Array.Reverse(c1);
1633                 Assert.AreEqual ('d', c1[0], "#L03");
1634                 Assert.AreEqual ('c', c1[1], "#L04");
1635                 Assert.AreEqual ('b', c1[2], "#L05");
1636                 Assert.AreEqual ('a', c1[3], "#L06");
1637
1638                 {
1639                         bool errorThrown = false;
1640                         try {
1641                                 Array.Reverse(null, 0, 0);
1642                         } catch (ArgumentNullException) {
1643                                 errorThrown = true;
1644                         }
1645                         Assert.IsTrue (errorThrown, "#L07");
1646                 }
1647                 {
1648                         bool errorThrown = false;
1649                         try {
1650                                 char[,] c = new Char[2,2];
1651                                 Array.Reverse(c, 0, 0);
1652                         } catch (RankException) {
1653                                 errorThrown = true;
1654                         }
1655                         Assert.IsTrue (errorThrown, "#L08");
1656                 }
1657                 //{
1658                 //bool errorThrown = false;
1659                 //try {
1660                 //      char[] c = new Char[2];
1661                 //      Array.Reverse(c, 0, 3);
1662                 //} catch (ArgumentOutOfRangeException) {
1663                 //      errorThrown = true;
1664                 //}
1665                 //Assert.IsTrue (errorThrown, "#L09");
1666                 //}
1667                 //{
1668                 //bool errorThrown = false;
1669                 //try {
1670                 //      char[] c = new Char[2];
1671                 //      Array.Reverse(c, 3, 0);
1672                 //} catch (ArgumentOutOfRangeException) {
1673                 //      errorThrown = true;
1674                 //}
1675                 //Assert.IsTrue (errorThrown, "#L10");
1676                 //}
1677
1678                 char[] c2 = { 'a', 'b', 'c', 'd'};
1679                 Array.Reverse(c2, 1, 2);
1680                 Assert.AreEqual ('a', c2[0], "#L11");
1681                 Assert.AreEqual ('c', c2[1], "#L12");
1682                 Assert.AreEqual ('b', c2[2], "#L13");
1683                 Assert.AreEqual ('d', c2[3], "#L14");
1684         }
1685
1686         [Test]
1687         public void TestSetValue1() {
1688                 {
1689                         bool errorThrown = false;
1690                         try {
1691                                 char[,] c = new Char[2,2];
1692                                 c.SetValue("buh", 1);
1693                         } catch (ArgumentException) {
1694                                 errorThrown = true;
1695                         }
1696                         Assert.IsTrue (errorThrown, "#M01");
1697                 }
1698                 {
1699                         bool errorThrown = false;
1700                         try {
1701                                 char[] c = {'a', 'b', 'c'};
1702                                 c.SetValue("buh", -1);
1703                         } catch (IndexOutOfRangeException) {
1704                                 errorThrown = true;
1705                         }
1706                         Assert.IsTrue (errorThrown, "#M02");
1707                 }
1708                 {
1709                         bool errorThrown = false;
1710                         try {
1711                                 char[] c = {'a', 'b', 'c'};
1712                                 c.SetValue("buh", 4);
1713                         } catch (IndexOutOfRangeException) {
1714                                 errorThrown = true;
1715                         }
1716                         Assert.IsTrue (errorThrown, "#M03");
1717                 }
1718
1719                 char[] c1 = {'a', 'b', 'c', 'd'};
1720                 char[] c2 = new char[4];
1721                 for (int i = 0; i < c1.Length; i++) {
1722                         c2.SetValue(c1[i], i);
1723                 }
1724                 for (int i = 0; i < c1.Length; i++) {
1725                         Assert.AreEqual (c1[i], c2[i], "#M04(" + i + ")");
1726                 }
1727
1728                 int[] c3 = { 1, 2, 3 };
1729                 long[] c4 = new long [3];
1730
1731                 for (int i = 0; i < c3.Length; i++)
1732                         c4.SetValue (c3 [i], i);
1733
1734                 try {
1735                         c3.CopyTo (c4, 0);
1736                 } catch (Exception e) {
1737                         Assert.Fail ("c3.CopyTo(): e=" + e);
1738                 }
1739                 for (int i = 0; i < c3.Length; i++)
1740                         Assert.IsTrue (c3[i] == c4[i], "#M05(" + i + ")");
1741
1742                 Object[] c5 = new Object [3];
1743                 long[] c6 = new long [3];
1744
1745                 try {
1746                         c4.CopyTo (c5, 0);
1747                 } catch (Exception e) {
1748                         Assert.Fail ("c4.CopyTo(): e=" + e);
1749                 }
1750
1751                 try {
1752                         c5.CopyTo (c6, 0);
1753                 } catch (Exception e) {
1754                         Assert.Fail ("c5.CopyTo(): e=" + e);
1755                 }
1756                 // for (int i = 0; i < c5.Length; i++)
1757                 // Assert.IsTrue (c5[i] == c6[i], "#M06(" + i + ")");
1758         }
1759
1760         [Test]
1761         public void TestSetValue2() {
1762                 {
1763                         bool errorThrown = false;
1764                         try {
1765                                 char[] c = new Char[2];
1766                                 c.SetValue("buh", 1,1);
1767                         } catch (ArgumentException) {
1768                                 errorThrown = true;
1769                         }
1770                         Assert.IsTrue (errorThrown, "#M21");
1771                 }
1772                 {
1773                         bool errorThrown = false;
1774                         try {
1775                                 char[,] c = new Char[2,2];
1776                                 c.SetValue("buh", -1, 1);
1777                         } catch (IndexOutOfRangeException) {
1778                                 errorThrown = true;
1779                         }
1780                         Assert.IsTrue (errorThrown, "#M22");
1781                 }
1782                 {
1783                         bool errorThrown = false;
1784                         try {
1785                                 char[,] c = new Char[2,2];
1786                                 c.SetValue("buh", 4,1);
1787                         } catch (IndexOutOfRangeException) {
1788                                 errorThrown = true;
1789                         }
1790                         Assert.IsTrue (errorThrown, "#M23");
1791                 }
1792
1793                 char[,] c1 = new Char[4,6];
1794                 char[,] c2 = new Char[4,6];
1795                 for (int i = 0; i < 24; i++) {
1796                         int first = i / 6;
1797                         int second = i % 6;
1798                         c1[first,second] = (char)(((int)'a')+i);
1799                         c2.SetValue(c1[first,second], first, second);
1800                 }
1801                 for (int i = 0; i < c1.GetLength(0); i++) {
1802                         for (int j = 0; j < c1.GetLength(1); j++) {
1803                                 Assert.AreEqual (c1[i, j], c2[i, j], "#M24(" + i + "," + j + ")");
1804                         }
1805                 }
1806         }
1807
1808         [Test]
1809         public void TestSetValue3() {
1810                 {
1811                         bool errorThrown = false;
1812                         try {
1813                                 char[] c = new Char[2];
1814                                 c.SetValue("buh", 1,1,1);
1815                         } catch (ArgumentException) {
1816                                 errorThrown = true;
1817                         }
1818                         Assert.IsTrue (errorThrown, "#M41");
1819                 }
1820                 {
1821                         bool errorThrown = false;
1822                         try {
1823                                 char[,,] c = new Char[2,2,2];
1824                                 c.SetValue("buh", -1, 1, 1);
1825                         } catch (IndexOutOfRangeException) {
1826                                 errorThrown = true;
1827                         }
1828                         Assert.IsTrue (errorThrown, "#M42");
1829                 }
1830                 {
1831                         bool errorThrown = false;
1832                         try {
1833                                 char[,,] c = new Char[2,2,2];
1834                                 c.SetValue("buh", 4,1,1);
1835                         } catch (IndexOutOfRangeException) {
1836                                 errorThrown = true;
1837                         }
1838                         Assert.IsTrue (errorThrown, "#M43");
1839                 }
1840
1841                 char[,,] c1 = new Char[4,2,3];
1842                 char[,,] c2 = new Char[4,2,3];
1843                 for (int i = 0; i < 24; i++) {
1844                         int first = i / 6;
1845                         int remains = i % 6;
1846                         int second = remains / 3;
1847                         int third = remains % 3;
1848                         c1[first,second, third] = (char)(((int)'a')+i);
1849                         c2.SetValue(c1[first, second, third], first, second, third);
1850                 }
1851                 for (int i = 0; i < c1.GetLength(0); i++) {
1852                         for (int j = 0; j < c1.GetLength(1); j++) {
1853                                 for (int k = 0; k < c1.GetLength(2); k++) {
1854                                         Assert.AreEqual (c1[i, j, k], c2[i, j, k], "#M44(" + i + "," + j + " )");
1855                                 }
1856                         }
1857                 }
1858         }
1859
1860         [Test]
1861 #if NET_2_0
1862         [ExpectedException (typeof (ArgumentNullException))]
1863 #else
1864         [ExpectedException (typeof (NullReferenceException))]
1865 #endif
1866         public void TestSetValueLongArray ()
1867         {
1868                 char[] c = new Char[2];
1869                 c.SetValue("buh", (long [])null);
1870         }
1871
1872         [Test]
1873         public void TestSetValueN() {
1874                 {
1875                         bool errorThrown = false;
1876                         try {
1877                                 char[] c = new Char[2];
1878                                 c.SetValue("buh", (int [])null);
1879                         } catch (ArgumentNullException) {
1880                                 errorThrown = true;
1881                         }
1882                         Assert.IsTrue (errorThrown, "#M61a");
1883                 }
1884                 {
1885                         bool errorThrown = false;
1886                         try {
1887                                 char[] c = new Char[2];
1888                                 int[] coords = {1, 1};
1889                                 c.SetValue("buh", coords);
1890                         } catch (ArgumentException) {
1891                                 errorThrown = true;
1892                         }
1893                         Assert.IsTrue (errorThrown, "#M62");
1894                 }
1895                 {
1896                         bool errorThrown = false;
1897                         try {
1898                                 char[,] c = new Char[2,2];
1899                                 int[] coords = {-1, 1};
1900                                 c.SetValue("buh", coords);
1901                         } catch (IndexOutOfRangeException) {
1902                                 errorThrown = true;
1903                         }
1904                         Assert.IsTrue (errorThrown, "#M63");
1905                 }
1906                 {
1907                         bool errorThrown = false;
1908                         try {
1909                                 char[,] c = new Char[2,2];
1910                                 int[] coords = {4, 1};
1911                                 c.SetValue("buh", coords);
1912                         } catch (IndexOutOfRangeException) {
1913                                 errorThrown = true;
1914                         }
1915                         Assert.IsTrue (errorThrown, "#M64");
1916                 }
1917
1918                 char[,] c1 = new Char[4,6];
1919                 char[,] c2 = new Char[4,6];
1920                 for (int i = 0; i < 24; i++) {
1921                         int first = i / 6;
1922                         int second = i % 6;
1923                         c1[first,second] = (char)(((int)'a')+i);
1924                         int[] coords = {first, second};
1925                         c2.SetValue(c1[first,second], coords);
1926                 }
1927                 for (int i = 0; i < c1.GetLength(0); i++) {
1928                         for (int j = 0; j < c1.GetLength(1); j++) {
1929                                 Assert.AreEqual (c1[i, j], c2[i, j], "#M65(" + i + "," + j + ")");
1930                         }
1931                 }
1932         }
1933
1934         [Test]
1935         public void TestSetValue4() {
1936                 {
1937                         int[] c1 = { 1, 2, 3 };
1938                         long[] c2 = new long [3];
1939
1940                         for (int i = 0; i < c1.Length; i++)
1941                                 c2.SetValue (c1 [i], i);
1942
1943                         for (int i = 0; i < c1.Length; i++) {
1944                                 Assert.IsTrue (c1[i] == c2[i], "#M81(" + i + ")");
1945                                 Assert.AreEqual (typeof (long), c2[i].GetType (), "#M82(" + i + ")");
1946                         }
1947                 }
1948                 {
1949                         long[] c1 = { 1, 2, 3 };
1950                         int[] c2 = new int [3];
1951                         bool errorThrown = false;
1952                         try {
1953                                 c2.SetValue (c1 [0], 0);
1954                         } catch (ArgumentException) {
1955                                 errorThrown = true;
1956                         }
1957                         Assert.IsTrue (errorThrown, "#M83");
1958                 }
1959                 {
1960                         int[] c1 = { 1, 2, 3 };
1961                         Object[] c2 = new Object [3];
1962
1963                         for (int i = 0; i < c1.Length; i++)
1964                                 c2.SetValue (c1 [i], i);
1965
1966                         for (int i = 0; i < c1.Length; i++)
1967                                 Assert.AreEqual (c1[i], Convert.ToInt32 (c2[i]), "#M84(" + i + ")");
1968                 }
1969                 {
1970                         Object[] c1 = new Object [3];
1971                         Object[] c2 = new Object [3];
1972                         c1[0] = new Object ();
1973
1974                         for (int i = 0; i < c1.Length; i++)
1975                                 c2.SetValue (c1 [i], i);
1976
1977                         for (int i = 0; i < c1.Length; i++)
1978                                 Assert.AreEqual (c1[i], c2[i], "#M85(" + i + ")");
1979                 }
1980                 {
1981                         Object[] c1 = new Object [3];
1982                         string[] c2 = new String [3];
1983                         string test = "hello";
1984                         c1[0] = test;
1985
1986                         c2.SetValue (c1 [0], 0);
1987                         Assert.AreEqual (c1[0], c2[0], "#M86");
1988                         Assert.AreEqual ("hello", c2[0], "#M87");
1989                 }
1990                 {
1991                         char[] c1 = { 'a', 'b', 'c' };
1992                         string[] c2 = new string [3];
1993                         try {
1994                                 c2.SetValue (c1 [0], 0);
1995                                 Assert.Fail ("#M88");
1996                         } catch (InvalidCastException) {}
1997                 }
1998                 {
1999                         Single[] c1 = { 1.2F, 2.3F, 3.4F, 4.5F };
2000                         long[] c2 = new long [3];
2001                         try {
2002                                 c2.SetValue (c1 [0], 0);
2003                                 Assert.Fail ("#M89");
2004                         } catch (ArgumentException) {}
2005                 }
2006                 {
2007                         Type[] types = {
2008                                 typeof (Boolean),
2009                                 typeof (Byte),
2010                                 typeof (Char),
2011                                 typeof (Double),
2012                                 typeof (Int16),
2013                                 typeof (Int32),
2014                                 typeof (Int64),
2015                                 typeof (SByte),
2016                                 typeof (Single),
2017                                 typeof (UInt16),
2018                                 typeof (UInt32),
2019                                 typeof (UInt64)
2020                         };
2021
2022                         bool v1 = true;
2023                         Byte v2 = 1;
2024                         Char v3 = 'a';
2025                         Double v4 = -1.2;
2026                         Int16 v5 = -32;
2027                         Int32 v6 = -234;
2028                         Int64 v7 = -34523;
2029                         SByte v8 = -1;
2030                         Single v9 = -4.8F;
2031                         UInt16 v10 = 24234;
2032                         UInt32 v11 = 235354;
2033                         UInt64 v12 = 234552;
2034
2035                         Object[] va1 = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 };
2036                         Object[] va2 = { "true", "1", "a", "-1.2", "-32", "-234", "-34523", "-1",
2037                                          "-4.8F", "24234", "235354", "234552" };
2038
2039                         Object[][] vt = { va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1 };
2040
2041                         int[] arg_ex = {
2042                                 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2043                                 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
2044                                 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
2045                                 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
2046                                 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1,
2047                                 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1,
2048                                 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1,
2049                                 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1,
2050                                 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1,
2051                                 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
2052                                 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0,
2053                                 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0
2054                         };
2055
2056                         // SetValue
2057
2058                         for (int i = 0; i < types.Length; i++) {
2059                                 for (int j = 0; j < types.Length; j++) {
2060                                         Array array = Array.CreateInstance (types [j], 2);
2061
2062                                         Object value = vt[j][i];
2063
2064                                         bool errorThrown = false;
2065                                         try {
2066                                                 array.SetValue (value, 0);
2067                                         } catch (ArgumentException) {
2068                                                 errorThrown = true;
2069                                         }
2070
2071                                         int ex_index = (i * types.Length) + j;
2072
2073                                         Assert.AreEqual (errorThrown, arg_ex [ex_index] == 1, "#M90(" + types [i] + "," + types [j] + ")");
2074                                 }
2075                         }
2076
2077                         for (int i = 0; i < types.Length; i++) {
2078                                 String[] array = new String [2];
2079
2080                                 Object value = va1 [i];
2081
2082                                 bool errorThrown = false;
2083                                 try {
2084                                         array.SetValue (value, 0);
2085                                 } catch (InvalidCastException) {
2086                                         errorThrown = true;
2087                                 }
2088
2089                                 Assert.IsTrue (errorThrown, "#M91(" + types [i] + ")");
2090                         }
2091
2092                         for (int i = 0; i < types.Length; i++) {
2093                                 Array array = Array.CreateInstance (types [i], 2);
2094
2095                                 Object value = va2 [i];
2096
2097                                 bool errorThrown = false;
2098                                 try {
2099                                         array.SetValue (value, 0);
2100                                 } catch (InvalidCastException) {
2101                                         errorThrown = true;
2102                                 }
2103
2104                                 Assert.IsTrue (errorThrown, "#M92(" + types [i] + ")");
2105                         }
2106
2107                         for (int i = 0; i < types.Length; i++) {
2108                                 Array array = Array.CreateInstance (types [i], 2);
2109
2110                                 Object value = null;
2111
2112                                 bool errorThrown = false;
2113                                 try {
2114                                         array.SetValue (value, 0);
2115                                 } catch (InvalidCastException) {
2116                                         errorThrown = true;
2117                                 }
2118
2119                                 Assert.IsTrue (!errorThrown, "#M93(" + types [i] + ")");
2120                         }
2121
2122                         // Copy
2123
2124                         for (int i = 0; i < types.Length; i++) {
2125                                 for (int j = 0; j < types.Length; j++) {
2126                                         Array source = Array.CreateInstance (types [i], 2);
2127                                         Array array = Array.CreateInstance (types [j], 2);
2128
2129                                         source.SetValue (vt[j][i], 0);
2130                                         source.SetValue (vt[j][i], 1);
2131
2132                                         bool errorThrown = false;
2133                                         try {
2134                                                 Array.Copy (source, array, 2);
2135                                         } catch (ArrayTypeMismatchException) {
2136                                                 errorThrown = true;
2137                                         }
2138
2139                                         int ex_index = (i * types.Length) + j;
2140
2141                                         Assert.AreEqual (errorThrown, arg_ex [ex_index] == 1, "#M94(" + types [i] + "," + types [j] + ")");
2142                                 }
2143                         }
2144
2145                         for (int i = 0; i < types.Length; i++) {
2146                                 Array source = Array.CreateInstance (types [i], 2);
2147                                 String[] array = new String [2];
2148
2149                                 source.SetValue (va1 [i], 0);
2150                                 source.SetValue (va1 [i], 1);
2151
2152                                 bool errorThrown = false;
2153                                 try {
2154                                         Array.Copy (source, array, 2);
2155                                 } catch (ArrayTypeMismatchException) {
2156                                         errorThrown = true;
2157                                 }
2158
2159                                 Assert.IsTrue (errorThrown, "#M95(" + types [i] + ")");
2160                         }
2161
2162                         for (int i = 0; i < types.Length; i++) {
2163                                 String[] source = new String [2];
2164                                 Array array = Array.CreateInstance (types [i], 2);
2165
2166                                 source.SetValue (va2 [i], 0);
2167                                 source.SetValue (va2 [i], 1);
2168
2169                                 bool errorThrown = false;
2170                                 try {
2171                                         Array.Copy (source, array, 2);
2172                                 } catch (ArrayTypeMismatchException) {
2173                                         errorThrown = true;
2174                                 }
2175
2176                                 Assert.IsTrue (errorThrown, "#M96(" + types [i] + ")");
2177                         }
2178                 }
2179         }
2180
2181         [Test]
2182         public void TestSort() {
2183                 {
2184                         bool errorThrown = false;
2185                         try {
2186                                 Array.Sort(null);
2187                         } catch (ArgumentNullException) {
2188                                 errorThrown = true;
2189                         }
2190                         Assert.IsTrue (errorThrown, "#N01");
2191                 }
2192                 {
2193                         bool errorThrown = false;
2194                         try {
2195                                 Array.Sort(null, 0, 1);
2196                         } catch (ArgumentNullException) {
2197                                 errorThrown = true;
2198                         }
2199                         Assert.IsTrue (errorThrown, "#N02");
2200                 }
2201                 {
2202                         bool errorThrown = false;
2203                         try {
2204                                 char[] c1 = new Char[2];
2205                                 Array.Sort(null, c1);
2206                         } catch (ArgumentNullException) {
2207                                 errorThrown = true;
2208                         }
2209                         Assert.IsTrue (errorThrown, "#N03");
2210                 }
2211                 {
2212                         bool errorThrown = false;
2213                         try {
2214                                 char[] c1 = new Char[2];
2215                                 Array.Sort(null, c1, 0, 1);
2216                         } catch (ArgumentNullException) {
2217                                 errorThrown = true;
2218                         }
2219                         Assert.IsTrue (errorThrown, "#N04");
2220                 }
2221                 {
2222                         int tc = 5;
2223                         char[] arr = {'d', 'b', 'f', 'e', 'a', 'c'};
2224                         
2225                         try {
2226                                 Array.Sort (null, 0, 1);
2227                                 Assert.Fail ("#N" + tc.ToString ());
2228                         }
2229                         catch (ArgumentException) {}
2230                         catch (Exception) { Assert.Fail ("#N" + tc.ToString ()); }
2231                         tc++;
2232                         
2233                         try {
2234                                 Array.Sort (arr, -1, 3);
2235                                 Assert.Fail ("#N" + tc.ToString ());
2236                         }
2237                         catch (ArgumentException) {}
2238                         catch (Exception) { Assert.Fail ("#N" + tc.ToString ()); }
2239                         tc++;
2240                         
2241                         try {
2242                                 Array.Sort (arr, 1, -3);
2243                                 Assert.Fail ("#N" + tc.ToString ());
2244                         }
2245                         catch (ArgumentException) {}
2246                         catch (Exception) { Assert.Fail ("#N" + tc.ToString ()); }
2247                         tc++;
2248                         
2249                         try {
2250                                 Array.Sort (arr, arr.Length, arr.Length + 2);
2251                                 Assert.Fail ("#N" + tc.ToString ());
2252                         }
2253                         catch (ArgumentException) {}
2254                         catch (Exception) { Assert.Fail ("#N" + tc.ToString ()); }
2255                 }
2256                 
2257                 // note: null second array => just sort first array
2258                 char[] starter = {'d', 'b', 'f', 'e', 'a', 'c'};
2259                 int[] starter1 = {1,2,3,4,5,6};
2260                 {
2261                         char[] c1 = (char[])starter.Clone();
2262                         Array.Sort(c1);
2263                         Assert.AreEqual ('a', c1[0], "#N21");
2264                         Assert.AreEqual ('b', c1[1], "#N22");
2265                         Assert.AreEqual ('c', c1[2], "#N23");
2266                         Assert.AreEqual ('d', c1[3], "#N24");
2267                         Assert.AreEqual ('e', c1[4], "#N25");
2268                         Assert.AreEqual ('f', c1[5], "#N26");
2269                 }
2270                 {
2271                         char[] c1 = (char[])starter.Clone();
2272                         int[] i1 = (int[])starter1.Clone();
2273                         Array.Sort(c1, i1);
2274                         Assert.AreEqual ('a', c1[0], "#N41");
2275                         Assert.AreEqual ('b', c1[1], "#N42");
2276                         Assert.AreEqual ('c', c1[2], "#N43");
2277                         Assert.AreEqual ('d', c1[3], "#N44");
2278                         Assert.AreEqual ('e', c1[4], "#N45");
2279                         Assert.AreEqual ('f', c1[5], "#N46");
2280                         Assert.AreEqual (5, i1[0], "#N47");
2281                         Assert.AreEqual (2, i1[1], "#N48");
2282                         Assert.AreEqual (6, i1[2], "#N49");
2283                         Assert.AreEqual (1, i1[3], "#N50");
2284                         Assert.AreEqual (4, i1[4], "#N51");
2285                         Assert.AreEqual (3, i1[5], "#N52");
2286                 }
2287                 {
2288                         char[] c1 = (char[])starter.Clone();
2289                         Array.Sort(c1, 1, 4);
2290                         Assert.AreEqual ('d', c1[0], "#N61");
2291                         Assert.AreEqual ('a', c1[1], "#N62");
2292                         Assert.AreEqual ('b', c1[2], "#N63");
2293                         Assert.AreEqual ('e', c1[3], "#N64");
2294                         Assert.AreEqual ('f', c1[4], "#N65");
2295                         Assert.AreEqual ('c', c1[5], "#N66");
2296                 }
2297                 {
2298                         char[] c1 = (char[])starter.Clone();
2299                         int[] i1 = (int[])starter1.Clone();
2300                         Array.Sort(c1, i1, 1, 4);
2301                         Assert.AreEqual ('d', c1[0], "#N81");
2302                         Assert.AreEqual ('a', c1[1], "#N82");
2303                         Assert.AreEqual ('b', c1[2], "#N83");
2304                         Assert.AreEqual ('e', c1[3], "#N84");
2305                         Assert.AreEqual ('f', c1[4], "#N85");
2306                         Assert.AreEqual ('c', c1[5], "#N86");
2307                         Assert.AreEqual (1, i1[0], "#N87");
2308                         Assert.AreEqual (5, i1[1], "#N88");
2309                         Assert.AreEqual (2, i1[2], "#N89");
2310                         Assert.AreEqual (4, i1[3], "#N90");
2311                         Assert.AreEqual (3, i1[4], "#N91");
2312                         Assert.AreEqual (6, i1[5], "#N92");
2313                 }
2314         }
2315
2316         [Test] // #616416
2317         public void SortNonGenericDoubleItems () {
2318             double[] doubleValues = new double[11];
2319
2320                         doubleValues[0] = 0.221788066253601;
2321                         doubleValues[1] = 0.497278285809481;
2322                         doubleValues[2] = 0.100565033883643;
2323                         doubleValues[3] = 0.0433309347749905;
2324                         doubleValues[4] = 0.00476726438463812;
2325                         doubleValues[5] = 0.1354609735456;
2326                         doubleValues[6] = 0.57690356588135;
2327                         doubleValues[7] = 0.466239434334826;
2328                         doubleValues[8] = 0.409741461978934;
2329                         doubleValues[9] = 0.0112412763949565;
2330                         doubleValues[10] = 0.668704347674307;
2331
2332             int[] indices = new int[11];
2333             indices[0] = 0;
2334             indices[1] = 1;
2335             indices[2] = 2;
2336             indices[3] = 3;
2337             indices[4] = 4;
2338             indices[5] = 5;
2339             indices[6] = 6;
2340             indices[7] = 7;
2341             indices[8] = 8;
2342             indices[9] = 9;
2343             indices[10] = 10;
2344
2345                         Array.Sort ((Array)doubleValues, (Array)indices);
2346                         Assert.AreEqual (4, indices [0]);
2347         }
2348
2349         [Test]
2350         public void TestInitializeEmpty()
2351         {
2352                 bool catched=false;
2353                 int[] a = {};
2354                 try
2355                 {
2356                         a.Initialize();
2357                 }
2358                 catch(Exception)
2359                 {
2360                         catched=true;
2361                 }
2362                 Assert.IsTrue (!catched, "#TI01");
2363         }
2364
2365         [Test]
2366         public void TestInitializeInt()
2367         {
2368                 int[] a = {1,2,0};
2369                 a.Initialize();
2370                 int[] b = {1,2,0};
2371                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2372                 {
2373                         Assert.AreEqual (a[i], b[i], "#TI02 " + i);
2374                 }
2375         }
2376
2377         [Test]
2378         public void TestInitializeDouble()
2379         {
2380                 double[] a = {1.0,2.0,0.0};
2381                 a.Initialize();
2382                 double[] b = {1.0,2.0,0.0};
2383                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2384                 {
2385                         Assert.AreEqual (a[i], b[i], "#TI03 " + i);
2386                 }
2387         }
2388
2389         [Test]
2390         public void TestInitializeFloat()
2391         {
2392                 float[] a = {1.0F,2.0F,0.0F};
2393                 a.Initialize();
2394                 float[] b = {1.0F,2.0F,0.0F};
2395                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2396                 {
2397                         Assert.AreEqual (a[i], b[i], "#TI04 " + i);
2398                 }
2399         }
2400
2401         [Test]
2402         public void TestInitializeChar()
2403         {
2404                 char[] a = {'1','.','0','F','2','.','0','F'};
2405                 a.Initialize();
2406                 char[] b = {'1','.','0','F','2','.','0','F'};
2407                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2408                 {
2409                         Assert.AreEqual (a[i], b[i], "#TI05 " + i);
2410                 }
2411         }
2412
2413         [Test]
2414         public void TestInitializeString()
2415         {
2416                 string[] a = {"hola","adios","menos","mas"};
2417                 a.Initialize();
2418                 string[] b = {"hola","adios","menos","mas"};
2419                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2420                 {
2421                         Assert.AreEqual (a[i], b[i], "#TI06 " + i);
2422                 }
2423         }
2424
2425         [Test]
2426         public void TestInitializeEnum()
2427         {
2428                 enua[] a = {enua.hola,enua.adios,enua.menos,enua.mas};
2429                 a.Initialize();
2430                 enua[] b = {enua.hola,enua.adios,enua.menos,enua.mas};
2431                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2432                 {
2433                         Assert.AreEqual (a[i], b[i], "#TI07 " + i);
2434                 }
2435         }
2436         
2437         [Test]
2438         public void TestInitializeIntNI()
2439         {
2440                 int[] a = new int[20];
2441                 a.Initialize();
2442                 foreach(int b in a)
2443                 {
2444                         Assert.AreEqual (b, 0, "#TI08");
2445                 }
2446         }
2447         
2448         [Test]
2449         public void TestInitializeCharNI()
2450         {
2451                 char[] a = new char[20];
2452                 a.Initialize();
2453                 foreach(char b in a)
2454                 {
2455                         Assert.AreEqual (b, 0, "#TI09");
2456                 }
2457         }
2458         
2459         [Test]
2460         public void TestInitializeDoubleNI()
2461         {
2462                 double[] a = new double[20];
2463                 a.Initialize();
2464                 foreach(double b in a)
2465                 {
2466                         Assert.AreEqual (b, 0.0, "#TI09");
2467                 }
2468         }
2469         
2470         [Test]
2471         public void TestInitializeStringNI()
2472         {
2473                 string[] a = new string[20];
2474                 a.Initialize();
2475                 foreach(string b in a)
2476                 {
2477                         Assert.AreEqual (b, null, "#TI10");
2478                 }
2479         }
2480         
2481         [Test]
2482         public void TestInitializeObjectNI()
2483         {
2484                 object[] a = new object[20];
2485                 a.Initialize();
2486                 foreach(object b in a)
2487                 {
2488                         Assert.AreEqual (b, null, "#TI11");
2489                 }
2490         }
2491
2492         [Test]
2493         public void TestInitializeAClassNI()
2494         {
2495                 AClass[] a = new AClass[20];
2496                 a.Initialize();
2497                 foreach(AClass b in a)
2498                 {
2499                         Assert.AreEqual (b, null, "#TI12");
2500                 }
2501         }
2502
2503
2504         [Test]
2505         public void TestInitializeAStructNI()
2506         {
2507                 AStruct[] a = new AStruct[20];
2508                 a.Initialize();
2509                 foreach(AStruct b in a)
2510                 {
2511                         Assert.AreEqual (b, new AStruct(), "#TI14");
2512                 }
2513         }
2514
2515         [Test]
2516         public void TestInitializeAStruct()
2517         {
2518                 AStruct[] a = new AStruct[3];
2519                 a[1].a = "ADIOS";
2520                 a[1].s = "HOLA";
2521                 a.Initialize();
2522                 AStruct[] b = new AStruct[3];
2523                 b[1].a = "ADIOS";
2524                 b[1].s = "HOLA";
2525                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2526                 {
2527                         Assert.AreEqual (a[i], b[i], "#TI15 " + i);
2528                 }
2529         }
2530
2531         [Test]
2532         public void TestInitializeDateTimeNI()
2533         {
2534                 DateTime[] a = new DateTime[20];
2535                 a.Initialize();
2536                 foreach(DateTime b in a)
2537                 {
2538                         Assert.AreEqual (b, new DateTime(), "#TI16");
2539                 }
2540         }
2541         
2542         [Test]
2543         [ExpectedException (typeof (ArgumentNullException))]
2544         public void MoreSort1 ()
2545         {
2546                 Array.Sort (null, 0, 1);
2547         }
2548
2549         [Test]
2550         [ExpectedException (typeof (ArgumentOutOfRangeException))]
2551         public void MoreSort2 ()
2552         {
2553                 Array.Sort (arrsort, -1, 3);
2554         }
2555
2556         [Test]
2557         [ExpectedException (typeof (ArgumentOutOfRangeException))]
2558         public void MoreSort3 ()
2559         {
2560                 Array.Sort (arrsort, 1, -3);
2561         }
2562
2563         [Test]
2564         [ExpectedException (typeof (ArgumentException))]
2565         public void MoreSort4 ()
2566         {
2567                 Array.Sort (arrsort, arrsort.Length, arrsort.Length + 2);
2568         }
2569
2570         [Test]
2571         [ExpectedException (typeof (RankException))]
2572         public void MoreSort5 ()
2573         {
2574                 char [,] arr = new char [,] {{'a'}, {'b'}};
2575                 Array.Sort (arr, 0, 1);
2576         }
2577
2578         [Test]
2579         public void MoreSort6 ()
2580         {
2581                 Array.Sort (arrsort, 0, 0);
2582         }
2583
2584         [Test]
2585         [ExpectedException (typeof (ArgumentException))]
2586         public void MoreSort7 ()
2587         {
2588                 Array.Sort (arrsort, arrsort.Length - 1, 2);
2589         }
2590
2591         [Test]
2592         [ExpectedException (typeof (ArgumentException))]
2593         public void MoreSort8 ()
2594         {
2595                 Array.Sort (arrsort, 0, arrsort.Length + 1);
2596         }
2597
2598         [Test]
2599         public void MoreSort9 ()
2600         {
2601                 Array.Sort (arrsort, null, 0, arrsort.Length, null);
2602         }
2603
2604         [Test]
2605         [ExpectedException (typeof (InvalidOperationException))]
2606         public void MoreSort10 ()
2607         {
2608                 object [] array = {true, 'k', SByte.MinValue, Byte.MinValue, (short) 2, 634, (long) 436, (float) 1.1, 1.23, "Hello World"};
2609                 Array.Sort (array, (IComparer) null);
2610         }
2611
2612         [Test] // bug #81941
2613         public void Sort ()
2614         {
2615                 double [] a = new double [2] { 0.9, 0.3 };
2616                 uint [] b = new uint [2] { 4, 7 };
2617                 Array.Sort (a, b);
2618                 Assert.AreEqual (0.3, a [0], "#1");
2619                 Assert.AreEqual (0.9, a [1], "#2");
2620                 Assert.AreEqual (7, b [0], "#3");
2621                 Assert.AreEqual (4, b [1], "#4");
2622         }
2623
2624         [Test]
2625         public void ClearJaggedArray () 
2626         {
2627                 byte[][] matrix = new byte [8][];
2628                 for (int i=0; i < 8; i++) {
2629                         matrix [i] = new byte [8];
2630                         for (int j=0; j < 8; j++) {
2631                                 matrix [i][j] = 1;
2632                         }
2633                 }
2634                 Array.Clear (matrix, 0, 8);
2635                 for (int i=0; i < 8; i++) {
2636                         Assert.IsNull (matrix [i], i.ToString ());
2637                 }
2638         }
2639
2640         [Test]
2641         public void ClearMultidimentionalArray () 
2642         {
2643                 byte[,] matrix = new byte [2,2] { {1, 1}, {2, 2} };
2644                 Array.Clear (matrix, 0, 2);
2645                 Assert.AreEqual (0, matrix [0, 0], "0,0");
2646                 Assert.AreEqual (0, matrix [0, 1], "0,1");
2647                 Assert.AreEqual (2, matrix [1, 0], "1,0");
2648                 Assert.AreEqual (2, matrix [1, 1], "1,1");
2649         }
2650
2651         [Test]
2652         [ExpectedException (typeof (IndexOutOfRangeException))]
2653         public void ClearOutsideMultidimentionalArray () 
2654         {
2655                 byte[,] matrix = new byte [2,2] { {1, 1}, {2, 2} };
2656                 Array.Clear (matrix, 0, 5);
2657         }
2658
2659         [Test]
2660         [ExpectedException (typeof (IndexOutOfRangeException))]
2661         public void Clear_IndexOverflow () 
2662         {
2663                 byte[] array = new byte [16];
2664                 Array.Clear (array, 4, Int32.MaxValue);
2665         }
2666
2667         [Test]
2668         [ExpectedException (typeof (IndexOutOfRangeException))]
2669         public void Clear_LengthOverflow () 
2670         {
2671                 byte[] array = new byte [16];
2672                 Array.Clear (array, Int32.MaxValue, 4);
2673         }
2674
2675         [Test]
2676         [ExpectedException (typeof (ArgumentException))]
2677         public void Copy_SourceIndexOverflow () 
2678         {
2679                 byte[] array = new byte [16];
2680                 Array.Copy (array, Int32.MaxValue, array, 8, 8);
2681         }
2682
2683         [Test]
2684         [ExpectedException (typeof (ArgumentException))]
2685         public void Copy_DestinationIndexOverflow () 
2686         {
2687                 byte[] array = new byte [16];
2688                 Array.Copy (array, 8, array, Int32.MaxValue, 8);
2689         }
2690
2691         [Test]
2692         [ExpectedException (typeof (ArgumentException))]
2693         public void Copy_LengthOverflow () 
2694         {
2695                 byte[] array = new byte [16];
2696                 Array.Copy (array, 8, array, 8, Int32.MaxValue);
2697         }
2698
2699         [Test]
2700         [ExpectedException (typeof (ArgumentException))]
2701         public void Reverse_IndexOverflow () 
2702         {
2703                 byte[] array = new byte [16];
2704                 Array.Reverse (array, Int32.MaxValue, 8);
2705         }
2706
2707         [Test]
2708         [ExpectedException (typeof (ArgumentException))]
2709         public void Reverse_LengthOverflow () 
2710         {
2711                 byte[] array = new byte [16];
2712                 Array.Reverse (array, 8, Int32.MaxValue);
2713         }
2714         
2715         public struct CharX : IComparable {
2716                 public char c;
2717         
2718                 public CharX (char c)
2719                 {
2720                         this.c = c;
2721                 }
2722         
2723                 public int CompareTo (object obj)
2724                 {
2725                         if (obj is CharX)
2726                                 return c.CompareTo (((CharX) obj).c);
2727                         else
2728                                 return c.CompareTo (obj);
2729                 }
2730         }
2731
2732         [Test]
2733         public void BinarySearch_ArgPassingOrder ()
2734         {
2735                 //
2736                 // This tests that arguments are passed to the comprer in the correct
2737                 // order. The IComparable of the *array* elements must get called, not
2738                 // that of the search object.
2739                 //
2740                 CharX [] x = { new CharX ('a'), new CharX ('b'), new CharX ('c') };
2741                 Assert.AreEqual (1, Array.BinarySearch (x, 'b'));
2742         }
2743
2744         class Comparer: IComparer {
2745
2746                 private bool called = false;
2747
2748                 public bool Called {
2749                         get {
2750                                 bool result = called;
2751                                 called = false;
2752                                 return called;
2753                         }
2754                 }
2755
2756                 public int Compare (object x, object y)
2757                 {
2758                         called = true;
2759                         return 0;
2760                 }
2761         }
2762
2763         [Test]
2764         public void BinarySearch1_EmptyList ()
2765         {
2766                 int[] array = new int[0];
2767                 Assert.AreEqual (- 1, Array.BinarySearch (array, 0), "BinarySearch");
2768         }
2769
2770         [Test]
2771         public void BinarySearch2_EmptyList ()
2772         {
2773                 int[] array = new int[0];
2774                 Assert.AreEqual (-1, Array.BinarySearch (array, 0, 0, 0), "BinarySearch");
2775         }
2776
2777         [Test]
2778         public void BinarySearch3_EmptyList ()
2779         {
2780                 Comparer comparer = new Comparer ();
2781                 int[] array = new int[0];
2782                 Assert.AreEqual (-1, Array.BinarySearch (array, 0, comparer), "BinarySearch");
2783                 // bug 77030 - the comparer isn't called for an empty array/list
2784                 Assert.IsTrue (!comparer.Called, "Called");
2785         }
2786
2787         [Test]
2788         public void BinarySearch4_EmptyList ()
2789         {
2790                 Comparer comparer = new Comparer ();
2791                 int[] array = new int[0];
2792                 Assert.AreEqual (-1, Array.BinarySearch (array, 0, 0, comparer), "BinarySearch");
2793                 // bug 77030 - the comparer isn't called for an empty array/list
2794                 Assert.IsTrue (!comparer.Called, "Called");
2795         }
2796
2797 #if NET_2_0
2798         [Test]
2799         [ExpectedException (typeof (ArgumentNullException))]
2800         public void AsReadOnly_NullArray ()
2801         {
2802                 Array.AsReadOnly <int> (null);
2803         }
2804
2805         [Test]
2806         public void ReadOnly_Count ()
2807         {
2808                 Assert.AreEqual (10, Array.AsReadOnly (new int [10]).Count);
2809         }
2810
2811         [Test]
2812         public void ReadOnly_Contains ()
2813         {
2814                 int[] arr = new int [2];
2815                 arr [0] = 3;
2816                 arr [1] = 5;
2817                 IList<int> a = Array.AsReadOnly (arr);
2818
2819                 Assert.IsTrue (a.Contains (3));
2820                 Assert.IsTrue (!a.Contains (6));
2821         }
2822
2823         [Test]
2824         public void ReadOnly_IndexOf ()
2825         {
2826                 int[] arr = new int [2];
2827                 arr [0] = 3;
2828                 arr [1] = 5;
2829                 IList<int> a = Array.AsReadOnly (arr);
2830
2831                 Assert.AreEqual (0, a.IndexOf (3));
2832                 Assert.AreEqual (1, a.IndexOf (5));
2833                 Assert.AreEqual (-1, a.IndexOf (6));
2834         }
2835
2836         [Test]
2837         public void ReadOnly_Indexer ()
2838         {
2839                 int[] arr = new int [2];
2840                 arr [0] = 3;
2841                 arr [1] = 5;
2842                 IList<int> a = Array.AsReadOnly (arr);
2843
2844                 Assert.AreEqual (3, a [0]);
2845                 Assert.AreEqual (5, a [1]);
2846
2847                 /* Check that modifications to the original array are visible */
2848                 arr [0] = 6;
2849                 Assert.AreEqual (6, a [0]);
2850         }
2851
2852         [Test]
2853         public void ReadOnly_Enumerator ()
2854         {
2855                 int[] arr = new int [10];
2856
2857                 for (int i = 0; i < 10; ++i)
2858                         arr [i] = i;
2859
2860                 int sum = 0;
2861                 foreach (int i in Array.AsReadOnly (arr))
2862                         sum += i;
2863
2864                 Assert.AreEqual (45, sum);
2865         }
2866
2867         [Test]
2868         public void ReadOnly_CopyTo ()
2869         {
2870                 int[] arr = new int [2];
2871                 arr [0] = 3;
2872                 arr [1] = 5;
2873                 IList<int> a = Array.AsReadOnly (arr);
2874
2875                 int[] arr2 = new int [3];
2876                 a.CopyTo (arr2, 1);
2877
2878                 Assert.AreEqual (0, arr2 [0]);
2879                 Assert.AreEqual (3, arr2 [1]);
2880                 Assert.AreEqual (5, arr2 [2]);
2881         }
2882
2883         [Test]
2884         public void Resize ()
2885         {
2886                 int [] arr = new int [] { 1, 3, 5 };
2887                 Array.Resize <int> (ref arr, 3);
2888                 Assert.AreEqual (3, arr.Length, "#A1");
2889                 Assert.AreEqual (1, arr [0], "#A2");
2890                 Assert.AreEqual (3, arr [1], "#A3");
2891                 Assert.AreEqual (5, arr [2], "#A4");
2892
2893                 Array.Resize <int> (ref arr, 2);
2894                 Assert.AreEqual (2, arr.Length, "#B1");
2895                 Assert.AreEqual (1, arr [0], "#B2");
2896                 Assert.AreEqual (3, arr [1], "#B3");
2897
2898                 Array.Resize <int> (ref arr, 4);
2899                 Assert.AreEqual (4, arr.Length, "#C1");
2900                 Assert.AreEqual (1, arr [0], "#C2");
2901                 Assert.AreEqual (3, arr [1], "#C3");
2902                 Assert.AreEqual (0, arr [2], "#C4");
2903                 Assert.AreEqual (0, arr [3], "#C5");
2904         }
2905
2906         [Test]
2907         public void Resize_null ()
2908         {
2909                 int [] arr = null;
2910                 Array.Resize (ref arr, 10);
2911                 Assert.AreEqual (arr.Length, 10);
2912         }
2913
2914         [Test]
2915         public void Test_ContainsAndIndexOf_EquatableItem ()
2916         {
2917                 EquatableClass[] list = new EquatableClass[] {new EquatableClass (0), new EquatableClass (1), new EquatableClass (0)};
2918
2919                 Assert.AreEqual (0, Array.IndexOf<EquatableClass> (list, list[0]), "#0");
2920                 Assert.AreEqual (0, Array.IndexOf<EquatableClass> (list, new EquatableClass (0)), "#1");
2921                 Assert.AreEqual (2, Array.LastIndexOf<EquatableClass> (list, list[0]), "#2");
2922                 Assert.AreEqual (2, Array.LastIndexOf<EquatableClass> (list, new EquatableClass (0)), "#3");
2923         }
2924
2925         public class EquatableClass : IEquatable<EquatableClass>
2926         {
2927                 int _x;
2928                 public EquatableClass (int x)
2929                 {
2930                         _x = x;
2931                 }
2932
2933                 public bool Equals (EquatableClass other)
2934                 {
2935                         return this._x == other._x;
2936                 }
2937         }
2938
2939         [Test]
2940         public void AsIList ()
2941         {
2942                 IList<int> arr = new int [10];
2943                 arr [0] = 5;
2944                 Assert.AreEqual (5, arr [0]);
2945
2946                 IList<FooStruct> arr2 = new FooStruct [10];
2947                 FooStruct s = new FooStruct ();
2948                 s.i = 11;
2949                 s.j = 22;
2950                 arr2 [5] = s;
2951                 s = arr2 [5];
2952                 Assert.AreEqual (11, s.i);
2953                 Assert.AreEqual (22, s.j);
2954
2955                 IList<string> arr3 = new string [10];
2956                 arr3 [5] = "ABC";
2957                 Assert.AreEqual ("ABC", arr3 [5]);
2958         }
2959
2960         struct FooStruct {
2961                 public int i, j;
2962         }
2963
2964 #if !TARGET_JVM // BugBUG: T[] is not yet ICollection<T> under TARGET_JVM
2965         [Test]
2966         // From bug #80563
2967         public void ICollectionNull ()
2968         {
2969                 ICollection<object> test;
2970                 
2971                 test = new List<object>();
2972                 Assert.AreEqual (test.Contains (null), false, "list<o>");
2973
2974                 test = new object[] {};
2975                 Assert.AreEqual (test.Contains (null), false, "empty array");
2976
2977                 test = new object[] {null};
2978                 Assert.AreEqual (test.Contains (null), true, "array with null");
2979
2980                 test = new List<object>(test);
2981                 Assert.AreEqual (test.Contains (null), true, "List<object> with test");
2982                 
2983                 test = new object[] {new object()};
2984                 Assert.AreEqual (test.Contains (null), false, "array with object");
2985
2986                 test = new List<object>(test);
2987                 Assert.AreEqual (test.Contains (null), false, "array with test");
2988         }
2989 #endif // TARGET_JVM
2990 #endif
2991
2992         #region Bug 80299
2993
2994         enum ByteEnum : byte {}
2995         enum IntEnum : int {}
2996
2997         [Test]
2998         public void TestByteEnumArrayToByteArray ()
2999         {
3000                 ByteEnum[] a = new ByteEnum[] {(ByteEnum) 1, (ByteEnum) 2};
3001                 byte[] b = new byte[a.Length];
3002                 a.CopyTo (b, 0);
3003         }
3004
3005         [Test]
3006         public void TestByteEnumArrayToIntArray ()
3007         {
3008                 ByteEnum[] a = new ByteEnum[] {(ByteEnum) 1, (ByteEnum) 2};
3009                 int[] b = new int[a.Length];
3010                 a.CopyTo (b, 0);
3011         }
3012
3013         [Test]
3014         [ExpectedException (typeof (ArrayTypeMismatchException))]
3015         public void TestIntEnumArrayToByteArray ()
3016         {
3017                 IntEnum[] a = new IntEnum[] {(IntEnum) 1, (IntEnum) 2};
3018                 byte[] b = new byte[a.Length];
3019                 a.CopyTo (b, 0);
3020         }
3021
3022         [Test]
3023         public void TestIntEnumArrayToIntArray ()
3024         {
3025                 IntEnum[] a = new IntEnum[] {(IntEnum) 1, (IntEnum) 2};
3026                 int[] b = new int[a.Length];
3027                 a.CopyTo (b, 0);
3028         }
3029
3030         #endregion
3031
3032 #if NET_2_0
3033         [Test] // bug #322248
3034         public void IEnumerator_Reset ()
3035         {
3036                 int[] array = new int[] { 1, 2, 3};
3037                 IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
3038                 Assert.IsTrue (e.MoveNext (), "#A1");
3039                 Assert.AreEqual (1, e.Current, "#A2");
3040                 Assert.IsTrue (e.MoveNext (), "#A3");
3041                 Assert.AreEqual (2, e.Current, "#A4");
3042
3043                 e.Reset ();
3044
3045                 Assert.IsTrue (e.MoveNext (), "#C1");
3046                 Assert.AreEqual (1, e.Current, "#C2");
3047         }
3048
3049         [Test]
3050         public void IEnumerator_Current_Finished ()
3051         {
3052                 int[] array = new int[] { 1, 2, 3 };
3053                 IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
3054                 Assert.IsTrue (e.MoveNext (), "#A1");
3055                 Assert.AreEqual (1, e.Current, "#A2");
3056                 Assert.IsTrue (e.MoveNext (), "#A3");
3057                 Assert.AreEqual (2, e.Current, "#A4");
3058                 Assert.IsTrue (e.MoveNext (), "#A5");
3059                 Assert.AreEqual (3, e.Current, "#A6");
3060                 Assert.IsTrue (!e.MoveNext (), "#A6");
3061
3062                 try {
3063                         Assert.Fail ("#B1:" + e.Current);
3064                 } catch (InvalidOperationException ex) {
3065                         // Enumeration already finished
3066                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
3067                         Assert.IsNull (ex.InnerException, "#B3");
3068                         Assert.IsNotNull (ex.Message, "#B4");
3069                 }
3070         }
3071
3072         [Test]
3073         public void IEnumerator_Current_NotStarted ()
3074         {
3075                 int[] array = new int[] { 1, 2, 3 };
3076                 IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
3077
3078                 try {
3079                         Assert.Fail ("#A1:" + e.Current);
3080                 } catch (InvalidOperationException ex) {
3081                         // Enumeration has not started. Call MoveNext
3082                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
3083                         Assert.IsNull (ex.InnerException, "#A3");
3084                         Assert.IsNotNull (ex.Message, "#A4");
3085                 }
3086         }
3087
3088         [Test]
3089         public void IEnumerator_Current_Reset ()
3090         {
3091                 int[] array = new int[] { 1, 2, 3 };
3092                 IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
3093                 e.MoveNext ();
3094                 e.Reset ();
3095
3096                 try {
3097                         Assert.Fail ("#B1:" + e.Current);
3098                 } catch (InvalidOperationException ex) {
3099                         // Enumeration has not started. Call MoveNext
3100                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
3101                         Assert.IsNull (ex.InnerException, "#B3");
3102                         Assert.IsNotNull (ex.Message, "#B4");
3103                 }
3104         }
3105
3106         public void ICollection_IsReadOnly() {
3107                 ICollection<string> arr = new string [10];
3108
3109                 Assert.IsTrue (arr.IsReadOnly);
3110         }
3111 #endif
3112
3113         [Test]
3114         [ExpectedException (typeof (NotSupportedException))]
3115         public void ArrayCreateInstanceOfVoid ()
3116         {
3117                 Array.CreateInstance (typeof (void), 42);
3118         }
3119
3120         class Foo<T> {}
3121
3122         [Test]
3123         [ExpectedException (typeof (NotSupportedException))]
3124         public void ArrayCreateInstanceOfOpenGenericType ()
3125         {
3126                 Array.CreateInstance (typeof (Foo<>), 42);
3127         }
3128
3129         [Test]
3130         [ExpectedException (typeof (IndexOutOfRangeException))]
3131         public void ClearNegativeLength ()
3132         {
3133                 Array.Clear (new int [] { 1, 2 }, 0, -1);
3134         }
3135
3136         [Test]
3137         [ExpectedException (typeof (ArgumentException))]
3138         public void MultiDimension_IList_setItem ()
3139         {
3140                 IList array = new int [1, 1];
3141                 array [0] = 2;
3142         }
3143
3144         [Test]
3145         [ExpectedException (typeof (ArgumentException))]
3146         public void MultiDimension_IList_getItem ()
3147         {
3148                 IList array = new int [1, 1];
3149                 int a = (int) array [0];
3150         }
3151
3152         [Test]
3153         public void SetValue_Nullable () {
3154                 Array array = Array.CreateInstance (typeof (int?), 7);
3155
3156                 object o = 42;
3157
3158                 array.SetValue (o, 0);
3159                 Assert.AreEqual (42, array.GetValue (0));
3160
3161                 array.SetValue (null, 0);
3162                 Assert.AreEqual (null, array.GetValue (0));
3163         }
3164
3165         [Test]
3166         public void SortNullsWithGenericVersion ()
3167         {
3168             string[] s1 = new string[6]{
3169                 "J",
3170                 "M",
3171                  null,
3172                 "P",
3173                 "T",
3174                 "A"};
3175
3176             string[] s2 = new string[]{null,
3177                 "A",
3178                 "J",
3179                 "M",
3180                 "P",
3181                 "T"};
3182
3183             Array.Sort<string> (s1);
3184             for (int i = 0; i < 6; i++) {
3185                     Assert.AreEqual (s1[i], s2[i], "At:" + i);
3186             }
3187         }
3188         
3189         //
3190         // This is a test case for the case that was broken by the code contributed
3191         // for bug  #351638.
3192         //
3193         // This tests the fix for: #622101
3194         //
3195         [Test]
3196         public void SortActuallyWorks ()
3197         {
3198                 string[] data = new string[9]{"Foo", "Bar", "Dingus", null, "Dingu4", "123", "Iam", null, "NotNull"};
3199                 IComparer comparer = new NullAtEndComparer ();
3200                 Array.Sort (data, comparer);
3201
3202                 Assert.AreEqual (data [7], null);
3203                 Assert.AreNotEqual (data [0], null);
3204         }
3205
3206         class NullAtEndComparer : IComparer {
3207                 public int Compare(object x, object y)
3208                 {
3209                         if (x == null) return 1;
3210                         if (y == null) return -1;
3211                         return ((string)x).CompareTo((string)y);
3212                 }
3213         }
3214
3215 #if NET_4_0
3216         [Test]
3217         [ExpectedException (typeof (ArgumentException))]
3218         public void CompareToWithJaggedArray () {
3219                 IStructuralComparable a = new int[][] { new int [] { 1,2 }, new int [] { 3,4 }};
3220                 IStructuralComparable b = new int[][] { new int [] { 1,2 }, new int [] { 3,4 }};
3221                 a.CompareTo (b, Comparer<object>.Default);
3222         }
3223
3224         [Test]
3225         [ExpectedException (typeof (ArgumentException))]
3226         public void CompareToWithArrayOfTheWrongKind () {
3227                 IStructuralComparable a = new int[] { 1, 2 };
3228                 IStructuralComparable b = new double[] { 1, 2 };
3229                 a.CompareTo (b, Comparer<object>.Default);
3230         }
3231
3232         [Test]
3233         [ExpectedException (typeof (ArgumentException))]
3234         public void CompareToWithNonArrayType () {
3235                 IStructuralComparable a = new int[] { 1, 2 };
3236                 a.CompareTo (99, Comparer<object>.Default);
3237         }
3238
3239         [Test]
3240         [ExpectedException (typeof (ArgumentException))]
3241         public void CompareToWithNonArrayOfDifferentSize () {
3242                 IStructuralComparable a = new int[] { 1, 2 };
3243                 IStructuralComparable b = new int[] { 1, 2, 3 };
3244                 a.CompareTo (b, Comparer<object>.Default);
3245         }
3246
3247         [Test]
3248         [ExpectedException (typeof (ArgumentException))]
3249         public void CompareToWithMultiDimArray1 () {
3250                 IStructuralComparable a = new int [2,2] { {10, 10 }, { 10, 10 } };
3251                 IStructuralComparable b = new int [2,2] { {10, 10 }, { 10, 10 } };
3252                 a.CompareTo (b, Comparer<object>.Default);
3253         }
3254
3255         [Test]
3256         [ExpectedException (typeof (ArgumentException))]
3257         public void CompareToWithMultiDimArray2 () {
3258                 IStructuralComparable a = new int [2] { 10, 10 };
3259                 IStructuralComparable b = new int [2,2] { {10, 10 }, { 10, 10 } };
3260                 a.CompareTo (b, Comparer<object>.Default);
3261         }
3262
3263         [Test]
3264         [ExpectedException (typeof (ArgumentException))]
3265         public void CompareToWithMultiDimArray3 () {
3266                 IStructuralComparable a = new int [4] { 10, 10, 10, 10 };
3267                 IStructuralComparable b = new int [2,2] { {10, 10 }, { 10, 10 } };
3268                 a.CompareTo (b, Comparer<object>.Default);
3269         }
3270
3271         [Test]
3272         [ExpectedException (typeof (IndexOutOfRangeException))]
3273         public void CompareToWithBoundedArray1 () {
3274                 IStructuralComparable a = new int [2] { 10, 10 };
3275                 Array ab = Array.CreateInstance (typeof (int), new int[] { 2 }, new int [] { 5 });
3276                 IStructuralComparable b = ab;
3277                 ab.SetValue (10, 5);
3278                 ab.SetValue (10, 6);
3279
3280                 a.CompareTo (b, Comparer<object>.Default);
3281         }
3282
3283         [Test]
3284         [ExpectedException (typeof (IndexOutOfRangeException))]
3285         public void CompareToWithBoundedArray2 () {
3286                 IStructuralComparable a = new int [2] { 10, 10 };
3287                 Array ab = Array.CreateInstance (typeof (int), new int[] { 2 }, new int [] { 5 });
3288                 IStructuralComparable b = ab;
3289                 ab.SetValue (10, 5);
3290                 ab.SetValue (10, 6);
3291
3292                 //Yes, CompareTo simply doesn't work with bounded arrays!
3293                 b.CompareTo (b, Comparer<object>.Default);
3294         }
3295
3296         [Test]
3297         [ExpectedException (typeof (NullReferenceException))]
3298         public void CompareToWithNullComparer () {
3299                 IStructuralComparable a = new int[] { 1, 2 };
3300                 IStructuralComparable b = new int[] { 1, 2 };
3301                 a.CompareTo (b, null);
3302         }
3303
3304         [Test]
3305         public void CompareToWithNullArray () {
3306                 IStructuralComparable a = new int[] { 1, 2 };
3307                 Assert.AreEqual (1, a.CompareTo (null, Comparer<object>.Default));
3308         }
3309
3310         [Test]
3311         public void CompareToWithGoodArrays () {
3312                 IStructuralComparable a = new int[] { 10, 20 };
3313                 Assert.AreEqual (0, a.CompareTo (a, Comparer<object>.Default));
3314                 Assert.AreEqual (0, a.CompareTo (new int [] { 10, 20 }, Comparer<object>.Default));
3315                 Assert.AreEqual (-1, a.CompareTo (new int [] { 11, 20 }, Comparer<object>.Default));
3316                 Assert.AreEqual (-1, a.CompareTo (new int [] { 10, 21 }, Comparer<object>.Default));
3317                 Assert.AreEqual (1, a.CompareTo (new int [] { 9, 20 }, Comparer<object>.Default));
3318                 Assert.AreEqual (1, a.CompareTo (new int [] { 10, 19 }, Comparer<object>.Default));
3319         }
3320
3321         [Test]
3322         public void IStructuralEquatable_Equals ()
3323         {
3324                 IStructuralEquatable array = new int[] {1, 2, 3};
3325                 IStructuralEquatable array2 = new int[] {1, 2, 3};
3326                 Assert.AreEqual (false, array.Equals (null, null));
3327                 Assert.AreEqual (true, array.Equals (array, null));
3328                 Assert.AreEqual (true, array.Equals (array2, EqualityComparer<int>.Default));
3329         }
3330
3331         [Test]
3332         [ExpectedException (typeof (NullReferenceException))]
3333         public void IStructuralEquatable_Equals_NoComparer ()
3334         {
3335                 IStructuralEquatable array = new int[] {1, 2, 3};
3336                 IStructuralComparable array2 = new int[] {1, 2, 3};
3337                 array.Equals (array2, null);
3338         }
3339
3340         [Test]
3341         [ExpectedException (typeof (ArgumentException))]
3342         public void IStructuralEquatable_Equals_ComparerThrows ()
3343         {
3344                 IStructuralEquatable array = new int[] {1, 2, 3};
3345                 IStructuralComparable array2 = new int[] {1, 2, 3};
3346                 array.Equals (array2, EqualityComparer<long>.Default);
3347         }
3348
3349 #endif
3350
3351 }
3352 }