Introducing ArrayTest
[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("Error not thrown", 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("Error not thrown", errorThrown);\r
92 \r
93                 {\r
94                         char[] bad = {'d', 'a', 'd', 'a', 'c', 'a'};\r
95                         AssertEquals("shouldn't find elem in badly-sorted array", -1, Array.BinarySearch(bad, 'c'));\r
96                 }\r
97                 {\r
98                         char[] bad = {'a', 'd', 'a', 'd', 'a', 'c', 'a'};\r
99                         AssertEquals("shouldn't find elem in badly-sorted array", -2, Array.BinarySearch(bad, 'c'));\r
100                 }\r
101                 {\r
102                         char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};\r
103                         Assert("couldn't find elem", \r
104                                Array.BinarySearch(arr, 'c') >= 3);\r
105                         Assert("couldn't find elem", \r
106                                Array.BinarySearch(arr, 'c') < 6);\r
107                 }\r
108                 {\r
109                         char[] arr = {'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};\r
110                         AssertEquals("couldn't find next-higher elem", \r
111                                      -4, Array.BinarySearch(arr, 'c'));\r
112                 }\r
113                 {\r
114                         char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};\r
115                         AssertEquals("couldn't find end", \r
116                                      -9, Array.BinarySearch(arr, 'e'));\r
117                 }\r
118         }\r
119         public void TestBinarySearch2() {\r
120                 bool errorThrown = false;\r
121                 try {\r
122                         Array.BinarySearch(null, 0, 1, "blue");\r
123                 } catch (ArgumentNullException) {\r
124                         errorThrown = true;\r
125                 }\r
126                 Assert("Error not thrown", errorThrown);\r
127                 errorThrown = false;\r
128                 try {\r
129                         char[,] c1 = new Char[2,2];\r
130                         Array.BinarySearch(c1, 0, 1, "needle");\r
131                 } catch (RankException) {\r
132                         errorThrown = true;\r
133                 }\r
134                 Assert("Error not thrown", errorThrown);\r
135                 errorThrown = false;\r
136                 try {\r
137                         char[] c1 = {'a'};\r
138                         Array.BinarySearch(c1, -1, 1, 'a');\r
139                 } catch (ArgumentOutOfRangeException) {\r
140                         errorThrown = true;\r
141                 }\r
142                 Assert("Error not thrown", errorThrown);\r
143                 errorThrown = false;\r
144                 try {\r
145                         char[] c1 = {'a'};\r
146                         Array.BinarySearch(c1, 0, -1, 'a');\r
147                 } catch (ArgumentOutOfRangeException) {\r
148                         errorThrown = true;\r
149                 }\r
150                 Assert("Error not thrown", errorThrown);\r
151                 errorThrown = false;\r
152                 try {\r
153                         char[] c1 = {'a'};\r
154                         Array.BinarySearch(c1, 0, 4, 'a');\r
155                 } catch (ArgumentException) {\r
156                         errorThrown = true;\r
157                 }\r
158                 Assert("Error not thrown", errorThrown);\r
159 \r
160                 // FIXME - see commented-out tests in TestBinarySearch1, above\r
161                 \r
162                 {\r
163                         char[] bad = {'z', 'z', 'd', 'a', 'd', 'a', 'c', 'a'};\r
164                         AssertEquals("shouldn't find elem in badly-sorted array", -3, Array.BinarySearch(bad, 2, 6, 'c'));\r
165                 }\r
166                 {\r
167                         char[] bad = {'z', 'z', 'a', 'd', 'a', 'd', 'a', 'c', 'a'};\r
168                         AssertEquals("shouldn't find elem in badly-sorted array", -4, Array.BinarySearch(bad, 2, 7, 'c'));\r
169                 }\r
170                 {\r
171                         char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};\r
172                         Assert("couldn't find elem", \r
173                                Array.BinarySearch(arr, 2, 8, 'c') >= 5);\r
174                         Assert("couldn't find elem", \r
175                                Array.BinarySearch(arr, 2, 8, 'c') < 8);\r
176                 }\r
177                 {\r
178                         char[] arr = {'z', 'z', 'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};\r
179                         AssertEquals("couldn't find next-higher elem", \r
180                                      -6, Array.BinarySearch(arr, 2, 8, 'c'));\r
181                 }\r
182                 {\r
183                         char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};\r
184                         AssertEquals("couldn't find end", \r
185                                      -11, Array.BinarySearch(arr, 2, 8, 'e'));\r
186                 }\r
187         }\r
188 \r
189         // TODO - testBinarySearch with explicit IComparer args\r
190 \r
191         public void TestClear() {\r
192                 bool errorThrown = false;\r
193                 try {\r
194                         Array.Clear(null, 0, 1);\r
195                 } catch (ArgumentNullException) {\r
196                         errorThrown = true;\r
197                 }\r
198                 Assert("error not thrown", errorThrown);\r
199 \r
200                 int[] i1 = { 1, 2, 3, 4 };\r
201                 {\r
202                         int[] compare = {1,2,3,4};\r
203                         AssertEquals("array match", compare[0], i1[0]);\r
204                         AssertEquals("array match", compare[1], i1[1]);\r
205                         AssertEquals("array match", compare[2], i1[2]);\r
206                         AssertEquals("array match", compare[3], i1[3]);\r
207                 }\r
208                 Array.Clear(i1, 3, 1);\r
209                 {\r
210                         int[] compare = {1,2,3,0};\r
211                         AssertEquals("array match", compare[0], i1[0]);\r
212                         AssertEquals("array match", compare[1], i1[1]);\r
213                         AssertEquals("array match", compare[2], i1[2]);\r
214                         AssertEquals("array match", compare[3], i1[3]);\r
215                 }\r
216                 Array.Clear(i1, 1, 1);\r
217                 {\r
218                         int[] compare = {1,0,3,0};\r
219                         AssertEquals("array match", compare[0], i1[0]);\r
220                         AssertEquals("array match", compare[1], i1[1]);\r
221                         AssertEquals("array match", compare[2], i1[2]);\r
222                         AssertEquals("array match", compare[3], i1[3]);\r
223                 }\r
224                 Array.Clear(i1, 1, 3);\r
225                 {\r
226                         int[] compare = {1,0,0,0};\r
227                         AssertEquals("array match", compare[0], i1[0]);\r
228                         AssertEquals("array match", compare[1], i1[1]);\r
229                         AssertEquals("array match", compare[2], i1[2]);\r
230                         AssertEquals("array match", compare[3], i1[3]);\r
231                 }\r
232 \r
233                 string[] s1 = { "red", "green", "blue" };\r
234                 Array.Clear(s1, 0, 3);\r
235                 {\r
236                         string[] compare = {null, null, null};\r
237                         AssertEquals("array match", compare[0], s1[0]);\r
238                         AssertEquals("array match", compare[1], s1[1]);\r
239                         AssertEquals("array match", compare[2], s1[2]);\r
240                 }\r
241         }\r
242 \r
243         public void TestClone() {\r
244                 char[] c1 = {'a', 'b', 'c'};\r
245                 char[] c2 = (char[])c1.Clone();\r
246                 AssertEquals("Array match", c1[0], c2[0]);\r
247                 AssertEquals("Array match", c1[1], c2[1]);\r
248                 AssertEquals("Array match", c1[2], c2[2]);\r
249 \r
250                 char[] d10 = {'a', 'b'};\r
251                 char[] d11 = {'a', 'c'};\r
252                 char[] d12 = {'b', 'c'};\r
253                 char[][] d1 = {d10, d11, d12};\r
254                 char[][] d2 = (char[][])d1.Clone();\r
255                 AssertEquals("Array match", d1[0], d2[0]);\r
256                 AssertEquals("Array match", d1[1], d2[1]);\r
257                 AssertEquals("Array match", d1[2], d2[2]);\r
258 \r
259                 d1[0][0] = 'z';\r
260                 AssertEquals("shallow copy", d1[0], d2[0]);\r
261         }\r
262 \r
263         public void TestCopy() {\r
264                 {\r
265                         bool errorThrown = false;\r
266                         try {\r
267                                 Char[] c1 = {};\r
268                                 Array.Copy(c1, null, 1);\r
269                         } catch (ArgumentNullException) {\r
270                                 errorThrown = true;\r
271                         }\r
272                         Assert("error not thrown", errorThrown);\r
273                 }\r
274                 {\r
275                         bool errorThrown = false;\r
276                         try {\r
277                                 Char[] c1 = {};\r
278                                 Array.Copy(null, c1, 1);\r
279                         } catch (ArgumentNullException) {\r
280                                 errorThrown = true;\r
281                         }\r
282                         Assert("error not thrown", errorThrown);\r
283                 }\r
284                 {\r
285                         bool errorThrown = false;\r
286                         try {\r
287                                 Char[] c1 = new Char[1];\r
288                                 Char[,] c2 = new Char[1,1];\r
289                                 Array.Copy(c1, c2, 1);\r
290                         } catch (RankException) {\r
291                                 errorThrown = true;\r
292                         }\r
293                         Assert("error not thrown", errorThrown);\r
294                 }\r
295                 {\r
296                         bool errorThrown = false;\r
297                         try {\r
298                                 Char[] c1 = new Char[1];\r
299                                 string[] s1 = new String[1];\r
300                                 Array.Copy(c1, s1, 1);\r
301                         } catch (ArrayTypeMismatchException) {\r
302                                 errorThrown = true;\r
303                         }\r
304                         Assert("error not thrown", errorThrown);\r
305                 }\r
306                 {\r
307                         bool errorThrown = false;\r
308                         try {\r
309                                 Char[] c1 = new Char[1];\r
310                                 Object[] o1 = new Object[1];\r
311                                 o1[0] = "hello";\r
312                                 Array.Copy(o1, c1, 1);\r
313                         } catch (InvalidCastException) {\r
314                                 errorThrown = true;\r
315                         }\r
316                         Assert("error not thrown", errorThrown);\r
317                 }\r
318                 {\r
319                         bool errorThrown = false;\r
320                         try {\r
321                                 Char[] c1 = new Char[1];\r
322                                 Char[] c2 = new Char[1];\r
323                                 Array.Copy(c1, c2, -1);\r
324                         } catch (ArgumentOutOfRangeException) {\r
325                                 errorThrown = true;\r
326                         }\r
327                         Assert("error not thrown", errorThrown);\r
328                 }\r
329                 {\r
330                         bool errorThrown = false;\r
331                         try {\r
332                                 Char[] c1 = new Char[1];\r
333                                 Char[] c2 = new Char[2];\r
334                                 Array.Copy(c1, c2, 2);\r
335                         } catch (ArgumentException) {\r
336                                 errorThrown = true;\r
337                         }\r
338                         Assert("error not thrown", errorThrown);\r
339                 }\r
340                 {\r
341                         bool errorThrown = false;\r
342                         try {\r
343                                 Char[] c1 = new Char[1];\r
344                                 Char[] c2 = new Char[2];\r
345                                 Array.Copy(c2, c1, 2);\r
346                         } catch (ArgumentException) {\r
347                                 errorThrown = true;\r
348                         }\r
349                         Assert("error not thrown", errorThrown);\r
350                 }\r
351 \r
352                 char[] orig = {'a', 'b', 'd', 'a'};\r
353                 char[] copy = new Char[4];\r
354                 Array.Copy(orig, copy, 4);\r
355                 for (int i = 0; i < orig.Length; i++) {\r
356                         AssertEquals("copy unsuccessful " + i,\r
357                                      orig[i], copy[i]);\r
358                 }\r
359                 Array.Clear(copy, 0, copy.Length);\r
360                 for (int i = 0; i < orig.Length; i++) {\r
361                         AssertEquals("clear unsuccessful " + i,\r
362                                      (char)0, copy[i]);\r
363                 }\r
364                 Array.Copy(orig, copy, 2);\r
365                 AssertEquals("copy unsuccessful 1", orig[0], copy[0]);\r
366                 AssertEquals("copy unsuccessful 2", orig[1], copy[1]);\r
367                 Assert("copy unsuccessful 3", orig[2] != copy[2]);\r
368                 Assert("copy unsuccessful 4", orig[3] != copy[3]);\r
369         }\r
370         public void TestCopy2() {\r
371                 {\r
372                         bool errorThrown = false;\r
373                         try {\r
374                                 Char[] c1 = new Char[2];\r
375                                 Char[] c2 = new Char[2];\r
376                                 Array.Copy(c2, 1, c1, 0, 2);\r
377                         } catch (ArgumentException) {\r
378                                 errorThrown = true;\r
379                         }\r
380                         Assert("error not thrown", errorThrown);\r
381                 }\r
382                 {\r
383                         bool errorThrown = false;\r
384                         try {\r
385                                 Char[] c1 = new Char[2];\r
386                                 Char[] c2 = new Char[2];\r
387                                 Array.Copy(c2, 0, c1, 1, 2);\r
388                         } catch (ArgumentException) {\r
389                                 errorThrown = true;\r
390                         }\r
391                         Assert("error not thrown", errorThrown);\r
392                 }\r
393                 \r
394                 char[] orig = {'a', 'b', 'd', 'a'};\r
395                 char[] copy = new Char[4];\r
396                 Array.Copy(orig, 1, copy, 1, 3);\r
397                 Assert("copy unsuccessful", copy[0] != orig[0]);\r
398                 for (int i = 1; i < orig.Length; i++) {\r
399                         AssertEquals("copy unsuccessful " + i,\r
400                                      orig[i], copy[i]);\r
401                 }\r
402                 Array.Clear(copy, 0, copy.Length);\r
403                 Array.Copy(orig, 1, copy, 0, 2);\r
404                 AssertEquals("copy unsuccessful", orig[1], copy[0]);\r
405                 AssertEquals("copy unsuccessful", orig[2], copy[1]);\r
406                 Assert("copy unsuccessful", copy[2] != orig[2]);\r
407                 Assert("copy unsuccessful", copy[3] != orig[3]);\r
408         }\r
409 \r
410         public void TestCopyTo() {\r
411                 {\r
412                         bool errorThrown = false;\r
413                         try {\r
414                                 Char[] c1 = new Char[2];\r
415                                 c1.CopyTo(null, 2);\r
416                         } catch (ArgumentNullException) {\r
417                                 errorThrown = true;\r
418                         }\r
419                         Assert("error not thrown", errorThrown);\r
420                 }\r
421                 {\r
422                         bool errorThrown = false;\r
423                         try {\r
424                                 Char[] c1 = new Char[2];\r
425                                 Char[,] c2 = new Char[2,2];\r
426                                 c1.CopyTo(c2, 2);\r
427                         } catch (ArgumentException) {\r
428                                 errorThrown = true;\r
429                         }\r
430                         Assert("error not thrown", errorThrown);\r
431                 }\r
432                 {\r
433                         bool errorThrown = false;\r
434                         try {\r
435                                 Char[,] c1 = new Char[2,2];\r
436                                 Char[] c2 = new Char[2];\r
437                                 c1.CopyTo(c2, 2);\r
438                         } catch (RankException) {\r
439                                 errorThrown = true;\r
440                         }\r
441                         Assert("error not thrown", errorThrown);\r
442                 }\r
443                 {\r
444                         bool errorThrown = false;\r
445                         try {\r
446                                 Char[] c1 = new Char[2];\r
447                                 Char[] c2 = new Char[2];\r
448                                 c1.CopyTo(c2, -1);\r
449                         } catch (ArgumentOutOfRangeException) {\r
450                                 errorThrown = true;\r
451                         }\r
452                         Assert("error not thrown", errorThrown);\r
453                 }\r
454                 {\r
455                         bool errorThrown = false;\r
456                         try {\r
457                                 Char[] c1 = new Char[2];\r
458                                 Char[] c2 = new Char[2];\r
459                                 c1.CopyTo(c2, 3);\r
460                         } catch (ArgumentException) {\r
461                                 errorThrown = true;\r
462                         }\r
463                         Assert("error not thrown", errorThrown);\r
464                 }\r
465                 {\r
466                         bool errorThrown = false;\r
467                         try {\r
468                                 Char[] c1 = new Char[2];\r
469                                 Char[] c2 = new Char[2];\r
470                                 c1.CopyTo(c2, 1);\r
471                         } catch (ArgumentException) {\r
472                                 errorThrown = true;\r
473                         }\r
474                         Assert("error not thrown", errorThrown);\r
475                 }\r
476                 {\r
477                         bool errorThrown = false;\r
478                         try {\r
479                                 String[] c1 = new String[2];\r
480                                 Char[] c2 = new Char[2];\r
481                                 c1.CopyTo(c2, 0);\r
482                         } catch (ArrayTypeMismatchException) {\r
483                                 errorThrown = true;\r
484                         }\r
485                         Assert("error not thrown", errorThrown);\r
486                 }\r
487 \r
488                 Char[] orig = {'a', 'b', 'c', 'd'};\r
489                 Char[] copy = new Char[10];\r
490                 Array.Clear(copy, 0, copy.Length);\r
491                 orig.CopyTo(copy, 3);\r
492                 AssertEquals("Wrong CopyTo 0", (char)0, copy[0]);\r
493                 AssertEquals("Wrong CopyTo 0", (char)0, copy[1]);\r
494                 AssertEquals("Wrong CopyTo 0", (char)0, copy[2]);\r
495                 AssertEquals("Wrong CopyTo 0", orig[0], copy[3]);\r
496                 AssertEquals("Wrong CopyTo 0", orig[1], copy[4]);\r
497                 AssertEquals("Wrong CopyTo 0", orig[2], copy[5]);\r
498                 AssertEquals("Wrong CopyTo 0", orig[3], copy[6]);\r
499                 AssertEquals("Wrong CopyTo 0", (char)0, copy[7]);\r
500                 AssertEquals("Wrong CopyTo 0", (char)0, copy[8]);\r
501                 AssertEquals("Wrong CopyTo 0", (char)0, copy[9]);\r
502         }\r
503 \r
504         public void TestCreateInstance() {\r
505                 {\r
506                         bool errorThrown = false;\r
507                         try {\r
508                                 Array.CreateInstance(null, 12);\r
509                         } catch (ArgumentNullException) {\r
510                                 errorThrown = true;\r
511                         }\r
512                         Assert("error not thrown", errorThrown);\r
513                 }\r
514                 {\r
515                         bool errorThrown = false;\r
516                         try {\r
517                                 Array.CreateInstance(Type.GetType("System.Char"), -3);\r
518                         } catch (ArgumentOutOfRangeException) {\r
519                                 errorThrown = true;\r
520                         }\r
521                         Assert("error not thrown", errorThrown);\r
522                 }\r
523 \r
524                 char[] c1 = (char[])Array.CreateInstance(Type.GetType("System.Char"), 12);\r
525                 AssertEquals("Array wrong size", 12, c1.Length);\r
526         }\r
527 \r
528         public void TestGetEnumerator() {\r
529                 String[] s1 = {"this", "is", "a", "test"};\r
530                 IEnumerator en = s1.GetEnumerator();\r
531                 AssertNotNull("No enumerator", en);\r
532 \r
533                 for (int i = 0; i < s1.Length; i++) {\r
534                         en.MoveNext();\r
535                         AssertEquals("Not enumerating", s1[i], en.Current);\r
536                 }\r
537         }\r
538 \r
539         public void TestGetLength() {\r
540                 {\r
541                         bool errorThrown = false;\r
542                         try {\r
543                                 char[] c1 = {'a', 'b', 'c'};\r
544                                 c1.GetLength(-1);\r
545                         } catch (IndexOutOfRangeException) {\r
546                                 errorThrown = true;\r
547                         }\r
548                         Assert("error not thrown", errorThrown);\r
549                 }\r
550                 {\r
551                         bool errorThrown = false;\r
552                         try {\r
553                                 char[] c1 = {'a', 'b', 'c'};\r
554                                 c1.GetLength(1);\r
555                         } catch (IndexOutOfRangeException) {\r
556                                 errorThrown = true;\r
557                         }\r
558                         Assert("error not thrown", errorThrown);\r
559                 }\r
560 \r
561                 char[] c2 = new Char[5];\r
562                 AssertEquals("wrong single dimension length", \r
563                              5, c2.GetLength(0));\r
564 \r
565                 char[,] c3 = new Char[6,7];\r
566                 AssertEquals("wrong single dimension length", \r
567                              6, c3.GetLength(0));\r
568                 AssertEquals("wrong single dimension length", \r
569                              7, c3.GetLength(1));\r
570         }\r
571 \r
572         public void TestGetLowerBound() {\r
573                 // I have no idea what the point of this function is.\r
574                 {\r
575                         bool errorThrown = false;\r
576                         try {\r
577                                 char[] c = {'a', 'b', 'c'};\r
578                                 c.GetLowerBound(-1);\r
579                         } catch (IndexOutOfRangeException) {\r
580                                 errorThrown = true;\r
581                         }\r
582                         Assert("error not thrown", errorThrown);\r
583                 }\r
584                 {\r
585                         bool errorThrown = false;\r
586                         try {\r
587                                 char[] c = {'a', 'b', 'c'};\r
588                                 c.GetLowerBound(1);\r
589                         } catch (IndexOutOfRangeException) {\r
590                                 errorThrown = true;\r
591                         }\r
592                         Assert("error not thrown", errorThrown);\r
593                 }\r
594 \r
595                 char[] c1 = new Char[5];\r
596                 AssertEquals("single-dimensional lower bound", \r
597                              0, c1.GetLowerBound(0));\r
598 \r
599                 char[,] c2 = new Char[4,4];\r
600                 AssertEquals("multiple-dimensional lower bound", \r
601                              0, c2.GetLowerBound(0));\r
602                 AssertEquals("multiple-dimensional lower bound", \r
603                              0, c2.GetLowerBound(1));\r
604         }\r
605 \r
606         public void TestGetUpperBound() {\r
607                 {\r
608                         bool errorThrown = false;\r
609                         try {\r
610                                 char[] c = {'a', 'b', 'c'};\r
611                                 c.GetUpperBound(-1);\r
612                         } catch (IndexOutOfRangeException) {\r
613                                 errorThrown = true;\r
614                         }\r
615                         Assert("error not thrown", errorThrown);\r
616                 }\r
617                 {\r
618                         bool errorThrown = false;\r
619                         try {\r
620                                 char[] c = {'a', 'b', 'c'};\r
621                                 c.GetUpperBound(1);\r
622                         } catch (IndexOutOfRangeException) {\r
623                                 errorThrown = true;\r
624                         }\r
625                         Assert("error not thrown", errorThrown);\r
626                 }\r
627 \r
628                 char[] c1 = new Char[5];\r
629                 AssertEquals("single-dimensional lower bound", \r
630                              4, c1.GetUpperBound(0));\r
631 \r
632                 char[,] c2 = new Char[4,6];\r
633                 AssertEquals("multiple-dimensional lower bound", \r
634                              3, c2.GetUpperBound(0));\r
635                 AssertEquals("multiple-dimensional lower bound", \r
636                              5, c2.GetUpperBound(1));\r
637         }\r
638 \r
639         public void TestGetValue1() {\r
640                 {\r
641                         bool errorThrown = false;\r
642                         try {\r
643                                 char[,] c = new Char[2,2];\r
644                                 c.GetValue(1);\r
645                         } catch (ArgumentException) {\r
646                                 errorThrown = true;\r
647                         }\r
648                         Assert("error not thrown", errorThrown);\r
649                 }\r
650                 {\r
651                         bool errorThrown = false;\r
652                         try {\r
653                                 char[] c = {'a', 'b', 'c'};\r
654                                 c.GetValue(-1);\r
655                         } catch (IndexOutOfRangeException) {\r
656                                 errorThrown = true;\r
657                         }\r
658                         Assert("error not thrown", errorThrown);\r
659                 }\r
660                 {\r
661                         bool errorThrown = false;\r
662                         try {\r
663                                 char[] c = {'a', 'b', 'c'};\r
664                                 c.GetValue(4);\r
665                         } catch (IndexOutOfRangeException) {\r
666                                 errorThrown = true;\r
667                         }\r
668                         Assert("error not thrown", errorThrown);\r
669                 }\r
670 \r
671                 char[] c1 = {'a', 'b', 'c', 'd'};\r
672                 for (int i = 0; i < c1.Length; i++) {\r
673                         AssertEquals("Bad GetValue", c1[i], c1.GetValue(i));\r
674                 }\r
675         }\r
676         public void TestGetValue2() {\r
677                 {\r
678                         bool errorThrown = false;\r
679                         try {\r
680                                 char[] c = new Char[2];\r
681                                 c.GetValue(1,1);\r
682                         } catch (ArgumentException) {\r
683                                 errorThrown = true;\r
684                         }\r
685                         Assert("error not thrown", errorThrown);\r
686                 }\r
687                 {\r
688                         bool errorThrown = false;\r
689                         try {\r
690                                 char[,] c = new Char[2,2];\r
691                                 c.GetValue(-1, 1);\r
692                         } catch (IndexOutOfRangeException) {\r
693                                 errorThrown = true;\r
694                         }\r
695                         Assert("error not thrown", errorThrown);\r
696                 }\r
697                 {\r
698                         bool errorThrown = false;\r
699                         try {\r
700                                 char[,] c = new Char[2,2];\r
701                                 c.GetValue(4,1);\r
702                         } catch (IndexOutOfRangeException) {\r
703                                 errorThrown = true;\r
704                         }\r
705                         Assert("error not thrown", errorThrown);\r
706                 }\r
707 \r
708                 char[,] c1 = new Char[4,6];\r
709                 for (int i = 0; i < 24; i++) {\r
710                         int first = i / 6;\r
711                         int second = i % 6;\r
712                         c1[first,second] = (char)(((int)'a')+i);\r
713                 }\r
714                 for (int i = 0; i < c1.GetLength(0); i++) {\r
715                         for (int j = 0; j < c1.GetLength(1); j++) {\r
716                                 AssertEquals("Bad GetValue", \r
717                                              c1[i,j], c1.GetValue(i, j));\r
718                         }\r
719                 }\r
720         }\r
721         public void TestGetValue3() {\r
722                 {\r
723                         bool errorThrown = false;\r
724                         try {\r
725                                 char[] c = new Char[2];\r
726                                 c.GetValue(1,1,1);\r
727                         } catch (ArgumentException) {\r
728                                 errorThrown = true;\r
729                         }\r
730                         Assert("error not thrown", errorThrown);\r
731                 }\r
732                 {\r
733                         bool errorThrown = false;\r
734                         try {\r
735                                 char[,,] c = new Char[2,2,2];\r
736                                 c.GetValue(-1, 1, 1);\r
737                         } catch (IndexOutOfRangeException) {\r
738                                 errorThrown = true;\r
739                         }\r
740                         Assert("error not thrown", errorThrown);\r
741                 }\r
742                 {\r
743                         bool errorThrown = false;\r
744                         try {\r
745                                 char[,,] c = new Char[2,2,2];\r
746                                 c.GetValue(4,1,1);\r
747                         } catch (IndexOutOfRangeException) {\r
748                                 errorThrown = true;\r
749                         }\r
750                         Assert("error not thrown", errorThrown);\r
751                 }\r
752 \r
753                 char[,,] c1 = new Char[4,2,3];\r
754                 for (int i = 0; i < 24; i++) {\r
755                         int first = i / 6;\r
756                         int remains = i % 6;\r
757                         int second = remains / 3;\r
758                         int third = remains % 3;\r
759                         c1[first,second, third] = (char)(((int)'a')+i);\r
760                 }\r
761                 for (int i = 0; i < c1.GetLength(0); i++) {\r
762                         for (int j = 0; j < c1.GetLength(1); j++) {\r
763                                 for (int k = 0; k < c1.GetLength(2); k++) {\r
764                                 AssertEquals("Bad GetValue", \r
765                                              c1[i,j,k], c1.GetValue(i,j,k));\r
766                                 }\r
767                         }\r
768                 }\r
769         }\r
770         public void TestGetValueN() {\r
771                 {\r
772                         bool errorThrown = false;\r
773                         try {\r
774                                 char[] c = new Char[2];\r
775                                 c.GetValue(null);\r
776                         } catch (ArgumentNullException) {\r
777                                 errorThrown = true;\r
778                         }\r
779                         Assert("error not thrown", errorThrown);\r
780                 }\r
781                 {\r
782                         bool errorThrown = false;\r
783                         try {\r
784                                 char[] c = new Char[2];\r
785                                 int[] coords = {1, 1};\r
786                                 c.GetValue(coords);\r
787                         } catch (ArgumentException) {\r
788                                 errorThrown = true;\r
789                         }\r
790                         Assert("error not thrown", errorThrown);\r
791                 }\r
792                 {\r
793                         bool errorThrown = false;\r
794                         try {\r
795                                 char[,] c = new Char[2,2];\r
796                                 int[] coords = {-1, 1};\r
797                                 c.GetValue(coords);\r
798                         } catch (IndexOutOfRangeException) {\r
799                                 errorThrown = true;\r
800                         }\r
801                         Assert("error not thrown", errorThrown);\r
802                 }\r
803                 {\r
804                         bool errorThrown = false;\r
805                         try {\r
806                                 char[,] c = new Char[2,2];\r
807                                 int[] coords = {4, 1};\r
808                                 c.GetValue(coords);\r
809                         } catch (IndexOutOfRangeException) {\r
810                                 errorThrown = true;\r
811                         }\r
812                         Assert("error not thrown", errorThrown);\r
813                 }\r
814 \r
815                 char[,] c1 = new Char[4,6];\r
816                 for (int i = 0; i < 24; i++) {\r
817                         int first = i / 6;\r
818                         int second = i % 6;\r
819                         c1[first,second] = (char)(((int)'a')+i);\r
820                 }\r
821                 for (int i = 0; i < c1.GetLength(0); i++) {\r
822                         for (int j = 0; j < c1.GetLength(1); j++) {\r
823                                 int[] coords = {i, j};\r
824                                 AssertEquals("Bad GetValue", \r
825                                              c1[i,j], c1.GetValue(coords));\r
826                         }\r
827                 }\r
828         }\r
829 \r
830         public void TestIndexOf1() {\r
831                 {\r
832                         bool errorThrown = false;\r
833                         try {\r
834                                 Array.IndexOf(null, "huh?");\r
835                         } catch (ArgumentNullException) {\r
836                                 errorThrown = true;\r
837                         }\r
838                         Assert("error not thrown", errorThrown);\r
839                 }\r
840                 {\r
841                         bool errorThrown = false;\r
842                         try {\r
843                                 char[,] c = new Char[2,2];\r
844                                 Array.IndexOf(c, "huh?");\r
845                         } catch (RankException) {\r
846                                 errorThrown = true;\r
847                         }\r
848                         Assert("error not thrown", errorThrown);\r
849                 }\r
850 \r
851                 String[] s1 = {"this", "is", "a", "test"};\r
852                 AssertEquals("No null here", -1, Array.IndexOf(s1, null));\r
853                 AssertEquals("No nothing here", -1, Array.IndexOf(s1, "nothing"));\r
854                 AssertEquals("Found first", 0, Array.IndexOf(s1, "this"));\r
855                 AssertEquals("Found last", 3, Array.IndexOf(s1, "test"));\r
856         }\r
857         public void TestIndexOf2() {\r
858                 {\r
859                         bool errorThrown = false;\r
860                         try {\r
861                                 Array.IndexOf(null, "huh?", 0);\r
862                         } catch (ArgumentNullException) {\r
863                                 errorThrown = true;\r
864                         }\r
865                         Assert("error not thrown", errorThrown);\r
866                 }\r
867                 {\r
868                         bool errorThrown = false;\r
869                         try {\r
870                                 char[,] c = new Char[2,2];\r
871                                 Array.IndexOf(c, "huh?", 0);\r
872                         } catch (RankException) {\r
873                                 errorThrown = true;\r
874                         }\r
875                         Assert("error not thrown", errorThrown);\r
876                 }\r
877                 {\r
878                         bool errorThrown = false;\r
879                         try {\r
880                                 char[] c = new Char[2];\r
881                                 Array.IndexOf(c, "huh?", 3);\r
882                         } catch (ArgumentOutOfRangeException) {\r
883                                 errorThrown = true;\r
884                         }\r
885                         Assert("error not thrown", errorThrown);\r
886                 }\r
887 \r
888                 String[] s1 = {"this", "is", "really", "a", "test"};\r
889                 AssertEquals("No null here", -1, Array.IndexOf(s1, null, 1));\r
890                 AssertEquals("No nothing here", -1, Array.IndexOf(s1, "nothing", 1));\r
891                 AssertEquals("Didn't find first", -1, Array.IndexOf(s1, "this", 1));\r
892                 AssertEquals("Found first", 1, Array.IndexOf(s1, "is", 1));\r
893                 AssertEquals("Found last", 4, Array.IndexOf(s1, "test", 1));\r
894         }\r
895         public void TestIndexOf3() {\r
896                 {\r
897                         bool errorThrown = false;\r
898                         try {\r
899                                 Array.IndexOf(null, "huh?", 0, 1);\r
900                         } catch (ArgumentNullException) {\r
901                                 errorThrown = true;\r
902                         }\r
903                         Assert("error not thrown", errorThrown);\r
904                 }\r
905                 {\r
906                         bool errorThrown = false;\r
907                         try {\r
908                                 char[,] c = new Char[2,2];\r
909                                 Array.IndexOf(c, "huh?", 0, 1);\r
910                         } catch (RankException) {\r
911                                 errorThrown = true;\r
912                         }\r
913                         Assert("error not thrown", errorThrown);\r
914                 }\r
915                 {\r
916                         bool errorThrown = false;\r
917                         try {\r
918                                 char[] c = new Char[2];\r
919                                 Array.IndexOf(c, "huh?", 3, 1);\r
920                         } catch (ArgumentOutOfRangeException) {\r
921                                 errorThrown = true;\r
922                         }\r
923                         Assert("error not thrown", errorThrown);\r
924                 }\r
925                 {\r
926                         bool errorThrown = false;\r
927                         try {\r
928                                 char[] c = new Char[2];\r
929                                 Array.IndexOf(c, "huh?", 0, 5);\r
930                         } catch (ArgumentOutOfRangeException) {\r
931                                 errorThrown = true;\r
932                         }\r
933                         Assert("error not thrown", errorThrown);\r
934                 }\r
935 \r
936                 String[] s1 = {"this", "is", "really", "a", "test"};\r
937                 AssertEquals("No null here", -1, Array.IndexOf(s1, null, 1, 3));\r
938                 AssertEquals("No nothing here", -1, Array.IndexOf(s1, "nothing", 1, 3));\r
939                 AssertEquals("Didn't find first", -1, Array.IndexOf(s1, "this", 1, 3));\r
940                 AssertEquals("Found first", 1, Array.IndexOf(s1, "is", 1, 3));\r
941                 AssertEquals("Didn't find last", -1, Array.IndexOf(s1, "test", 1, 3));\r
942                 AssertEquals("Found last", 3, Array.IndexOf(s1, "a", 1, 3));\r
943         }\r
944         \r
945         public void TestLastIndexOf1() {\r
946                 {\r
947                         bool errorThrown = false;\r
948                         try {\r
949                                 Array.LastIndexOf(null, "huh?");\r
950                         } catch (ArgumentNullException) {\r
951                                 errorThrown = true;\r
952                         }\r
953                         Assert("error not thrown", errorThrown);\r
954                 }\r
955                 {\r
956                         bool errorThrown = false;\r
957                         try {\r
958                                 char[,] c = new Char[2,2];\r
959                                 Array.LastIndexOf(c, "huh?");\r
960                         } catch (RankException) {\r
961                                 errorThrown = true;\r
962                         }\r
963                         Assert("error not thrown", errorThrown);\r
964                 }\r
965 \r
966                 String[] s1 = {"this", "is", "a", "a", "test"};\r
967                 AssertEquals("No null here", -1, Array.LastIndexOf(s1, null));\r
968                 AssertEquals("No nothing here", -1, Array.LastIndexOf(s1, "nothing"));\r
969                 AssertEquals("Found first", 0, Array.LastIndexOf(s1, "this"));\r
970                 AssertEquals("Found last", 4, Array.LastIndexOf(s1, "test"));\r
971                 AssertEquals("Found repeat", 3, Array.LastIndexOf(s1, "a"));\r
972         }\r
973         public void TestLastIndexOf2() {\r
974                 {\r
975                         bool errorThrown = false;\r
976                         try {\r
977                                 Array.LastIndexOf(null, "huh?", 0);\r
978                         } catch (ArgumentNullException) {\r
979                                 errorThrown = true;\r
980                         }\r
981                         Assert("error not thrown", errorThrown);\r
982                 }\r
983                 {\r
984                         bool errorThrown = false;\r
985                         try {\r
986                                 char[,] c = new Char[2,2];\r
987                                 Array.LastIndexOf(c, "huh?", 0);\r
988                         } catch (RankException) {\r
989                                 errorThrown = true;\r
990                         }\r
991                         Assert("error not thrown", errorThrown);\r
992                 }\r
993                 {\r
994                         bool errorThrown = false;\r
995                         try {\r
996                                 char[] c = new Char[2];\r
997                                 Array.LastIndexOf(c, "huh?", 3);\r
998                         } catch (ArgumentOutOfRangeException) {\r
999                                 errorThrown = true;\r
1000                         }\r
1001                         Assert("error not thrown", errorThrown);\r
1002                 }\r
1003 \r
1004                 String[] s1 = {"this", "is", "really", "a", "test"};\r
1005                 AssertEquals("No null here", -1, Array.LastIndexOf(s1, null, 3));\r
1006                 AssertEquals("No nothing here", -1, Array.LastIndexOf(s1, "nothing", 3));\r
1007                 AssertEquals("Didn't find larst", -1, Array.LastIndexOf(s1, "test", 3));\r
1008                 AssertEquals("Found last", 3, Array.LastIndexOf(s1, "a", 3));\r
1009                 AssertEquals("Found first", 0, Array.LastIndexOf(s1, "this", 3));\r
1010         }\r
1011         public void TestLastIndexOf3() {\r
1012                 {\r
1013                         bool errorThrown = false;\r
1014                         try {\r
1015                                 Array.LastIndexOf(null, "huh?", 0, 1);\r
1016                         } catch (ArgumentNullException) {\r
1017                                 errorThrown = true;\r
1018                         }\r
1019                         Assert("error not thrown", errorThrown);\r
1020                 }\r
1021                 {\r
1022                         bool errorThrown = false;\r
1023                         try {\r
1024                                 char[,] c = new Char[2,2];\r
1025                                 Array.LastIndexOf(c, "huh?", 0, 1);\r
1026                         } catch (RankException) {\r
1027                                 errorThrown = true;\r
1028                         }\r
1029                         Assert("error not thrown", errorThrown);\r
1030                 }\r
1031                 {\r
1032                         bool errorThrown = false;\r
1033                         try {\r
1034                                 char[] c = new Char[2];\r
1035                                 Array.LastIndexOf(c, "huh?", 3, 1);\r
1036                         } catch (ArgumentOutOfRangeException) {\r
1037                                 errorThrown = true;\r
1038                         }\r
1039                         Assert("error not thrown", errorThrown);\r
1040                 }\r
1041                 {\r
1042                         bool errorThrown = false;\r
1043                         try {\r
1044                                 char[] c = new Char[2];\r
1045                                 Array.LastIndexOf(c, "huh?", 0, 5);\r
1046                         } catch (ArgumentOutOfRangeException) {\r
1047                                 errorThrown = true;\r
1048                         }\r
1049                         Assert("error not thrown", errorThrown);\r
1050                 }\r
1051 \r
1052                 String[] s1 = {"this", "is", "really", "a", "test"};\r
1053                 AssertEquals("No null here", \r
1054                              -1, Array.LastIndexOf(s1, null, 3, 3));\r
1055                 AssertEquals("No nothing here", \r
1056                              -1, Array.LastIndexOf(s1, "nothing", 3, 3));\r
1057                 AssertEquals("Didn't find first", \r
1058                              -1, Array.LastIndexOf(s1, "this", 3, 3));\r
1059                 AssertEquals("Found first", \r
1060                              1, Array.LastIndexOf(s1, "is", 3, 3));\r
1061                 AssertEquals("Didn't find last", \r
1062                              -1, Array.LastIndexOf(s1, "test", 3, 3));\r
1063                 AssertEquals("Found last", \r
1064                              3, Array.LastIndexOf(s1, "a", 3, 3));\r
1065         }\r
1066 \r
1067         public void TestReverse() {\r
1068                 {\r
1069                         bool errorThrown = false;\r
1070                         try {\r
1071                                 Array.Reverse(null);\r
1072                         } catch (ArgumentNullException) {\r
1073                                 errorThrown = true;\r
1074                         }\r
1075                         Assert("error not thrown", errorThrown);\r
1076                 }\r
1077                 {\r
1078                         bool errorThrown = false;\r
1079                         try {\r
1080                                 char[,] c = new Char[2,2];\r
1081                                 Array.Reverse(c);\r
1082                         } catch (RankException) {\r
1083                                 errorThrown = true;\r
1084                         }\r
1085                         Assert("error not thrown", errorThrown);\r
1086                 }\r
1087                 \r
1088                 char[] c1 = {'a', 'b', 'c', 'd'};\r
1089                 Array.Reverse(c1);\r
1090                 AssertEquals("Reverse not working", 'd', c1[0]);\r
1091                 AssertEquals("Reverse not working", 'c', c1[1]);\r
1092                 AssertEquals("Reverse not working", 'b', c1[2]);\r
1093                 AssertEquals("Reverse not working", 'a', c1[3]);\r
1094 \r
1095                 {\r
1096                         bool errorThrown = false;\r
1097                         try {\r
1098                                 Array.Reverse(null, 0, 0);\r
1099                         } catch (ArgumentNullException) {\r
1100                                 errorThrown = true;\r
1101                         }\r
1102                         Assert("error not thrown", errorThrown);\r
1103                 }\r
1104                 {\r
1105                         bool errorThrown = false;\r
1106                         try {\r
1107                                 char[,] c = new Char[2,2];\r
1108                                 Array.Reverse(c, 0, 0);\r
1109                         } catch (RankException) {\r
1110                                 errorThrown = true;\r
1111                         }\r
1112                         Assert("error not thrown", errorThrown);\r
1113                 }\r
1114                 //{\r
1115                 //bool errorThrown = false;\r
1116                 //try {\r
1117                 //      char[] c = new Char[2];\r
1118                 //      Array.Reverse(c, 0, 3);\r
1119                 //} catch (ArgumentOutOfRangeException) {\r
1120                 //      errorThrown = true;\r
1121                 //}\r
1122                 //Assert("error not thrown", errorThrown);\r
1123                 //}\r
1124                 //{\r
1125                 //bool errorThrown = false;\r
1126                 //try {\r
1127                 //      char[] c = new Char[2];\r
1128                 //      Array.Reverse(c, 3, 0);\r
1129                 //} catch (ArgumentOutOfRangeException) {\r
1130                 //      errorThrown = true;\r
1131                 //}\r
1132                 //Assert("error not thrown", errorThrown);\r
1133                 //}\r
1134 \r
1135                 char[] c2 = { 'a', 'b', 'c', 'd'};\r
1136                 Array.Reverse(c2, 1, 2);\r
1137                 AssertEquals("Reverse not working", 'a', c2[0]);\r
1138                 AssertEquals("Reverse not working", 'c', c2[1]);\r
1139                 AssertEquals("Reverse not working", 'b', c2[2]);\r
1140                 AssertEquals("Reverse not working", 'd', c2[3]);\r
1141         }\r
1142 \r
1143         public void TestSetValue1() {\r
1144                 {\r
1145                         bool errorThrown = false;\r
1146                         try {\r
1147                                 char[,] c = new Char[2,2];\r
1148                                 c.SetValue("buh", 1);\r
1149                         } catch (ArgumentException) {\r
1150                                 errorThrown = true;\r
1151                         }\r
1152                         Assert("error not thrown", errorThrown);\r
1153                 }\r
1154                 {\r
1155                         bool errorThrown = false;\r
1156                         try {\r
1157                                 char[] c = {'a', 'b', 'c'};\r
1158                                 c.SetValue("buh", -1);\r
1159                         } catch (IndexOutOfRangeException) {\r
1160                                 errorThrown = true;\r
1161                         }\r
1162                         Assert("error not thrown", errorThrown);\r
1163                 }\r
1164                 {\r
1165                         bool errorThrown = false;\r
1166                         try {\r
1167                                 char[] c = {'a', 'b', 'c'};\r
1168                                 c.SetValue("buh", 4);\r
1169                         } catch (IndexOutOfRangeException) {\r
1170                                 errorThrown = true;\r
1171                         }\r
1172                         Assert("error not thrown", errorThrown);\r
1173                 }\r
1174 \r
1175                 char[] c1 = {'a', 'b', 'c', 'd'};\r
1176                 char[] c2 = new char[4];\r
1177                 for (int i = 0; i < c1.Length; i++) {\r
1178                         c2.SetValue(c1[i], i);\r
1179                 }\r
1180                 for (int i = 0; i < c1.Length; i++) {\r
1181                         AssertEquals("Bad SetValue", c1[i], c2[i]);\r
1182                 }\r
1183         }\r
1184         public void TestSetValue2() {\r
1185                 {\r
1186                         bool errorThrown = false;\r
1187                         try {\r
1188                                 char[] c = new Char[2];\r
1189                                 c.SetValue("buh", 1,1);\r
1190                         } catch (ArgumentException) {\r
1191                                 errorThrown = true;\r
1192                         }\r
1193                         Assert("error not thrown", errorThrown);\r
1194                 }\r
1195                 {\r
1196                         bool errorThrown = false;\r
1197                         try {\r
1198                                 char[,] c = new Char[2,2];\r
1199                                 c.SetValue("buh", -1, 1);\r
1200                         } catch (IndexOutOfRangeException) {\r
1201                                 errorThrown = true;\r
1202                         }\r
1203                         Assert("error not thrown", errorThrown);\r
1204                 }\r
1205                 {\r
1206                         bool errorThrown = false;\r
1207                         try {\r
1208                                 char[,] c = new Char[2,2];\r
1209                                 c.SetValue("buh", 4,1);\r
1210                         } catch (IndexOutOfRangeException) {\r
1211                                 errorThrown = true;\r
1212                         }\r
1213                         Assert("error not thrown", errorThrown);\r
1214                 }\r
1215 \r
1216                 char[,] c1 = new Char[4,6];\r
1217                 char[,] c2 = new Char[4,6];\r
1218                 for (int i = 0; i < 24; i++) {\r
1219                         int first = i / 6;\r
1220                         int second = i % 6;\r
1221                         c1[first,second] = (char)(((int)'a')+i);\r
1222                         c2.SetValue(c1[first,second], first, second);\r
1223                 }\r
1224                 for (int i = 0; i < c1.GetLength(0); i++) {\r
1225                         for (int j = 0; j < c1.GetLength(1); j++) {\r
1226                                 AssertEquals("Bad SetValue", \r
1227                                              c1[i,j], c2[i, j]);\r
1228                         }\r
1229                 }\r
1230         }\r
1231         public void TestSetValue3() {\r
1232                 {\r
1233                         bool errorThrown = false;\r
1234                         try {\r
1235                                 char[] c = new Char[2];\r
1236                                 c.SetValue("buh", 1,1,1);\r
1237                         } catch (ArgumentException) {\r
1238                                 errorThrown = true;\r
1239                         }\r
1240                         Assert("error not thrown", errorThrown);\r
1241                 }\r
1242                 {\r
1243                         bool errorThrown = false;\r
1244                         try {\r
1245                                 char[,,] c = new Char[2,2,2];\r
1246                                 c.SetValue("buh", -1, 1, 1);\r
1247                         } catch (IndexOutOfRangeException) {\r
1248                                 errorThrown = true;\r
1249                         }\r
1250                         Assert("error not thrown", errorThrown);\r
1251                 }\r
1252                 {\r
1253                         bool errorThrown = false;\r
1254                         try {\r
1255                                 char[,,] c = new Char[2,2,2];\r
1256                                 c.SetValue("buh", 4,1,1);\r
1257                         } catch (IndexOutOfRangeException) {\r
1258                                 errorThrown = true;\r
1259                         }\r
1260                         Assert("error not thrown", errorThrown);\r
1261                 }\r
1262 \r
1263                 char[,,] c1 = new Char[4,2,3];\r
1264                 char[,,] c2 = new Char[4,2,3];\r
1265                 for (int i = 0; i < 24; i++) {\r
1266                         int first = i / 6;\r
1267                         int remains = i % 6;\r
1268                         int second = remains / 3;\r
1269                         int third = remains % 3;\r
1270                         c1[first,second, third] = (char)(((int)'a')+i);\r
1271                         c2.SetValue(c1[first, second, third], first, second, third);\r
1272                 }\r
1273                 for (int i = 0; i < c1.GetLength(0); i++) {\r
1274                         for (int j = 0; j < c1.GetLength(1); j++) {\r
1275                                 for (int k = 0; k < c1.GetLength(2); k++) {\r
1276                                 AssertEquals("Bad SetValue", \r
1277                                              c1[i,j,k], c2[i,j,k]);\r
1278                                 }\r
1279                         }\r
1280                 }\r
1281         }\r
1282         public void TestSetValueN() {\r
1283                 {\r
1284                         bool errorThrown = false;\r
1285                         try {\r
1286                                 char[] c = new Char[2];\r
1287                                 c.SetValue("buh", null);\r
1288                         } catch (ArgumentNullException) {\r
1289                                 errorThrown = true;\r
1290                         }\r
1291                         Assert("error not thrown", errorThrown);\r
1292                 }\r
1293                 {\r
1294                         bool errorThrown = false;\r
1295                         try {\r
1296                                 char[] c = new Char[2];\r
1297                                 int[] coords = {1, 1};\r
1298                                 c.SetValue("buh", coords);\r
1299                         } catch (ArgumentException) {\r
1300                                 errorThrown = true;\r
1301                         }\r
1302                         Assert("error not thrown", errorThrown);\r
1303                 }\r
1304                 {\r
1305                         bool errorThrown = false;\r
1306                         try {\r
1307                                 char[,] c = new Char[2,2];\r
1308                                 int[] coords = {-1, 1};\r
1309                                 c.SetValue("buh", coords);\r
1310                         } catch (IndexOutOfRangeException) {\r
1311                                 errorThrown = true;\r
1312                         }\r
1313                         Assert("error not thrown", errorThrown);\r
1314                 }\r
1315                 {\r
1316                         bool errorThrown = false;\r
1317                         try {\r
1318                                 char[,] c = new Char[2,2];\r
1319                                 int[] coords = {4, 1};\r
1320                                 c.SetValue("buh", coords);\r
1321                         } catch (IndexOutOfRangeException) {\r
1322                                 errorThrown = true;\r
1323                         }\r
1324                         Assert("error not thrown", errorThrown);\r
1325                 }\r
1326 \r
1327                 char[,] c1 = new Char[4,6];\r
1328                 char[,] c2 = new Char[4,6];\r
1329                 for (int i = 0; i < 24; i++) {\r
1330                         int first = i / 6;\r
1331                         int second = i % 6;\r
1332                         c1[first,second] = (char)(((int)'a')+i);\r
1333                         int[] coords = {first, second};\r
1334                         c2.SetValue(c1[first,second], coords);\r
1335                 }\r
1336                 for (int i = 0; i < c1.GetLength(0); i++) {\r
1337                         for (int j = 0; j < c1.GetLength(1); j++) {\r
1338                                 AssertEquals("Bad SetValue", \r
1339                                              c1[i,j], c2[i,j]);\r
1340                         }\r
1341                 }\r
1342         }\r
1343 \r
1344         public void TestSort() {\r
1345                 {\r
1346                         bool errorThrown = false;\r
1347                         try {\r
1348                                 Array.Sort(null);\r
1349                         } catch (ArgumentNullException) {\r
1350                                 errorThrown = true;\r
1351                         }\r
1352                         Assert("error not thrown 1", errorThrown);\r
1353                 }\r
1354                 {\r
1355                         bool errorThrown = false;\r
1356                         try {\r
1357                                 Array.Sort(null, 0, 1);\r
1358                         } catch (ArgumentNullException) {\r
1359                                 errorThrown = true;\r
1360                         }\r
1361                         Assert("error not thrown 2", errorThrown);\r
1362                 }\r
1363                 {\r
1364                         bool errorThrown = false;\r
1365                         try {\r
1366                                 char[] c1 = new Char[2];\r
1367                                 Array.Sort(null, c1);\r
1368                         } catch (ArgumentNullException) {\r
1369                                 errorThrown = true;\r
1370                         }\r
1371                         Assert("error not thrown 5", errorThrown);\r
1372                 }\r
1373                 {\r
1374                         bool errorThrown = false;\r
1375                         try {\r
1376                                 char[] c1 = new Char[2];\r
1377                                 Array.Sort(null, c1, 0, 1);\r
1378                         } catch (ArgumentNullException) {\r
1379                                 errorThrown = true;\r
1380                         }\r
1381                         Assert("error not thrown 6", errorThrown);\r
1382                 }\r
1383 \r
1384                 // note: null second array => just sort first array\r
1385                 char[] starter = {'d', 'b', 'f', 'e', 'a', 'c'};\r
1386                 int[] starter1 = {1,2,3,4,5,6};\r
1387                 {\r
1388                         char[] c1 = (char[])starter.Clone();\r
1389                         Array.Sort(c1);\r
1390                         AssertEquals("Basic sort problem", 'a', c1[0]);\r
1391                         AssertEquals("Basic sort problem", 'b', c1[1]);\r
1392                         AssertEquals("Basic sort problem", 'c', c1[2]);\r
1393                         AssertEquals("Basic sort problem", 'd', c1[3]);\r
1394                         AssertEquals("Basic sort problem", 'e', c1[4]);\r
1395                         AssertEquals("Basic sort problem", 'f', c1[5]);\r
1396                 }\r
1397                 {\r
1398                         char[] c1 = (char[])starter.Clone();\r
1399                         int[] i1 = (int[])starter1.Clone();\r
1400                         Array.Sort(c1, i1);\r
1401                         AssertEquals("Keyed sort problem", 'a', c1[0]);\r
1402                         AssertEquals("Keyed sort problem", 'b', c1[1]);\r
1403                         AssertEquals("Keyed sort problem", 'c', c1[2]);\r
1404                         AssertEquals("Keyed sort problem", 'd', c1[3]);\r
1405                         AssertEquals("Keyed sort problem", 'e', c1[4]);\r
1406                         AssertEquals("Keyed sort problem", 'f', c1[5]);\r
1407                         AssertEquals("Keyed sort problem", 5, i1[0]);\r
1408                         AssertEquals("Keyed sort problem", 2, i1[1]);\r
1409                         AssertEquals("Keyed sort problem", 6, i1[2]);\r
1410                         AssertEquals("Keyed sort problem", 1, i1[3]);\r
1411                         AssertEquals("Keyed sort problem", 4, i1[4]);\r
1412                         AssertEquals("Keyed sort problem", 3, i1[5]);\r
1413                 }\r
1414                 {\r
1415                         char[] c1 = (char[])starter.Clone();\r
1416                         Array.Sort(c1, 1, 4);\r
1417                         AssertEquals("Basic sort chunk problem", 'd', c1[0]);\r
1418                         AssertEquals("Basic sort chunk problem", 'a', c1[1]);\r
1419                         AssertEquals("Basic sort chunk problem", 'b', c1[2]);\r
1420                         AssertEquals("Basic sort chunk problem", 'e', c1[3]);\r
1421                         AssertEquals("Basic sort chunk problem", 'f', c1[4]);\r
1422                         AssertEquals("Basic sort chunk problem", 'c', c1[5]);\r
1423                 }\r
1424                 {\r
1425                         char[] c1 = (char[])starter.Clone();\r
1426                         int[] i1 = (int[])starter1.Clone();\r
1427                         Array.Sort(c1, i1, 1, 4);\r
1428                         AssertEquals("Keyed sort chunk problem", 'd', c1[0]);\r
1429                         AssertEquals("Keyed sort chunk problem", 'a', c1[1]);\r
1430                         AssertEquals("Keyed sort chunk problem", 'b', c1[2]);\r
1431                         AssertEquals("Keyed sort chunk problem", 'e', c1[3]);\r
1432                         AssertEquals("Keyed sort chunk problem", 'f', c1[4]);\r
1433                         AssertEquals("Keyed sort chunk problem", 'c', c1[5]);\r
1434                         AssertEquals("Keyed sort chunk problem", 1, i1[0]);\r
1435                         AssertEquals("Keyed sort chunk problem", 5, i1[1]);\r
1436                         AssertEquals("Keyed sort chunk problem", 2, i1[2]);\r
1437                         AssertEquals("Keyed sort chunk problem", 4, i1[3]);\r
1438                         AssertEquals("Keyed sort chunk problem", 3, i1[4]);\r
1439                         AssertEquals("Keyed sort chunk problem", 6, i1[5]);\r
1440                 }\r
1441         }\r
1442 \r
1443         // TODO - TestSort passed-in IComparable versions\r
1444 \r
1445 }\r
1446 \r
1447 }\r