2002-04-09 Nick Drochak <ndrochak@gol.com>
[mono.git] / mcs / class / corlib / Test / System / ArrayTest.cs
1 // ArrayTest.cs - NUnit Test Cases for the System.Array class\r
2 //\r
3 // David Brandt (bucky@keystreams.com)\r
4 //\r
5 // (C) Ximian, Inc.  http://www.ximian.com\r
6 // \r
7 \r
8 using NUnit.Framework;\r
9 using System;\r
10 using System.Collections;\r
11 using System.Globalization;\r
12 \r
13 namespace MonoTests.System\r
14 {\r
15 \r
16 public class ArrayTest : TestCase\r
17 {\r
18         public ArrayTest() : base ("MonoTests.System.ArrayTest testsuite") {}\r
19         public ArrayTest(string name) : base(name) {}\r
20 \r
21         protected override void SetUp() \r
22         {\r
23         }\r
24 \r
25         protected override void TearDown() \r
26         {\r
27         }\r
28 \r
29         public static ITest Suite {\r
30                 get { \r
31                         return new TestSuite(typeof(ArrayTest)); \r
32                 }\r
33         }\r
34     \r
35         public void TestIsFixedSize() {\r
36                 char[] a1 = {'a'};\r
37                 Assert("All arrays are fixed", a1.IsFixedSize);\r
38         }\r
39 \r
40         public void TestIsReadOnly() {\r
41                 char[] a1 = {'a'};\r
42                 Assert("No array is readonly", !a1.IsReadOnly);\r
43         }\r
44 \r
45         public void TestIsSynchronized() {\r
46                 char[] a1 = {'a'};\r
47                 Assert("No array is synchronized", !a1.IsSynchronized);\r
48         }\r
49 \r
50         public void TestLength() {\r
51                 {\r
52                         char[] a1 = { };\r
53                         AssertEquals("Zero length array", 0, a1.Length);\r
54                 }\r
55                 {\r
56                         char[] a1 = {'c'};\r
57                         AssertEquals("One-length array", 1, a1.Length);\r
58                 }\r
59                 {\r
60                         char[] a1 = {'c', 'c'};\r
61                         AssertEquals("Two-length array", 2, a1.Length);\r
62                 }\r
63         }\r
64 \r
65         public void TestRank() {\r
66                 char[] a1 = { 'c', 'd', 'e' };\r
67                 AssertEquals("Rank one", 1, a1.Rank);\r
68 \r
69                 char[,] a2 = new Char[3,3];\r
70                 AssertEquals("Rank two", 2, a2.Rank);\r
71 \r
72                 char[,,] a3 = new Char[3,3,3];\r
73                 AssertEquals("Rank three", 3, a3.Rank);\r
74         }\r
75 \r
76         public void TestBinarySearch1() {\r
77                 bool errorThrown = false;\r
78                 try {\r
79                         Array.BinarySearch(null, "blue");\r
80                 } catch (ArgumentNullException) {\r
81                         errorThrown = true;\r
82                 }\r
83                 Assert("#B01", errorThrown);\r
84                 errorThrown = false;\r
85                 try {\r
86                         char[,] c1 = new Char[2,2];\r
87                         Array.BinarySearch(c1, "needle");\r
88                 } catch (RankException) {\r
89                         errorThrown = true;\r
90                 }\r
91                 Assert("#B02", errorThrown);\r
92 \r
93                 {\r
94                         char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};\r
95                         Assert("#B05", \r
96                                Array.BinarySearch(arr, 'c') >= 3);\r
97                         Assert("#B06", \r
98                                Array.BinarySearch(arr, 'c') < 6);\r
99                 }\r
100                 {\r
101                         char[] arr = {'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};\r
102                         AssertEquals("#B07", \r
103                                      -4, Array.BinarySearch(arr, 'c'));\r
104                 }\r
105                 {\r
106                         char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};\r
107                         AssertEquals("#B08", \r
108                                      -9, Array.BinarySearch(arr, 'e'));\r
109                 }\r
110         }\r
111         public void TestBinarySearch2() {\r
112                 bool errorThrown = false;\r
113                 try {\r
114                         Array.BinarySearch(null, 0, 1, "blue");\r
115                 } catch (ArgumentNullException) {\r
116                         errorThrown = true;\r
117                 }\r
118                 Assert("#B20", errorThrown);\r
119                 errorThrown = false;\r
120                 try {\r
121                         char[,] c1 = new Char[2,2];\r
122                         Array.BinarySearch(c1, 0, 1, "needle");\r
123                 } catch (RankException) {\r
124                         errorThrown = true;\r
125                 }\r
126                 Assert("#B21", errorThrown);\r
127                 errorThrown = false;\r
128                 try {\r
129                         char[] c1 = {'a'};\r
130                         Array.BinarySearch(c1, -1, 1, 'a');\r
131                 } catch (ArgumentOutOfRangeException) {\r
132                         errorThrown = true;\r
133                 }\r
134                 Assert("#B22", errorThrown);\r
135                 errorThrown = false;\r
136                 try {\r
137                         char[] c1 = {'a'};\r
138                         Array.BinarySearch(c1, 0, -1, 'a');\r
139                 } catch (ArgumentOutOfRangeException) {\r
140                         errorThrown = true;\r
141                 }\r
142                 Assert("#B23", errorThrown);\r
143                 errorThrown = false;\r
144                 try {\r
145                         char[] c1 = {'a'};\r
146                         Array.BinarySearch(c1, 0, 4, 'a');\r
147                 } catch (ArgumentException) {\r
148                         errorThrown = true;\r
149                 }\r
150                 Assert("#B24", errorThrown);\r
151 \r
152                 {\r
153                         char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};\r
154                         Assert("#B26", \r
155                                Array.BinarySearch(arr, 2, 8, 'c') >= 5);\r
156                         Assert("#B27", \r
157                                Array.BinarySearch(arr, 2, 8, 'c') < 8);\r
158                 }\r
159                 {\r
160                         char[] arr = {'z', 'z', 'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};\r
161                         AssertEquals("#B28", \r
162                                      -6, Array.BinarySearch(arr, 2, 8, 'c'));\r
163                 }\r
164                 {\r
165                         char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};\r
166                         AssertEquals("#B29", \r
167                                      -11, Array.BinarySearch(arr, 2, 8, 'e'));\r
168                 }\r
169         }\r
170 \r
171         // TODO - testBinarySearch with explicit IComparer args\r
172 \r
173         public void TestClear() {\r
174                 bool errorThrown = false;\r
175                 try {\r
176                         Array.Clear(null, 0, 1);\r
177                 } catch (ArgumentNullException) {\r
178                         errorThrown = true;\r
179                 }\r
180                 Assert("#C01", errorThrown);\r
181 \r
182                 int[] i1 = { 1, 2, 3, 4 };\r
183                 {\r
184                         int[] compare = {1,2,3,4};\r
185                         AssertEquals("#C02", compare[0], i1[0]);\r
186                         AssertEquals("#C03", compare[1], i1[1]);\r
187                         AssertEquals("#C04", compare[2], i1[2]);\r
188                         AssertEquals("#C05", compare[3], i1[3]);\r
189                 }\r
190                 Array.Clear(i1, 3, 1);\r
191                 {\r
192                         int[] compare = {1,2,3,0};\r
193                         AssertEquals("#C06", compare[0], i1[0]);\r
194                         AssertEquals("#C07", compare[1], i1[1]);\r
195                         AssertEquals("#C08", compare[2], i1[2]);\r
196                         AssertEquals("#C09", compare[3], i1[3]);\r
197                 }\r
198                 Array.Clear(i1, 1, 1);\r
199                 {\r
200                         int[] compare = {1,0,3,0};\r
201                         AssertEquals("#C10", compare[0], i1[0]);\r
202                         AssertEquals("#C11", compare[1], i1[1]);\r
203                         AssertEquals("#C12", compare[2], i1[2]);\r
204                         AssertEquals("#C13", compare[3], i1[3]);\r
205                 }\r
206                 Array.Clear(i1, 1, 3);\r
207                 {\r
208                         int[] compare = {1,0,0,0};\r
209                         AssertEquals("#C14", compare[0], i1[0]);\r
210                         AssertEquals("#C15", compare[1], i1[1]);\r
211                         AssertEquals("#C16", compare[2], i1[2]);\r
212                         AssertEquals("#C17", compare[3], i1[3]);\r
213                 }\r
214 \r
215                 string[] s1 = { "red", "green", "blue" };\r
216                 Array.Clear(s1, 0, 3);\r
217                 {\r
218                         string[] compare = {null, null, null};\r
219                         AssertEquals("#C18", compare[0], s1[0]);\r
220                         AssertEquals("#C19", compare[1], s1[1]);\r
221                         AssertEquals("#C20", compare[2], s1[2]);\r
222                 }\r
223         }\r
224 \r
225         public void TestClone() {\r
226                 char[] c1 = {'a', 'b', 'c'};\r
227                 char[] c2 = (char[])c1.Clone();\r
228                 AssertEquals("#D01", c1[0], c2[0]);\r
229                 AssertEquals("#D02", c1[1], c2[1]);\r
230                 AssertEquals("#D03", c1[2], c2[2]);\r
231 \r
232                 char[] d10 = {'a', 'b'};\r
233                 char[] d11 = {'a', 'c'};\r
234                 char[] d12 = {'b', 'c'};\r
235                 char[][] d1 = {d10, d11, d12};\r
236                 char[][] d2 = (char[][])d1.Clone();\r
237                 AssertEquals("#D04", d1[0], d2[0]);\r
238                 AssertEquals("#D05", d1[1], d2[1]);\r
239                 AssertEquals("#D06", d1[2], d2[2]);\r
240 \r
241                 d1[0][0] = 'z';\r
242                 AssertEquals("#D07", d1[0], d2[0]);\r
243         }\r
244 \r
245         public void TestCopy() {\r
246                 {\r
247                         bool errorThrown = false;\r
248                         try {\r
249                                 Char[] c1 = {};\r
250                                 Array.Copy(c1, null, 1);\r
251                         } catch (ArgumentNullException) {\r
252                                 errorThrown = true;\r
253                         }\r
254                         Assert("#E01", errorThrown);\r
255                 }\r
256                 {\r
257                         bool errorThrown = false;\r
258                         try {\r
259                                 Char[] c1 = {};\r
260                                 Array.Copy(null, c1, 1);\r
261                         } catch (ArgumentNullException) {\r
262                                 errorThrown = true;\r
263                         }\r
264                         Assert("#E02", errorThrown);\r
265                 }\r
266                 {\r
267                         bool errorThrown = false;\r
268                         try {\r
269                                 Char[] c1 = new Char[1];\r
270                                 Char[,] c2 = new Char[1,1];\r
271                                 Array.Copy(c1, c2, 1);\r
272                         } catch (RankException) {\r
273                                 errorThrown = true;\r
274                         }\r
275                         Assert("#E03", errorThrown);\r
276                 }\r
277                 {\r
278                         bool errorThrown = false;\r
279                         try {\r
280                                 Char[] c1 = new Char[1];\r
281                                 string[] s1 = new String[1];\r
282                                 Array.Copy(c1, s1, 1);\r
283                         } catch (ArrayTypeMismatchException) {\r
284                                 errorThrown = true;\r
285                         }\r
286                         Assert("#E04", errorThrown);\r
287                 }\r
288                 {\r
289                         bool errorThrown = false;\r
290                         try {\r
291                                 Char[] c1 = new Char[1];\r
292                                 Object[] o1 = new Object[1];\r
293                                 o1[0] = "hello";\r
294                                 Array.Copy(o1, c1, 1);\r
295                         } catch (InvalidCastException) {\r
296                                 errorThrown = true;\r
297                         }\r
298                         Assert("#E05", errorThrown);\r
299                 }\r
300                 {\r
301                         bool errorThrown = false;\r
302                         try {\r
303                                 Char[] c1 = new Char[1];\r
304                                 Char[] c2 = new Char[1];\r
305                                 Array.Copy(c1, c2, -1);\r
306                         } catch (ArgumentOutOfRangeException) {\r
307                                 errorThrown = true;\r
308                         }\r
309                         Assert("#E06", errorThrown);\r
310                 }\r
311                 {\r
312                         bool errorThrown = false;\r
313                         try {\r
314                                 Char[] c1 = new Char[1];\r
315                                 Char[] c2 = new Char[2];\r
316                                 Array.Copy(c1, c2, 2);\r
317                         } catch (ArgumentException) {\r
318                                 errorThrown = true;\r
319                         }\r
320                         Assert("#E07", errorThrown);\r
321                 }\r
322                 {\r
323                         bool errorThrown = false;\r
324                         try {\r
325                                 Char[] c1 = new Char[1];\r
326                                 Char[] c2 = new Char[2];\r
327                                 Array.Copy(c2, c1, 2);\r
328                         } catch (ArgumentException) {\r
329                                 errorThrown = true;\r
330                         }\r
331                         Assert("#E08", errorThrown);\r
332                 }\r
333 \r
334                 char[] orig = {'a', 'b', 'd', 'a'};\r
335                 char[] copy = new Char[4];\r
336                 Array.Copy(orig, copy, 4);\r
337                 for (int i = 0; i < orig.Length; i++) {\r
338                         AssertEquals("#E09(" + i + ")",\r
339                                      orig[i], copy[i]);\r
340                 }\r
341                 Array.Clear(copy, 0, copy.Length);\r
342                 for (int i = 0; i < orig.Length; i++) {\r
343                         AssertEquals("#E10(" + i + ")",\r
344                                      (char)0, copy[i]);\r
345                 }\r
346                 Array.Copy(orig, copy, 2);\r
347                 AssertEquals("#E11", orig[0], copy[0]);\r
348                 AssertEquals("#E12", orig[1], copy[1]);\r
349                 Assert("#E13", orig[2] != copy[2]);\r
350                 Assert("#E14", orig[3] != copy[3]);\r
351         }\r
352         public void TestCopy2() {\r
353                 {\r
354                         bool errorThrown = false;\r
355                         try {\r
356                                 Char[] c1 = new Char[2];\r
357                                 Char[] c2 = new Char[2];\r
358                                 Array.Copy(c2, 1, c1, 0, 2);\r
359                         } catch (ArgumentException) {\r
360                                 errorThrown = true;\r
361                         }\r
362                         Assert("#E31", errorThrown);\r
363                 }\r
364                 {\r
365                         bool errorThrown = false;\r
366                         try {\r
367                                 Char[] c1 = new Char[2];\r
368                                 Char[] c2 = new Char[2];\r
369                                 Array.Copy(c2, 0, c1, 1, 2);\r
370                         } catch (ArgumentException) {\r
371                                 errorThrown = true;\r
372                         }\r
373                         Assert("#E32", errorThrown);\r
374                 }\r
375                 \r
376                 char[] orig = {'a', 'b', 'd', 'a'};\r
377                 char[] copy = new Char[4];\r
378                 Array.Copy(orig, 1, copy, 1, 3);\r
379                 Assert("#E33", copy[0] != orig[0]);\r
380                 for (int i = 1; i < orig.Length; i++) {\r
381                         AssertEquals("#E34(" + i + ")",\r
382                                      orig[i], copy[i]);\r
383                 }\r
384                 Array.Clear(copy, 0, copy.Length);\r
385                 Array.Copy(orig, 1, copy, 0, 2);\r
386                 AssertEquals("#E35", orig[1], copy[0]);\r
387                 AssertEquals("#E36", orig[2], copy[1]);\r
388                 Assert("#E37", copy[2] != orig[2]);\r
389                 Assert("#E38", copy[3] != orig[3]);\r
390         }\r
391 \r
392         public void TestCopyTo() {\r
393                 {\r
394                         bool errorThrown = false;\r
395                         try {\r
396                                 Char[] c1 = new Char[2];\r
397                                 c1.CopyTo(null, 2);\r
398                         } catch (ArgumentNullException) {\r
399                                 errorThrown = true;\r
400                         }\r
401                         Assert("#E61", errorThrown);\r
402                 }\r
403                 {\r
404                         bool errorThrown = false;\r
405                         try {\r
406                                 Char[] c1 = new Char[2];\r
407                                 Char[,] c2 = new Char[2,2];\r
408                                 c1.CopyTo(c2, 2);\r
409                         } catch (ArgumentException) {\r
410                                 errorThrown = true;\r
411                         }\r
412                         Assert("#E62", errorThrown);\r
413                 }\r
414                 {\r
415                         bool errorThrown = false;\r
416                         try {\r
417                                 Char[,] c1 = new Char[2,2];\r
418                                 Char[] c2 = new Char[2];\r
419                                 c1.CopyTo(c2, -1);\r
420                         } catch (RankException) {\r
421                                 errorThrown = true;\r
422                         }\r
423                         Assert("#E63", errorThrown);\r
424                 }\r
425                 {\r
426                         bool errorThrown = false;\r
427                         try {\r
428                                 Char[,] c1 = new Char[2,2];\r
429                                 Char[] c2 = new Char[2];\r
430                                 c1.CopyTo(c2, 2);\r
431                         } catch (RankException) {\r
432                                 errorThrown = true;\r
433                         }\r
434                         Assert("#E64", errorThrown);\r
435                 }\r
436                 {\r
437                         bool errorThrown = false;\r
438                         try {\r
439                                 Char[] c1 = new Char[2];\r
440                                 Char[] c2 = new Char[2];\r
441                                 c1.CopyTo(c2, -1);\r
442                         } catch (ArgumentOutOfRangeException) {\r
443                                 errorThrown = true;\r
444                         }\r
445                         Assert("#E65", errorThrown);\r
446                 }\r
447                 {\r
448                         bool errorThrown = false;\r
449                         try {\r
450                                 Char[] c1 = new Char[2];\r
451                                 Char[] c2 = new Char[2];\r
452                                 c1.CopyTo(c2, 3);\r
453                         } catch (ArgumentException) {\r
454                                 errorThrown = true;\r
455                         }\r
456                         Assert("#E66", errorThrown);\r
457                 }\r
458                 {\r
459                         bool errorThrown = false;\r
460                         try {\r
461                                 Char[] c1 = new Char[2];\r
462                                 Char[] c2 = new Char[2];\r
463                                 c1.CopyTo(c2, 1);\r
464                         } catch (ArgumentException) {\r
465                                 errorThrown = true;\r
466                         }\r
467                         Assert("#E67", errorThrown);\r
468                 }\r
469                 {\r
470                         bool errorThrown = false;\r
471                         try {\r
472                                 String[] c1 = new String[2];\r
473                                 Char[] c2 = new Char[2];\r
474                                 // FIXME: Our implementation doesn't throw an exception if\r
475                                 //        this is uninitialized.\r
476                                 c1[0] = "Hello";\r
477                                 c1[1] = "World";\r
478                                 c1.CopyTo(c2, 0);\r
479                         } catch (ArrayTypeMismatchException) {\r
480                                 errorThrown = true;\r
481                         }\r
482                         Assert("#E68", errorThrown);\r
483                 }\r
484 \r
485                 Char[] orig = {'a', 'b', 'c', 'd'};\r
486                 Char[] copy = new Char[10];\r
487                 Array.Clear(copy, 0, copy.Length);\r
488                 orig.CopyTo(copy, 3);\r
489                 AssertEquals("#E69", (char)0, copy[0]);\r
490                 AssertEquals("#E70", (char)0, copy[1]);\r
491                 AssertEquals("#E71", (char)0, copy[2]);\r
492                 AssertEquals("#E72", orig[0], copy[3]);\r
493                 AssertEquals("#E73", orig[1], copy[4]);\r
494                 AssertEquals("#E74", orig[2], copy[5]);\r
495                 AssertEquals("#E75", orig[3], copy[6]);\r
496                 AssertEquals("#E76", (char)0, copy[7]);\r
497                 AssertEquals("#E77", (char)0, copy[8]);\r
498                 AssertEquals("#E78", (char)0, copy[9]);\r
499 \r
500                 {\r
501                         // The following is valid and must not throw an exception.\r
502                         bool errorThrown = false;\r
503                         try {\r
504                                 int[] src = new int [0];\r
505                                 int[] dest = new int [0];\r
506                                 src.CopyTo (dest, 0);\r
507                         } catch (ArgumentException) {\r
508                                 errorThrown = true;\r
509                         }\r
510                         Assert("#E79", !errorThrown);\r
511                 }\r
512         }\r
513 \r
514         public void TestCreateInstance() {\r
515                 {\r
516                         bool errorThrown = false;\r
517                         try {\r
518                                 Array.CreateInstance(null, 12);\r
519                         } catch (ArgumentNullException) {\r
520                                 errorThrown = true;\r
521                         }\r
522                         Assert("#F01", errorThrown);\r
523                 }\r
524                 {\r
525                         bool errorThrown = false;\r
526                         try {\r
527                                 Array.CreateInstance(Type.GetType("System.Char"), -3);\r
528                         } catch (ArgumentOutOfRangeException) {\r
529                                 errorThrown = true;\r
530                         }\r
531                         Assert("#F02", errorThrown);\r
532                 }\r
533                 {\r
534                         bool errorThrown = false;\r
535                         try {\r
536                                 Array.CreateInstance(Type.GetType("System.Char"), null);\r
537                         } catch (ArgumentNullException) {\r
538                                 errorThrown = true;\r
539                         }\r
540                         Assert("#F03", errorThrown);\r
541                 }\r
542                 {\r
543                         bool errorThrown = false;\r
544                         try {\r
545                                 Array.CreateInstance(Type.GetType("System.Char"), null, null);\r
546                         } catch (ArgumentNullException) {\r
547                                 errorThrown = true;\r
548                         }\r
549                         Assert("#F04", errorThrown);\r
550                 }\r
551                 {\r
552                         bool errorThrown = false;\r
553                         try {\r
554                                 int[] lengths = new int [0];\r
555                                 Array.CreateInstance(Type.GetType("System.Char"), lengths);\r
556                         } catch (ArgumentException) {\r
557                                 errorThrown = true;\r
558                         }\r
559                         Assert("#F05", errorThrown);\r
560                 }\r
561                 {\r
562                         bool errorThrown = false;\r
563                         try {\r
564                                 int[] lengths = new int [1];\r
565                                 int[] bounds = new int [2];\r
566                                 // FIXME: Broken\r
567                                 // Array.CreateInstance(Type.GetType("System.Char"), lengths, bounds);\r
568                                 errorThrown = true;\r
569                         } catch (ArgumentException) {\r
570                                 errorThrown = true;\r
571                         }\r
572                         Assert("#F06", errorThrown);\r
573                 }\r
574 \r
575                 char[] c1 = (char[])Array.CreateInstance(Type.GetType("System.Char"), 12);\r
576                 AssertEquals("#F07", 12, c1.Length);\r
577 \r
578                 Array c2 = Array.CreateInstance(Type.GetType("System.Char"), 12, 5);\r
579                 AssertEquals("#F08", 2, c2.Rank);\r
580                 AssertEquals("#F09", 60, c2.Length);\r
581 \r
582 \r
583                 {\r
584                         int[] lengths = { 3 };\r
585                         int[] bounds = { 5 };\r
586                         int[] src = { 512, 718, 912 };\r
587                         Array array = Array.CreateInstance(typeof(int), lengths, bounds);\r
588 \r
589                         AssertEquals("#F10", 3, array.Length);\r
590                         AssertEquals("#F11", 5, array.GetLowerBound(0));\r
591                         AssertEquals("#F12", 7, array.GetUpperBound(0));\r
592 \r
593                         src.CopyTo (array, 5);\r
594 \r
595                         for (int i = 0; i < src.Length; i++)\r
596                                 AssertEquals("#F13(" + i + ")", src[i], array.GetValue(i+5));\r
597                 }\r
598 \r
599         }\r
600 \r
601         public void TestGetEnumerator() {\r
602                 String[] s1 = {"this", "is", "a", "test"};\r
603                 IEnumerator en = s1.GetEnumerator ();\r
604                 AssertNotNull ("#G01", en);\r
605 \r
606                 Assert ("#G02", en.MoveNext ());\r
607                 AssertEquals ("#G03", "this", en.Current);\r
608                 Assert ("#G04", en.MoveNext ());\r
609                 AssertEquals ("#G05", "is", en.Current);\r
610                 Assert ("#G06", en.MoveNext ());\r
611                 AssertEquals ("#G07", "a", en.Current);\r
612                 Assert ("#G08", en.MoveNext ());\r
613                 AssertEquals ("#G09", "test", en.Current);\r
614                 Assert ("#G10", !en.MoveNext ());\r
615 \r
616                 en.Reset ();\r
617                 Assert("#G11", en.MoveNext ());\r
618                 AssertEquals ("#G12", "this", en.Current);\r
619 \r
620                 // mutation does not invalidate array enumerator!\r
621                 s1.SetValue ("change", 1);\r
622                 Assert ("#G13", en.MoveNext ());\r
623                 AssertEquals ("#G14", "change", en.Current);\r
624         }\r
625 \r
626         public void TestGetEnumeratorMultipleDimension() {\r
627                 String[,] s1 = {{"this", "is"}, {"a", "test"}};\r
628                 IEnumerator en = s1.GetEnumerator ();\r
629                 AssertNotNull ("#AA01", en);\r
630 \r
631                 Assert ("#AA02", en.MoveNext ());\r
632                 AssertEquals ("#AA03", "this", en.Current);\r
633                 Assert ("#AA04", en.MoveNext ());\r
634                 AssertEquals ("#AA05", "is", en.Current);\r
635                 Assert ("#AA06", en.MoveNext ());\r
636                 AssertEquals ("#AA07", "a", en.Current);\r
637                 Assert ("#AA08", en.MoveNext ());\r
638                 AssertEquals ("#AA09", "test", en.Current);\r
639                 Assert ("#AA10", !en.MoveNext ());\r
640 \r
641                 en.Reset ();\r
642                 Assert("#AA11", en.MoveNext ());\r
643                 AssertEquals ("#AA12", "this", en.Current);\r
644 \r
645                 int[] idxs = {0,1};\r
646                 // mutation does not invalidate array enumerator!\r
647                 s1.SetValue ("change", idxs);\r
648                 Assert ("#AA13", en.MoveNext ());\r
649                 AssertEquals ("#AA14", "change", en.Current);\r
650         }\r
651 \r
652         public void TestGetEnumeratorNonZeroLowerBounds() {\r
653                 int[] myLengthsArray = new int[2] { 3, 5 };\r
654                 int[] myBoundsArray = new int[2] { 2, 3 };\r
655 \r
656                 Array myArray=Array.CreateInstance( typeof(String), myLengthsArray, myBoundsArray );\r
657                 for ( int i = myArray.GetLowerBound(0); i <= myArray.GetUpperBound(0); i++ )\r
658                         for ( int j = myArray.GetLowerBound(1); j <= myArray.GetUpperBound(1); j++ )  {\r
659                                 int[] myIndicesArray = new int[2] { i, j };\r
660                                 myArray.SetValue( Convert.ToString(i) + j, myIndicesArray );\r
661                         }\r
662                 IEnumerator en = myArray.GetEnumerator ();\r
663                 AssertNotNull ("#AB01", en);\r
664 \r
665                 // check the first couple of values\r
666                 Assert ("#AB02", en.MoveNext ());\r
667                 AssertEquals ("#AB03", "23", en.Current);\r
668                 Assert ("#AB04", en.MoveNext ());\r
669                 AssertEquals ("#AB05", "24", en.Current);\r
670 \r
671                 // then check the last element's value\r
672                 string lastElement;\r
673                 do {  \r
674                         lastElement = (string)en.Current;\r
675                 } while (en.MoveNext());\r
676                 AssertEquals ("#AB06", "47", lastElement);\r
677         }\r
678 \r
679         public void TestIList_Add () {\r
680                 int[] myLengthsArray = new int[2] { 3, 5 };\r
681                 int[] myBoundsArray = new int[2] { 2, 3 };\r
682 \r
683                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );\r
684                 try {\r
685                         ((IList)myArray).Add ("can not");\r
686                         Fail ("IList.Add should throw");    \r
687                 }\r
688                 catch (NotSupportedException) {\r
689                         return;\r
690                 }\r
691                 catch (Exception) {\r
692                         Fail ("IList.Add threw wrong exception type");    \r
693                 }\r
694 \r
695                 Fail("IList.Add shouldn't get this far");\r
696         }\r
697 \r
698         public void TestIList_Insert () {\r
699                 int[] myLengthsArray = new int[2] { 3, 5 };\r
700                 int[] myBoundsArray = new int[2] { 2, 3 };\r
701 \r
702                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );\r
703                 try {\r
704                         ((IList)myArray).Insert (0, "can not");\r
705                         Fail ("IList.Insert should throw");    \r
706                 }\r
707                 catch (NotSupportedException) {\r
708                         return;\r
709                 }\r
710                 catch (Exception) {\r
711                         Fail ("IList.Insert threw wrong exception type");    \r
712                 }\r
713 \r
714                 Fail("IList.Insert shouldn't get this far");\r
715         }\r
716 \r
717         public void TestIList_Remove () {\r
718                 int[] myLengthsArray = new int[2] { 3, 5 };\r
719                 int[] myBoundsArray = new int[2] { 2, 3 };\r
720 \r
721                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );\r
722                 try {\r
723                         ((IList)myArray).Remove ("can not");\r
724                         Fail ("IList.Remove should throw");    \r
725                 }\r
726                 catch (NotSupportedException) {\r
727                         return;\r
728                 }\r
729                 catch (Exception) {\r
730                         Fail ("IList.Remove threw wrong exception type");    \r
731                 }\r
732 \r
733                 Fail("IList.Remove shouldn't get this far");\r
734         }\r
735 \r
736         public void TestIList_RemoveAt () {\r
737                 int[] myLengthsArray = new int[2] { 3, 5 };\r
738                 int[] myBoundsArray = new int[2] { 2, 3 };\r
739 \r
740                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );\r
741                 try {\r
742                         ((IList)myArray).RemoveAt (0);\r
743                         Fail ("IList.RemoveAt should throw");    \r
744                 }\r
745                 catch (NotSupportedException) {\r
746                         return;\r
747                 }\r
748                 catch (Exception) {\r
749                         Fail ("IList.RemoveAt threw wrong exception type");    \r
750                 }\r
751 \r
752                 Fail("IList.RemoveAt shouldn't get this far");\r
753         }\r
754 \r
755         public void TestIList_Contains () {\r
756                 int[] myLengthsArray = new int[2] { 3, 5 };\r
757                 int[] myBoundsArray = new int[2] { 2, 3 };\r
758 \r
759                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );\r
760 \r
761                 try {\r
762                         bool b = ((IList)myArray).Contains ("23");\r
763                         Fail("IList.Contains should throw with multi-dimensional arrays");\r
764                 }\r
765                 catch (RankException) {\r
766                         int[] iArr = new int[3] { 1, 2, 3};\r
767                         // check the first and last items\r
768                         Assert("AC01", ((IList)iArr).Contains (1));\r
769                         Assert("AC02", ((IList)iArr).Contains (3));\r
770 \r
771                         // and one that is definately not there\r
772                         Assert("AC03", !((IList)iArr).Contains (42));\r
773                         return;\r
774                 }\r
775 \r
776                 Fail("Should not get here");\r
777         }\r
778 \r
779         public void TestIList_IndexOf () {\r
780                 int[] myLengthsArray = new int[2] { 3, 5 };\r
781                 int[] myBoundsArray = new int[2] { 2, 3 };\r
782 \r
783                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );\r
784 \r
785                 try {\r
786                         bool b = ((IList)myArray).Contains ("23");\r
787                         Fail("IList.Contains should throw with multi-dimensional arrays");\r
788                 }\r
789                 catch (RankException) {\r
790                         int[] iArr = new int[3] { 1, 2, 3};\r
791                         // check the first and last items\r
792                         AssertEquals("AD01", 0, ((IList)iArr).IndexOf (1));\r
793                         AssertEquals("AD02", 2, ((IList)iArr).IndexOf (3));\r
794 \r
795                         // and one that is definately not there\r
796                         AssertEquals("AD03", -1, ((IList)iArr).IndexOf (42));\r
797                 }\r
798                 catch (Exception) {\r
799                         Fail("Should not get here");\r
800                 }\r
801 \r
802                 // check that wierd case whem lowerbound is Int32.MinValue,\r
803                 // so that IndexOf() needs to return Int32.MaxValue when it cannot find the object\r
804                 int[] myLengthArray = new int[1] { 3 };\r
805                 int[] myBoundArray = new int[1] { Int32.MinValue };\r
806                 Array myExtremeArray=Array.CreateInstance ( typeof(String), myLengthArray, myBoundArray );\r
807                 AssertEquals("AD04", Int32.MaxValue, ((IList)myExtremeArray).IndexOf (42));\r
808 \r
809         }\r
810 \r
811         public void TestGetLength() {\r
812                 {\r
813                         bool errorThrown = false;\r
814                         try {\r
815                                 char[] c1 = {'a', 'b', 'c'};\r
816                                 c1.GetLength(-1);\r
817                         } catch (IndexOutOfRangeException) {\r
818                                 errorThrown = true;\r
819                         }\r
820                         Assert("#H01", errorThrown);\r
821                 }\r
822                 {\r
823                         bool errorThrown = false;\r
824                         try {\r
825                                 char[] c1 = {'a', 'b', 'c'};\r
826                                 c1.GetLength(1);\r
827                         } catch (IndexOutOfRangeException) {\r
828                                 errorThrown = true;\r
829                         }\r
830                         Assert("#H02", errorThrown);\r
831                 }\r
832 \r
833                 char[] c2 = new Char[5];\r
834                 AssertEquals("#H03", \r
835                              5, c2.GetLength(0));\r
836 \r
837                 char[,] c3 = new Char[6,7];\r
838                 AssertEquals("#H04", \r
839                              6, c3.GetLength(0));\r
840                 AssertEquals("#H05", \r
841                              7, c3.GetLength(1));\r
842         }\r
843 \r
844         public void TestGetLowerBound() {\r
845                 {\r
846                         bool errorThrown = false;\r
847                         try {\r
848                                 char[] c = {'a', 'b', 'c'};\r
849                                 c.GetLowerBound(-1);\r
850                         } catch (IndexOutOfRangeException) {\r
851                                 errorThrown = true;\r
852                         }\r
853                         Assert("#H31", errorThrown);\r
854                 }\r
855                 {\r
856                         bool errorThrown = false;\r
857                         try {\r
858                                 char[] c = {'a', 'b', 'c'};\r
859                                 c.GetLowerBound(1);\r
860                         } catch (IndexOutOfRangeException) {\r
861                                 errorThrown = true;\r
862                         }\r
863                         Assert("#H32", errorThrown);\r
864                 }\r
865 \r
866                 char[] c1 = new Char[5];\r
867                 AssertEquals("#H33", \r
868                              0, c1.GetLowerBound(0));\r
869 \r
870                 char[,] c2 = new Char[4,4];\r
871                 AssertEquals("#H34", \r
872                              0, c2.GetLowerBound(0));\r
873                 AssertEquals("#H35", \r
874                              0, c2.GetLowerBound(1));\r
875         }\r
876 \r
877         public void TestGetUpperBound() {\r
878                 {\r
879                         bool errorThrown = false;\r
880                         try {\r
881                                 char[] c = {'a', 'b', 'c'};\r
882                                 c.GetUpperBound(-1);\r
883                         } catch (IndexOutOfRangeException) {\r
884                                 errorThrown = true;\r
885                         }\r
886                         Assert("#H61", errorThrown);\r
887                 }\r
888                 {\r
889                         bool errorThrown = false;\r
890                         try {\r
891                                 char[] c = {'a', 'b', 'c'};\r
892                                 c.GetUpperBound(1);\r
893                         } catch (IndexOutOfRangeException) {\r
894                                 errorThrown = true;\r
895                         }\r
896                         Assert("#H62", errorThrown);\r
897                 }\r
898 \r
899                 char[] c1 = new Char[5];\r
900                 AssertEquals("#H63", \r
901                              4, c1.GetUpperBound(0));\r
902 \r
903                 char[,] c2 = new Char[4,6];\r
904                 AssertEquals("#H64", \r
905                              3, c2.GetUpperBound(0));\r
906                 AssertEquals("#H65", \r
907                              5, c2.GetUpperBound(1));\r
908         }\r
909 \r
910         public void TestGetValue1() {\r
911                 {\r
912                         bool errorThrown = false;\r
913                         try {\r
914                                 char[,] c = new Char[2,2];\r
915                                 c.GetValue(1);\r
916                         } catch (ArgumentException) {\r
917                                 errorThrown = true;\r
918                         }\r
919                         Assert("#I01", errorThrown);\r
920                 }\r
921                 {\r
922                         bool errorThrown = false;\r
923                         try {\r
924                                 char[] c = {'a', 'b', 'c'};\r
925                                 c.GetValue(-1);\r
926                         } catch (IndexOutOfRangeException) {\r
927                                 errorThrown = true;\r
928                         }\r
929                         Assert("#I02", errorThrown);\r
930                 }\r
931                 {\r
932                         bool errorThrown = false;\r
933                         try {\r
934                                 char[] c = {'a', 'b', 'c'};\r
935                                 c.GetValue(4);\r
936                         } catch (IndexOutOfRangeException) {\r
937                                 errorThrown = true;\r
938                         }\r
939                         Assert("#I03", errorThrown);\r
940                 }\r
941 \r
942                 char[] c1 = {'a', 'b', 'c', 'd'};\r
943                 for (int i = 0; i < c1.Length; i++) {\r
944                         AssertEquals("#I04(" + i + ")", c1[i], c1.GetValue(i));\r
945                 }\r
946         }\r
947         public void TestGetValue2() {\r
948                 {\r
949                         bool errorThrown = false;\r
950                         try {\r
951                                 char[] c = new Char[2];\r
952                                 c.GetValue(1,1);\r
953                         } catch (ArgumentException) {\r
954                                 errorThrown = true;\r
955                         }\r
956                         Assert("#I21", errorThrown);\r
957                 }\r
958                 {\r
959                         bool errorThrown = false;\r
960                         try {\r
961                                 char[,] c = new Char[2,2];\r
962                                 c.GetValue(-1, 1);\r
963                         } catch (IndexOutOfRangeException) {\r
964                                 errorThrown = true;\r
965                         }\r
966                         Assert("#I22", errorThrown);\r
967                 }\r
968                 {\r
969                         bool errorThrown = false;\r
970                         try {\r
971                                 char[,] c = new Char[2,2];\r
972                                 c.GetValue(4,1);\r
973                         } catch (IndexOutOfRangeException) {\r
974                                 errorThrown = true;\r
975                         }\r
976                         Assert("#I23", errorThrown);\r
977                 }\r
978 \r
979                 char[,] c1 = new Char[4,6];\r
980                 for (int i = 0; i < 24; i++) {\r
981                         int first = i / 6;\r
982                         int second = i % 6;\r
983                         c1[first,second] = (char)(((int)'a')+i);\r
984                 }\r
985                 for (int i = 0; i < c1.GetLength(0); i++) {\r
986                         for (int j = 0; j < c1.GetLength(1); j++) {\r
987                                 AssertEquals("#I24(" + i + "," + j + ")",\r
988                                              c1[i,j], c1.GetValue(i, j));\r
989                         }\r
990                 }\r
991         }\r
992         public void TestGetValue3() {\r
993                 {\r
994                         bool errorThrown = false;\r
995                         try {\r
996                                 char[] c = new Char[2];\r
997                                 c.GetValue(1,1,1);\r
998                         } catch (ArgumentException) {\r
999                                 errorThrown = true;\r
1000                         }\r
1001                         Assert("#I41", errorThrown);\r
1002                 }\r
1003                 {\r
1004                         bool errorThrown = false;\r
1005                         try {\r
1006                                 char[,,] c = new Char[2,2,2];\r
1007                                 c.GetValue(-1, 1, 1);\r
1008                         } catch (IndexOutOfRangeException) {\r
1009                                 errorThrown = true;\r
1010                         }\r
1011                         Assert("#I42", errorThrown);\r
1012                 }\r
1013                 {\r
1014                         bool errorThrown = false;\r
1015                         try {\r
1016                                 char[,,] c = new Char[2,2,2];\r
1017                                 c.GetValue(4,1,1);\r
1018                         } catch (IndexOutOfRangeException) {\r
1019                                 errorThrown = true;\r
1020                         }\r
1021                         Assert("#I43", errorThrown);\r
1022                 }\r
1023 \r
1024                 char[,,] c1 = new Char[4,2,3];\r
1025                 for (int i = 0; i < 24; i++) {\r
1026                         int first = i / 6;\r
1027                         int remains = i % 6;\r
1028                         int second = remains / 3;\r
1029                         int third = remains % 3;\r
1030                         c1[first,second, third] = (char)(((int)'a')+i);\r
1031                 }\r
1032                 for (int i = 0; i < c1.GetLength(0); i++) {\r
1033                         for (int j = 0; j < c1.GetLength(1); j++) {\r
1034                                 for (int k = 0; k < c1.GetLength(2); k++) {\r
1035                                         AssertEquals("#I44(" + i + "," + j + ")",\r
1036                                                      c1[i,j,k], c1.GetValue(i,j,k));\r
1037                                 }\r
1038                         }\r
1039                 }\r
1040         }\r
1041         public void TestGetValueN() {\r
1042                 {\r
1043                         bool errorThrown = false;\r
1044                         try {\r
1045                                 char[] c = new Char[2];\r
1046                                 c.GetValue(null);\r
1047                         } catch (ArgumentNullException) {\r
1048                                 errorThrown = true;\r
1049                         }\r
1050                         Assert("#I61", errorThrown);\r
1051                 }\r
1052                 {\r
1053                         bool errorThrown = false;\r
1054                         try {\r
1055                                 char[] c = new Char[2];\r
1056                                 int[] coords = {1, 1};\r
1057                                 c.GetValue(coords);\r
1058                         } catch (ArgumentException) {\r
1059                                 errorThrown = true;\r
1060                         }\r
1061                         Assert("#I62", errorThrown);\r
1062                 }\r
1063                 {\r
1064                         bool errorThrown = false;\r
1065                         try {\r
1066                                 char[,] c = new Char[2,2];\r
1067                                 int[] coords = {-1, 1};\r
1068                                 c.GetValue(coords);\r
1069                         } catch (IndexOutOfRangeException) {\r
1070                                 errorThrown = true;\r
1071                         }\r
1072                         Assert("#I63", errorThrown);\r
1073                 }\r
1074                 {\r
1075                         bool errorThrown = false;\r
1076                         try {\r
1077                                 char[,] c = new Char[2,2];\r
1078                                 int[] coords = {4, 1};\r
1079                                 c.GetValue(coords);\r
1080                         } catch (IndexOutOfRangeException) {\r
1081                                 errorThrown = true;\r
1082                         }\r
1083                         Assert("#I64", errorThrown);\r
1084                 }\r
1085 \r
1086                 char[,] c1 = new Char[4,6];\r
1087                 for (int i = 0; i < 24; i++) {\r
1088                         int first = i / 6;\r
1089                         int second = i % 6;\r
1090                         c1[first,second] = (char)(((int)'a')+i);\r
1091                 }\r
1092                 for (int i = 0; i < c1.GetLength(0); i++) {\r
1093                         for (int j = 0; j < c1.GetLength(1); j++) {\r
1094                                 int[] coords = {i, j};\r
1095                                 AssertEquals("#I65(" + i + "," + j + ")",\r
1096                                              c1[i,j], c1.GetValue(coords));\r
1097                         }\r
1098                 }\r
1099         }\r
1100 \r
1101         public void TestIndexOf1() {\r
1102                 {\r
1103                         bool errorThrown = false;\r
1104                         try {\r
1105                                 Array.IndexOf(null, "huh?");\r
1106                         } catch (ArgumentNullException) {\r
1107                                 errorThrown = true;\r
1108                         }\r
1109                         Assert("#J01", errorThrown);\r
1110                 }\r
1111                 {\r
1112                         bool errorThrown = false;\r
1113                         try {\r
1114                                 char[,] c = new Char[2,2];\r
1115                                 Array.IndexOf(c, "huh?");\r
1116                         } catch (RankException) {\r
1117                                 errorThrown = true;\r
1118                         }\r
1119                         Assert("#J02", errorThrown);\r
1120                 }\r
1121 \r
1122                 String[] s1 = {"this", "is", "a", "test"};\r
1123                 AssertEquals("#J03", -1, Array.IndexOf(s1, null));\r
1124                 AssertEquals("#J04", -1, Array.IndexOf(s1, "nothing"));\r
1125                 AssertEquals("#J05", 0, Array.IndexOf(s1, "this"));\r
1126                 AssertEquals("#J06", 3, Array.IndexOf(s1, "test"));\r
1127         }\r
1128         public void TestIndexOf2() {\r
1129                 {\r
1130                         bool errorThrown = false;\r
1131                         try {\r
1132                                 Array.IndexOf(null, "huh?", 0);\r
1133                         } catch (ArgumentNullException) {\r
1134                                 errorThrown = true;\r
1135                         }\r
1136                         Assert("#J21", errorThrown);\r
1137                 }\r
1138                 {\r
1139                         bool errorThrown = false;\r
1140                         try {\r
1141                                 char[,] c = new Char[2,2];\r
1142                                 Array.IndexOf(c, "huh?", 0);\r
1143                         } catch (RankException) {\r
1144                                 errorThrown = true;\r
1145                         }\r
1146                         Assert("#J22", errorThrown);\r
1147                 }\r
1148                 {\r
1149                         bool errorThrown = false;\r
1150                         try {\r
1151                                 char[] c = new Char[2];\r
1152                                 Array.IndexOf(c, "huh?", 3);\r
1153                         } catch (ArgumentOutOfRangeException) {\r
1154                                 errorThrown = true;\r
1155                         }\r
1156                         Assert("#J23", errorThrown);\r
1157                 }\r
1158 \r
1159                 String[] s1 = {"this", "is", "really", "a", "test"};\r
1160                 AssertEquals("#J24", -1, Array.IndexOf(s1, null, 1));\r
1161                 AssertEquals("#J25", -1, Array.IndexOf(s1, "nothing", 1));\r
1162                 AssertEquals("#J26", -1, Array.IndexOf(s1, "this", 1));\r
1163                 AssertEquals("#J27", 1, Array.IndexOf(s1, "is", 1));\r
1164                 AssertEquals("#J28", 4, Array.IndexOf(s1, "test", 1));\r
1165         }\r
1166         public void TestIndexOf3() {\r
1167                 {\r
1168                         bool errorThrown = false;\r
1169                         try {\r
1170                                 Array.IndexOf(null, "huh?", 0, 1);\r
1171                         } catch (ArgumentNullException) {\r
1172                                 errorThrown = true;\r
1173                         }\r
1174                         Assert("#J41", errorThrown);\r
1175                 }\r
1176                 {\r
1177                         bool errorThrown = false;\r
1178                         try {\r
1179                                 char[,] c = new Char[2,2];\r
1180                                 Array.IndexOf(c, "huh?", 0, 1);\r
1181                         } catch (RankException) {\r
1182                                 errorThrown = true;\r
1183                         }\r
1184                         Assert("#J42", errorThrown);\r
1185                 }\r
1186                 {\r
1187                         bool errorThrown = false;\r
1188                         try {\r
1189                                 char[] c = new Char[2];\r
1190                                 Array.IndexOf(c, "huh?", 3, 1);\r
1191                         } catch (ArgumentOutOfRangeException) {\r
1192                                 errorThrown = true;\r
1193                         }\r
1194                         Assert("#J43", errorThrown);\r
1195                 }\r
1196                 {\r
1197                         bool errorThrown = false;\r
1198                         try {\r
1199                                 char[] c = new Char[2];\r
1200                                 Array.IndexOf(c, "huh?", 0, 5);\r
1201                         } catch (ArgumentOutOfRangeException) {\r
1202                                 errorThrown = true;\r
1203                         }\r
1204                         Assert("#J44", errorThrown);\r
1205                 }\r
1206 \r
1207                 String[] s1 = {"this", "is", "really", "a", "test"};\r
1208                 AssertEquals("#J45", -1, Array.IndexOf(s1, null, 1, 3));\r
1209                 AssertEquals("#J46", -1, Array.IndexOf(s1, "nothing", 1, 3));\r
1210                 AssertEquals("#J47", -1, Array.IndexOf(s1, "this", 1, 3));\r
1211                 AssertEquals("#J48", 1, Array.IndexOf(s1, "is", 1, 3));\r
1212                 AssertEquals("#J49", -1, Array.IndexOf(s1, "test", 1, 3));\r
1213                 AssertEquals("#J50", 3, Array.IndexOf(s1, "a", 1, 3));\r
1214         }\r
1215         \r
1216         public void TestLastIndexOf1() {\r
1217                 {\r
1218                         bool errorThrown = false;\r
1219                         try {\r
1220                                 Array.LastIndexOf(null, "huh?");\r
1221                         } catch (ArgumentNullException) {\r
1222                                 errorThrown = true;\r
1223                         }\r
1224                         Assert("#K01", errorThrown);\r
1225                 }\r
1226                 {\r
1227                         bool errorThrown = false;\r
1228                         try {\r
1229                                 char[,] c = new Char[2,2];\r
1230                                 Array.LastIndexOf(c, "huh?");\r
1231                         } catch (RankException) {\r
1232                                 errorThrown = true;\r
1233                         }\r
1234                         Assert("#K02", errorThrown);\r
1235                 }\r
1236 \r
1237                 String[] s1 = {"this", "is", "a", "a", "test"};\r
1238                 AssertEquals("#K03", -1, Array.LastIndexOf(s1, null));\r
1239                 AssertEquals("#K04", -1, Array.LastIndexOf(s1, "nothing"));\r
1240                 AssertEquals("#K05", 0, Array.LastIndexOf(s1, "this"));\r
1241                 AssertEquals("#K06", 4, Array.LastIndexOf(s1, "test"));\r
1242                 AssertEquals("#K07", 3, Array.LastIndexOf(s1, "a"));\r
1243         }\r
1244         public void TestLastIndexOf2() {\r
1245                 {\r
1246                         bool errorThrown = false;\r
1247                         try {\r
1248                                 Array.LastIndexOf(null, "huh?", 0);\r
1249                         } catch (ArgumentNullException) {\r
1250                                 errorThrown = true;\r
1251                         }\r
1252                         Assert("#K21", errorThrown);\r
1253                 }\r
1254                 {\r
1255                         bool errorThrown = false;\r
1256                         try {\r
1257                                 char[,] c = new Char[2,2];\r
1258                                 Array.LastIndexOf(c, "huh?", 0);\r
1259                         } catch (RankException) {\r
1260                                 errorThrown = true;\r
1261                         }\r
1262                         Assert("#K22", errorThrown);\r
1263                 }\r
1264                 {\r
1265                         bool errorThrown = false;\r
1266                         try {\r
1267                                 char[] c = new Char[2];\r
1268                                 Array.LastIndexOf(c, "huh?", 3);\r
1269                         } catch (ArgumentOutOfRangeException) {\r
1270                                 errorThrown = true;\r
1271                         }\r
1272                         Assert("#K23", errorThrown);\r
1273                 }\r
1274 \r
1275                 String[] s1 = {"this", "is", "really", "a", "test"};\r
1276                 AssertEquals("#K24", -1, Array.LastIndexOf(s1, null, 3));\r
1277                 AssertEquals("#K25", -1, Array.LastIndexOf(s1, "nothing", 3));\r
1278                 AssertEquals("#K26", -1, Array.LastIndexOf(s1, "test", 3));\r
1279                 AssertEquals("#K27", 3, Array.LastIndexOf(s1, "a", 3));\r
1280                 AssertEquals("#K28", 0, Array.LastIndexOf(s1, "this", 3));\r
1281         }\r
1282         public void TestLastIndexOf3() {\r
1283                 {\r
1284                         bool errorThrown = false;\r
1285                         try {\r
1286                                 Array.LastIndexOf(null, "huh?", 0, 1);\r
1287                         } catch (ArgumentNullException) {\r
1288                                 errorThrown = true;\r
1289                         }\r
1290                         Assert("#K41", errorThrown);\r
1291                 }\r
1292                 {\r
1293                         bool errorThrown = false;\r
1294                         try {\r
1295                                 char[,] c = new Char[2,2];\r
1296                                 Array.LastIndexOf(c, "huh?", 0, 1);\r
1297                         } catch (RankException) {\r
1298                                 errorThrown = true;\r
1299                         }\r
1300                         Assert("#K42", errorThrown);\r
1301                 }\r
1302                 {\r
1303                         bool errorThrown = false;\r
1304                         try {\r
1305                                 char[] c = new Char[2];\r
1306                                 Array.LastIndexOf(c, "huh?", 3, 1);\r
1307                         } catch (ArgumentOutOfRangeException) {\r
1308                                 errorThrown = true;\r
1309                         }\r
1310                         Assert("#K43", errorThrown);\r
1311                 }\r
1312                 {\r
1313                         bool errorThrown = false;\r
1314                         try {\r
1315                                 char[] c = new Char[2];\r
1316                                 Array.LastIndexOf(c, "huh?", 0, 5);\r
1317                         } catch (ArgumentOutOfRangeException) {\r
1318                                 errorThrown = true;\r
1319                         }\r
1320                         Assert("#K44", errorThrown);\r
1321                 }\r
1322 \r
1323                 String[] s1 = {"this", "is", "really", "a", "test"};\r
1324                 AssertEquals("#K45", \r
1325                              -1, Array.LastIndexOf(s1, null, 3, 3));\r
1326                 AssertEquals("#K46", \r
1327                              -1, Array.LastIndexOf(s1, "nothing", 3, 3));\r
1328                 AssertEquals("#K47", \r
1329                              -1, Array.LastIndexOf(s1, "this", 3, 3));\r
1330                 AssertEquals("#K48",\r
1331                              1, Array.LastIndexOf(s1, "is", 3, 3));\r
1332                 AssertEquals("#K49", \r
1333                              -1, Array.LastIndexOf(s1, "test", 3, 3));\r
1334                 AssertEquals("#K50", \r
1335                              3, Array.LastIndexOf(s1, "a", 3, 3));\r
1336         }\r
1337 \r
1338         public void TestReverse() {\r
1339                 {\r
1340                         bool errorThrown = false;\r
1341                         try {\r
1342                                 Array.Reverse(null);\r
1343                         } catch (ArgumentNullException) {\r
1344                                 errorThrown = true;\r
1345                         }\r
1346                         Assert("#L01", errorThrown);\r
1347                 }\r
1348                 {\r
1349                         bool errorThrown = false;\r
1350                         try {\r
1351                                 char[,] c = new Char[2,2];\r
1352                                 Array.Reverse(c);\r
1353                         } catch (RankException) {\r
1354                                 errorThrown = true;\r
1355                         }\r
1356                         Assert("#L02", errorThrown);\r
1357                 }\r
1358                 \r
1359                 char[] c1 = {'a', 'b', 'c', 'd'};\r
1360                 Array.Reverse(c1);\r
1361                 AssertEquals("#L03", 'd', c1[0]);\r
1362                 AssertEquals("#L04", 'c', c1[1]);\r
1363                 AssertEquals("#L05", 'b', c1[2]);\r
1364                 AssertEquals("#L06", 'a', c1[3]);\r
1365 \r
1366                 {\r
1367                         bool errorThrown = false;\r
1368                         try {\r
1369                                 Array.Reverse(null, 0, 0);\r
1370                         } catch (ArgumentNullException) {\r
1371                                 errorThrown = true;\r
1372                         }\r
1373                         Assert("#L07", errorThrown);\r
1374                 }\r
1375                 {\r
1376                         bool errorThrown = false;\r
1377                         try {\r
1378                                 char[,] c = new Char[2,2];\r
1379                                 Array.Reverse(c, 0, 0);\r
1380                         } catch (RankException) {\r
1381                                 errorThrown = true;\r
1382                         }\r
1383                         Assert("#L08", errorThrown);\r
1384                 }\r
1385                 //{\r
1386                 //bool errorThrown = false;\r
1387                 //try {\r
1388                 //      char[] c = new Char[2];\r
1389                 //      Array.Reverse(c, 0, 3);\r
1390                 //} catch (ArgumentOutOfRangeException) {\r
1391                 //      errorThrown = true;\r
1392                 //}\r
1393                 //Assert("#L09", errorThrown);\r
1394                 //}\r
1395                 //{\r
1396                 //bool errorThrown = false;\r
1397                 //try {\r
1398                 //      char[] c = new Char[2];\r
1399                 //      Array.Reverse(c, 3, 0);\r
1400                 //} catch (ArgumentOutOfRangeException) {\r
1401                 //      errorThrown = true;\r
1402                 //}\r
1403                 //Assert("#L10", errorThrown);\r
1404                 //}\r
1405 \r
1406                 char[] c2 = { 'a', 'b', 'c', 'd'};\r
1407                 Array.Reverse(c2, 1, 2);\r
1408                 AssertEquals("#L11", 'a', c2[0]);\r
1409                 AssertEquals("#L12", 'c', c2[1]);\r
1410                 AssertEquals("#L13", 'b', c2[2]);\r
1411                 AssertEquals("#L14", 'd', c2[3]);\r
1412         }\r
1413 \r
1414         public void TestSetValue1() {\r
1415                 {\r
1416                         bool errorThrown = false;\r
1417                         try {\r
1418                                 char[,] c = new Char[2,2];\r
1419                                 c.SetValue("buh", 1);\r
1420                         } catch (ArgumentException) {\r
1421                                 errorThrown = true;\r
1422                         }\r
1423                         Assert("#M01", errorThrown);\r
1424                 }\r
1425                 {\r
1426                         bool errorThrown = false;\r
1427                         try {\r
1428                                 char[] c = {'a', 'b', 'c'};\r
1429                                 c.SetValue("buh", -1);\r
1430                         } catch (IndexOutOfRangeException) {\r
1431                                 errorThrown = true;\r
1432                         }\r
1433                         Assert("#M02", errorThrown);\r
1434                 }\r
1435                 {\r
1436                         bool errorThrown = false;\r
1437                         try {\r
1438                                 char[] c = {'a', 'b', 'c'};\r
1439                                 c.SetValue("buh", 4);\r
1440                         } catch (IndexOutOfRangeException) {\r
1441                                 errorThrown = true;\r
1442                         }\r
1443                         Assert("#M03", errorThrown);\r
1444                 }\r
1445 \r
1446                 char[] c1 = {'a', 'b', 'c', 'd'};\r
1447                 char[] c2 = new char[4];\r
1448                 for (int i = 0; i < c1.Length; i++) {\r
1449                         c2.SetValue(c1[i], i);\r
1450                 }\r
1451                 for (int i = 0; i < c1.Length; i++) {\r
1452                         AssertEquals("#M04(" + i + ")", c1[i], c2[i]);\r
1453                 }\r
1454 \r
1455                 int[] c3 = { 1, 2, 3 };\r
1456                 long[] c4 = new long [3];\r
1457 \r
1458                 for (int i = 0; i < c3.Length; i++)\r
1459                         c4.SetValue (c3 [i], i);\r
1460                 c3.CopyTo (c4, 0);\r
1461                 for (int i = 0; i < c3.Length; i++)\r
1462                         Assert ("#M05(" + i + ")", c3[i] == c4[i]);\r
1463 \r
1464                 Object[] c5 = new Object [3];\r
1465                 long[] c6 = new long [3];\r
1466 \r
1467                 c4.CopyTo (c5, 0);\r
1468 \r
1469                 c5.CopyTo (c6, 0);\r
1470                 // for (int i = 0; i < c5.Length; i++)\r
1471                 // Assert ("#M06(" + i + ")", c5[i] == c6[i]);\r
1472         }\r
1473 \r
1474         public void TestSetValue2() {\r
1475                 {\r
1476                         bool errorThrown = false;\r
1477                         try {\r
1478                                 char[] c = new Char[2];\r
1479                                 c.SetValue("buh", 1,1);\r
1480                         } catch (ArgumentException) {\r
1481                                 errorThrown = true;\r
1482                         }\r
1483                         Assert("#M21", errorThrown);\r
1484                 }\r
1485                 {\r
1486                         bool errorThrown = false;\r
1487                         try {\r
1488                                 char[,] c = new Char[2,2];\r
1489                                 c.SetValue("buh", -1, 1);\r
1490                         } catch (IndexOutOfRangeException) {\r
1491                                 errorThrown = true;\r
1492                         }\r
1493                         Assert("#M22", errorThrown);\r
1494                 }\r
1495                 {\r
1496                         bool errorThrown = false;\r
1497                         try {\r
1498                                 char[,] c = new Char[2,2];\r
1499                                 c.SetValue("buh", 4,1);\r
1500                         } catch (IndexOutOfRangeException) {\r
1501                                 errorThrown = true;\r
1502                         }\r
1503                         Assert("#M23", errorThrown);\r
1504                 }\r
1505 \r
1506                 char[,] c1 = new Char[4,6];\r
1507                 char[,] c2 = new Char[4,6];\r
1508                 for (int i = 0; i < 24; i++) {\r
1509                         int first = i / 6;\r
1510                         int second = i % 6;\r
1511                         c1[first,second] = (char)(((int)'a')+i);\r
1512                         c2.SetValue(c1[first,second], first, second);\r
1513                 }\r
1514                 for (int i = 0; i < c1.GetLength(0); i++) {\r
1515                         for (int j = 0; j < c1.GetLength(1); j++) {\r
1516                                 AssertEquals("#M24(" + i + "," + j + ")",\r
1517                                              c1[i,j], c2[i, j]);\r
1518                         }\r
1519                 }\r
1520         }\r
1521         public void TestSetValue3() {\r
1522                 {\r
1523                         bool errorThrown = false;\r
1524                         try {\r
1525                                 char[] c = new Char[2];\r
1526                                 c.SetValue("buh", 1,1,1);\r
1527                         } catch (ArgumentException) {\r
1528                                 errorThrown = true;\r
1529                         }\r
1530                         Assert("#M41", errorThrown);\r
1531                 }\r
1532                 {\r
1533                         bool errorThrown = false;\r
1534                         try {\r
1535                                 char[,,] c = new Char[2,2,2];\r
1536                                 c.SetValue("buh", -1, 1, 1);\r
1537                         } catch (IndexOutOfRangeException) {\r
1538                                 errorThrown = true;\r
1539                         }\r
1540                         Assert("#M42", errorThrown);\r
1541                 }\r
1542                 {\r
1543                         bool errorThrown = false;\r
1544                         try {\r
1545                                 char[,,] c = new Char[2,2,2];\r
1546                                 c.SetValue("buh", 4,1,1);\r
1547                         } catch (IndexOutOfRangeException) {\r
1548                                 errorThrown = true;\r
1549                         }\r
1550                         Assert("#M43", errorThrown);\r
1551                 }\r
1552 \r
1553                 char[,,] c1 = new Char[4,2,3];\r
1554                 char[,,] c2 = new Char[4,2,3];\r
1555                 for (int i = 0; i < 24; i++) {\r
1556                         int first = i / 6;\r
1557                         int remains = i % 6;\r
1558                         int second = remains / 3;\r
1559                         int third = remains % 3;\r
1560                         c1[first,second, third] = (char)(((int)'a')+i);\r
1561                         c2.SetValue(c1[first, second, third], first, second, third);\r
1562                 }\r
1563                 for (int i = 0; i < c1.GetLength(0); i++) {\r
1564                         for (int j = 0; j < c1.GetLength(1); j++) {\r
1565                                 for (int k = 0; k < c1.GetLength(2); k++) {\r
1566                                         AssertEquals("#M44(" + i + "," + j + " )",\r
1567                                                      c1[i,j,k], c2[i,j,k]);\r
1568                                 }\r
1569                         }\r
1570                 }\r
1571         }\r
1572         public void TestSetValueN() {\r
1573                 {\r
1574                         bool errorThrown = false;\r
1575                         try {\r
1576                                 char[] c = new Char[2];\r
1577                                 c.SetValue("buh", null);\r
1578                         } catch (ArgumentNullException) {\r
1579                                 errorThrown = true;\r
1580                         }\r
1581                         Assert("#M61", errorThrown);\r
1582                 }\r
1583                 {\r
1584                         bool errorThrown = false;\r
1585                         try {\r
1586                                 char[] c = new Char[2];\r
1587                                 int[] coords = {1, 1};\r
1588                                 c.SetValue("buh", coords);\r
1589                         } catch (ArgumentException) {\r
1590                                 errorThrown = true;\r
1591                         }\r
1592                         Assert("#M62", errorThrown);\r
1593                 }\r
1594                 {\r
1595                         bool errorThrown = false;\r
1596                         try {\r
1597                                 char[,] c = new Char[2,2];\r
1598                                 int[] coords = {-1, 1};\r
1599                                 c.SetValue("buh", coords);\r
1600                         } catch (IndexOutOfRangeException) {\r
1601                                 errorThrown = true;\r
1602                         }\r
1603                         Assert("#M63", errorThrown);\r
1604                 }\r
1605                 {\r
1606                         bool errorThrown = false;\r
1607                         try {\r
1608                                 char[,] c = new Char[2,2];\r
1609                                 int[] coords = {4, 1};\r
1610                                 c.SetValue("buh", coords);\r
1611                         } catch (IndexOutOfRangeException) {\r
1612                                 errorThrown = true;\r
1613                         }\r
1614                         Assert("#M64", errorThrown);\r
1615                 }\r
1616 \r
1617                 char[,] c1 = new Char[4,6];\r
1618                 char[,] c2 = new Char[4,6];\r
1619                 for (int i = 0; i < 24; i++) {\r
1620                         int first = i / 6;\r
1621                         int second = i % 6;\r
1622                         c1[first,second] = (char)(((int)'a')+i);\r
1623                         int[] coords = {first, second};\r
1624                         c2.SetValue(c1[first,second], coords);\r
1625                 }\r
1626                 for (int i = 0; i < c1.GetLength(0); i++) {\r
1627                         for (int j = 0; j < c1.GetLength(1); j++) {\r
1628                                 AssertEquals("#M65(" + i + "," + j + ")",\r
1629                                              c1[i,j], c2[i,j]);\r
1630                         }\r
1631                 }\r
1632         }\r
1633 \r
1634         public void TestSetValue4() {\r
1635                 {\r
1636                         int[] c1 = { 1, 2, 3 };\r
1637                         long[] c2 = new long [3];\r
1638 \r
1639                         for (int i = 0; i < c1.Length; i++)\r
1640                                 c2.SetValue (c1 [i], i);\r
1641 \r
1642                         for (int i = 0; i < c1.Length; i++) {\r
1643                                 Assert ("#M81(" + i + ")", c1[i] == c2[i]);\r
1644                                 AssertEquals ("#M82(" + i + ")", typeof (long), c2[i].GetType ());\r
1645                         }\r
1646                 }\r
1647                 {\r
1648                         long[] c1 = { 1, 2, 3 };\r
1649                         int[] c2 = new int [3];\r
1650                         bool errorThrown = false;\r
1651                         try {\r
1652                                 c2.SetValue (c1 [0], 0);\r
1653                         } catch (ArgumentException) {\r
1654                                 errorThrown = true;\r
1655                         }\r
1656                         Assert("#M83", errorThrown);\r
1657                 }\r
1658                 {\r
1659                         int[] c1 = { 1, 2, 3 };\r
1660                         Object[] c2 = new Object [3];\r
1661 \r
1662                         for (int i = 0; i < c1.Length; i++)\r
1663                                 c2.SetValue (c1 [i], i);\r
1664 \r
1665                         for (int i = 0; i < c1.Length; i++)\r
1666                                 AssertEquals ("#M84(" + i + ")", c1[i], Convert.ToInt32 (c2[i]));\r
1667                 }\r
1668                 {\r
1669                         Object[] c1 = new Object [3];\r
1670                         Object[] c2 = new Object [3];\r
1671                         c1[0] = new Object ();\r
1672 \r
1673                         for (int i = 0; i < c1.Length; i++)\r
1674                                 c2.SetValue (c1 [i], i);\r
1675 \r
1676                         for (int i = 0; i < c1.Length; i++)\r
1677                                 AssertEquals ("#M85(" + i + ")", c1[i], c2[i]);\r
1678                 }\r
1679                 {\r
1680                         Object[] c1 = new Object [3];\r
1681                         string[] c2 = new String [3];\r
1682                         string test = "hello";\r
1683                         c1[0] = test;\r
1684 \r
1685                         c2.SetValue (c1 [0], 0);\r
1686                         AssertEquals ("#M86", c1[0], c2[0]);\r
1687                         AssertEquals ("#M87", "hello", c2[0]);\r
1688                 }\r
1689                 {\r
1690                         char[] c1 = { 'a', 'b', 'c' };\r
1691                         string[] c2 = new string [3];\r
1692                         bool errorThrown = false;\r
1693                         try {\r
1694                                 c2.SetValue (c1 [0], 0);\r
1695                                 // FIXME\r
1696                                 errorThrown = true;\r
1697                         } catch (InvalidCastException) {\r
1698                                 errorThrown = true;\r
1699                         }\r
1700                         Assert("#M88", errorThrown);\r
1701                 }\r
1702                 {\r
1703                         Single[] c1 = { 1.2F, 2.3F, 3.4F, 4.5F };\r
1704                         long[] c2 = new long [3];\r
1705                         bool errorThrown = false;\r
1706                         try {\r
1707                                 c2.SetValue (c1 [0], 0);\r
1708                                 // FIXME\r
1709                                 errorThrown = true;\r
1710                         } catch (ArgumentException) {\r
1711                                 errorThrown = true;\r
1712                         }\r
1713                         Assert("#M89", errorThrown);\r
1714                 }\r
1715                 {\r
1716                         Type[] types = {\r
1717                                 typeof (Boolean),\r
1718                                 typeof (Byte),\r
1719                                 typeof (Char),\r
1720                                 typeof (Double),\r
1721                                 typeof (Int16),\r
1722                                 typeof (Int32),\r
1723                                 typeof (Int64),\r
1724                                 typeof (SByte),\r
1725                                 typeof (Single),\r
1726                                 typeof (UInt16),\r
1727                                 typeof (UInt32),\r
1728                                 typeof (UInt64)\r
1729                         };\r
1730 \r
1731                         bool v1 = true;\r
1732                         Byte v2 = 1;\r
1733                         Char v3 = 'a';\r
1734                         Double v4 = -1.2;\r
1735                         Int16 v5 = -32;\r
1736                         Int32 v6 = -234;\r
1737                         Int64 v7 = -34523;\r
1738                         SByte v8 = -1;\r
1739                         Single v9 = -4.8F;\r
1740                         UInt16 v10 = 24234;\r
1741                         UInt32 v11 = 235354;\r
1742                         UInt64 v12 = 234552;\r
1743 \r
1744                         Object[] va1 = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 };\r
1745                         Object[] va2 = { "true", "1", "a", "-1.2", "-32", "-234", "-34523", "-1",\r
1746                                          "-4.8F", "24234", "235354", "234552" };\r
1747 \r
1748                         Object[][] vt = { va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1 };\r
1749 \r
1750                         int[] arg_ex = {\r
1751                                 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
1752                                 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,\r
1753                                 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,\r
1754                                 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,\r
1755                                 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1,\r
1756                                 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1,\r
1757                                 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1,\r
1758                                 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1,\r
1759                                 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1,\r
1760                                 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,\r
1761                                 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0,\r
1762                                 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0\r
1763                         };\r
1764 \r
1765                         // SetValue\r
1766 \r
1767                         for (int i = 0; i < types.Length; i++) {\r
1768                                 for (int j = 0; j < types.Length; j++) {\r
1769                                         Array array = Array.CreateInstance (types [j], 2);\r
1770 \r
1771                                         Object value = vt[j][i];\r
1772 \r
1773                                         bool errorThrown = false;\r
1774                                         try {\r
1775                                                 array.SetValue (value, 0);\r
1776                                         } catch (ArgumentException) {\r
1777                                                 errorThrown = true;\r
1778                                         }\r
1779 \r
1780                                         int ex_index = (i * types.Length) + j;\r
1781 \r
1782                                         AssertEquals ("#M90(" + types [i] + "," + types [j] + ")",\r
1783                                                       errorThrown, arg_ex [ex_index] == 1);\r
1784                                 }\r
1785                         }\r
1786 \r
1787                         for (int i = 0; i < types.Length; i++) {\r
1788                                 String[] array = new String [2];\r
1789 \r
1790                                 Object value = va1 [i];\r
1791 \r
1792                                 bool errorThrown = false;\r
1793                                 try {\r
1794                                         array.SetValue (value, 0);\r
1795                                 } catch (InvalidCastException) {\r
1796                                         errorThrown = true;\r
1797                                 }\r
1798 \r
1799                                 Assert ("#M91(" + types [i] + ")", errorThrown);\r
1800                         }\r
1801 \r
1802                         for (int i = 0; i < types.Length; i++) {\r
1803                                 Array array = Array.CreateInstance (types [i], 2);\r
1804 \r
1805                                 Object value = va2 [i];\r
1806 \r
1807                                 bool errorThrown = false;\r
1808                                 try {\r
1809                                         array.SetValue (value, 0);\r
1810                                 } catch (InvalidCastException) {\r
1811                                         errorThrown = true;\r
1812                                 }\r
1813 \r
1814                                 Assert ("#M92(" + types [i] + ")", errorThrown);\r
1815                         }\r
1816 \r
1817                         for (int i = 0; i < types.Length; i++) {\r
1818                                 Array array = Array.CreateInstance (types [i], 2);\r
1819 \r
1820                                 Object value = null;\r
1821 \r
1822                                 bool errorThrown = false;\r
1823                                 try {\r
1824                                         array.SetValue (value, 0);\r
1825                                 } catch (InvalidCastException) {\r
1826                                         errorThrown = true;\r
1827                                 }\r
1828 \r
1829                                 Assert ("#M93(" + types [i] + ")", !errorThrown);\r
1830                         }\r
1831 \r
1832                         // Copy\r
1833 \r
1834                         for (int i = 0; i < types.Length; i++) {\r
1835                                 for (int j = 0; j < types.Length; j++) {\r
1836                                         Array source = Array.CreateInstance (types [i], 2);\r
1837                                         Array array = Array.CreateInstance (types [j], 2);\r
1838 \r
1839                                         source.SetValue (vt[j][i], 0);\r
1840                                         source.SetValue (vt[j][i], 1);\r
1841 \r
1842                                         bool errorThrown = false;\r
1843                                         try {\r
1844                                                 Array.Copy (source, array, 2);\r
1845                                         } catch (ArrayTypeMismatchException) {\r
1846                                                 errorThrown = true;\r
1847                                         }\r
1848 \r
1849                                         int ex_index = (i * types.Length) + j;\r
1850 \r
1851                                         AssertEquals ("#M94(" + types [i] + "," + types [j] + ")",\r
1852                                                       errorThrown, arg_ex [ex_index] == 1);\r
1853                                 }\r
1854                         }\r
1855 \r
1856                         for (int i = 0; i < types.Length; i++) {\r
1857                                 Array source = Array.CreateInstance (types [i], 2);\r
1858                                 String[] array = new String [2];\r
1859 \r
1860                                 source.SetValue (va1 [i], 0);\r
1861                                 source.SetValue (va1 [i], 1);\r
1862 \r
1863                                 bool errorThrown = false;\r
1864                                 try {\r
1865                                         Array.Copy (source, array, 2);\r
1866                                 } catch (ArrayTypeMismatchException) {\r
1867                                         errorThrown = true;\r
1868                                 }\r
1869 \r
1870                                 Assert ("#M95(" + types [i] + ")", errorThrown);\r
1871                         }\r
1872 \r
1873                         for (int i = 0; i < types.Length; i++) {\r
1874                                 String[] source = new String [2];\r
1875                                 Array array = Array.CreateInstance (types [i], 2);\r
1876 \r
1877                                 source.SetValue (va2 [i], 0);\r
1878                                 source.SetValue (va2 [i], 1);\r
1879 \r
1880                                 bool errorThrown = false;\r
1881                                 try {\r
1882                                         Array.Copy (source, array, 2);\r
1883                                 } catch (ArrayTypeMismatchException) {\r
1884                                         errorThrown = true;\r
1885                                 }\r
1886 \r
1887                                 Assert ("#M96(" + types [i] + ")", errorThrown);\r
1888                         }\r
1889                 }\r
1890         }\r
1891 \r
1892 \r
1893         public void TestSort() {\r
1894                 {\r
1895                         bool errorThrown = false;\r
1896                         try {\r
1897                                 Array.Sort(null);\r
1898                         } catch (ArgumentNullException) {\r
1899                                 errorThrown = true;\r
1900                         }\r
1901                         Assert("#N01", errorThrown);\r
1902                 }\r
1903                 {\r
1904                         bool errorThrown = false;\r
1905                         try {\r
1906                                 Array.Sort(null, 0, 1);\r
1907                         } catch (ArgumentNullException) {\r
1908                                 errorThrown = true;\r
1909                         }\r
1910                         Assert("#N02", errorThrown);\r
1911                 }\r
1912                 {\r
1913                         bool errorThrown = false;\r
1914                         try {\r
1915                                 char[] c1 = new Char[2];\r
1916                                 Array.Sort(null, c1);\r
1917                         } catch (ArgumentNullException) {\r
1918                                 errorThrown = true;\r
1919                         }\r
1920                         Assert("#N03", errorThrown);\r
1921                 }\r
1922                 {\r
1923                         bool errorThrown = false;\r
1924                         try {\r
1925                                 char[] c1 = new Char[2];\r
1926                                 Array.Sort(null, c1, 0, 1);\r
1927                         } catch (ArgumentNullException) {\r
1928                                 errorThrown = true;\r
1929                         }\r
1930                         Assert("#N04", errorThrown);\r
1931                 }\r
1932 \r
1933                 // note: null second array => just sort first array\r
1934                 char[] starter = {'d', 'b', 'f', 'e', 'a', 'c'};\r
1935                 int[] starter1 = {1,2,3,4,5,6};\r
1936                 {\r
1937                         char[] c1 = (char[])starter.Clone();\r
1938                         Array.Sort(c1);\r
1939                         AssertEquals("#N21", 'a', c1[0]);\r
1940                         AssertEquals("#N22", 'b', c1[1]);\r
1941                         AssertEquals("#N23", 'c', c1[2]);\r
1942                         AssertEquals("#N24", 'd', c1[3]);\r
1943                         AssertEquals("#N25", 'e', c1[4]);\r
1944                         AssertEquals("#N26", 'f', c1[5]);\r
1945                 }\r
1946                 {\r
1947                         char[] c1 = (char[])starter.Clone();\r
1948                         int[] i1 = (int[])starter1.Clone();\r
1949                         Array.Sort(c1, i1);\r
1950                         AssertEquals("#N41", 'a', c1[0]);\r
1951                         AssertEquals("#N42", 'b', c1[1]);\r
1952                         AssertEquals("#N43", 'c', c1[2]);\r
1953                         AssertEquals("#N44", 'd', c1[3]);\r
1954                         AssertEquals("#N45", 'e', c1[4]);\r
1955                         AssertEquals("#N46", 'f', c1[5]);\r
1956                         AssertEquals("#N47", 5, i1[0]);\r
1957                         AssertEquals("#N48", 2, i1[1]);\r
1958                         AssertEquals("#N49", 6, i1[2]);\r
1959                         AssertEquals("#N50", 1, i1[3]);\r
1960                         AssertEquals("#N51", 4, i1[4]);\r
1961                         AssertEquals("#N52", 3, i1[5]);\r
1962                 }\r
1963                 {\r
1964                         char[] c1 = (char[])starter.Clone();\r
1965                         Array.Sort(c1, 1, 4);\r
1966                         AssertEquals("#N61", 'd', c1[0]);\r
1967                         AssertEquals("#N62", 'a', c1[1]);\r
1968                         AssertEquals("#N63", 'b', c1[2]);\r
1969                         AssertEquals("#N64", 'e', c1[3]);\r
1970                         AssertEquals("#N65", 'f', c1[4]);\r
1971                         AssertEquals("#N66", 'c', c1[5]);\r
1972                 }\r
1973                 {\r
1974                         char[] c1 = (char[])starter.Clone();\r
1975                         int[] i1 = (int[])starter1.Clone();\r
1976                         Array.Sort(c1, i1, 1, 4);\r
1977                         AssertEquals("#N81", 'd', c1[0]);\r
1978                         AssertEquals("#N82", 'a', c1[1]);\r
1979                         AssertEquals("#N83", 'b', c1[2]);\r
1980                         AssertEquals("#N84", 'e', c1[3]);\r
1981                         AssertEquals("#N85", 'f', c1[4]);\r
1982                         AssertEquals("#N86", 'c', c1[5]);\r
1983                         AssertEquals("#N87", 1, i1[0]);\r
1984                         AssertEquals("#N88", 5, i1[1]);\r
1985                         AssertEquals("#N89", 2, i1[2]);\r
1986                         AssertEquals("#N90", 4, i1[3]);\r
1987                         AssertEquals("#N91", 3, i1[4]);\r
1988                         AssertEquals("#N92", 6, i1[5]);\r
1989                 }\r
1990         }\r
1991 \r
1992         // TODO - TestSort passed-in IComparable versions\r
1993 \r
1994 }\r
1995 \r
1996 }\r