1 // ArrayTest.cs - NUnit Test Cases for the System.Array class
\r
3 // David Brandt (bucky@keystreams.com)
\r
5 // (C) Ximian, Inc. http://www.ximian.com
\r
8 using NUnit.Framework;
\r
10 using System.Collections;
\r
11 using System.Globalization;
\r
13 namespace MonoTests.System
\r
16 public class ArrayTest : TestCase
\r
18 public ArrayTest() : base ("MonoTests.System.ArrayTest testsuite") {}
\r
19 public ArrayTest(string name) : base(name) {}
\r
21 protected override void SetUp()
\r
25 protected override void TearDown()
\r
29 public static ITest Suite {
\r
31 return new TestSuite(typeof(ArrayTest));
\r
35 public void TestIsFixedSize() {
\r
37 Assert("All arrays are fixed", a1.IsFixedSize);
\r
40 public void TestIsReadOnly() {
\r
42 Assert("No array is readonly", !a1.IsReadOnly);
\r
45 public void TestIsSynchronized() {
\r
47 Assert("No array is synchronized", !a1.IsSynchronized);
\r
50 public void TestLength() {
\r
53 AssertEquals("Zero length array", 0, a1.Length);
\r
57 AssertEquals("One-length array", 1, a1.Length);
\r
60 char[] a1 = {'c', 'c'};
\r
61 AssertEquals("Two-length array", 2, a1.Length);
\r
65 public void TestRank() {
\r
66 char[] a1 = { 'c', 'd', 'e' };
\r
67 AssertEquals("Rank one", 1, a1.Rank);
\r
69 char[,] a2 = new Char[3,3];
\r
70 AssertEquals("Rank two", 2, a2.Rank);
\r
72 char[,,] a3 = new Char[3,3,3];
\r
73 AssertEquals("Rank three", 3, a3.Rank);
\r
76 public void TestBinarySearch1() {
\r
77 bool errorThrown = false;
\r
79 Array.BinarySearch(null, "blue");
\r
80 } catch (ArgumentNullException) {
\r
83 Assert("#B01", errorThrown);
\r
84 errorThrown = false;
\r
86 char[,] c1 = new Char[2,2];
\r
87 Array.BinarySearch(c1, "needle");
\r
88 } catch (RankException) {
\r
91 Assert("#B02", errorThrown);
\r
94 char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
\r
96 Array.BinarySearch(arr, 'c') >= 3);
\r
98 Array.BinarySearch(arr, 'c') < 6);
\r
101 char[] arr = {'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
\r
102 AssertEquals("#B07",
\r
103 -4, Array.BinarySearch(arr, 'c'));
\r
106 char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
\r
107 AssertEquals("#B08",
\r
108 -9, Array.BinarySearch(arr, 'e'));
\r
111 public void TestBinarySearch2() {
\r
112 bool errorThrown = false;
\r
114 Array.BinarySearch(null, 0, 1, "blue");
\r
115 } catch (ArgumentNullException) {
\r
116 errorThrown = true;
\r
118 Assert("#B20", errorThrown);
\r
119 errorThrown = false;
\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
126 Assert("#B21", errorThrown);
\r
127 errorThrown = false;
\r
130 Array.BinarySearch(c1, -1, 1, 'a');
\r
131 } catch (ArgumentOutOfRangeException) {
\r
132 errorThrown = true;
\r
134 Assert("#B22", errorThrown);
\r
135 errorThrown = false;
\r
138 Array.BinarySearch(c1, 0, -1, 'a');
\r
139 } catch (ArgumentOutOfRangeException) {
\r
140 errorThrown = true;
\r
142 Assert("#B23", errorThrown);
\r
143 errorThrown = false;
\r
146 Array.BinarySearch(c1, 0, 4, 'a');
\r
147 } catch (ArgumentException) {
\r
148 errorThrown = true;
\r
150 Assert("#B24", errorThrown);
\r
153 char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
\r
155 Array.BinarySearch(arr, 2, 8, 'c') >= 5);
\r
157 Array.BinarySearch(arr, 2, 8, 'c') < 8);
\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
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
171 // TODO - testBinarySearch with explicit IComparer args
\r
173 public void TestClear() {
\r
174 bool errorThrown = false;
\r
176 Array.Clear(null, 0, 1);
\r
177 } catch (ArgumentNullException) {
\r
178 errorThrown = true;
\r
180 Assert("#C01", errorThrown);
\r
182 int[] i1 = { 1, 2, 3, 4 };
\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
190 Array.Clear(i1, 3, 1);
\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
198 Array.Clear(i1, 1, 1);
\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
206 Array.Clear(i1, 1, 3);
\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
215 string[] s1 = { "red", "green", "blue" };
\r
216 Array.Clear(s1, 0, 3);
\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
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
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
242 AssertEquals("#D07", d1[0], d2[0]);
\r
245 public void TestCopy() {
\r
247 bool errorThrown = false;
\r
250 Array.Copy(c1, null, 1);
\r
251 } catch (ArgumentNullException) {
\r
252 errorThrown = true;
\r
254 Assert("#E01", errorThrown);
\r
257 bool errorThrown = false;
\r
260 Array.Copy(null, c1, 1);
\r
261 } catch (ArgumentNullException) {
\r
262 errorThrown = true;
\r
264 Assert("#E02", errorThrown);
\r
267 bool errorThrown = false;
\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
275 Assert("#E03", errorThrown);
\r
278 bool errorThrown = false;
\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
286 Assert("#E04", errorThrown);
\r
289 bool errorThrown = false;
\r
291 Char[] c1 = new Char[1];
\r
292 Object[] o1 = new Object[1];
\r
294 Array.Copy(o1, c1, 1);
\r
295 } catch (InvalidCastException) {
\r
296 errorThrown = true;
\r
298 Assert("#E05", errorThrown);
\r
301 bool errorThrown = false;
\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
309 Assert("#E06", errorThrown);
\r
312 bool errorThrown = false;
\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
320 Assert("#E07", errorThrown);
\r
323 bool errorThrown = false;
\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
331 Assert("#E08", errorThrown);
\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
341 Array.Clear(copy, 0, copy.Length);
\r
342 for (int i = 0; i < orig.Length; i++) {
\r
343 AssertEquals("#E10(" + i + ")",
\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
352 public void TestCopy2() {
\r
354 bool errorThrown = false;
\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
362 Assert("#E31", errorThrown);
\r
365 bool errorThrown = false;
\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
373 Assert("#E32", errorThrown);
\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
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
392 public void TestCopyTo() {
\r
394 bool errorThrown = false;
\r
396 Char[] c1 = new Char[2];
\r
397 c1.CopyTo(null, 2);
\r
398 } catch (ArgumentNullException) {
\r
399 errorThrown = true;
\r
401 Assert("#E61", errorThrown);
\r
404 bool errorThrown = false;
\r
406 Char[] c1 = new Char[2];
\r
407 Char[,] c2 = new Char[2,2];
\r
409 } catch (ArgumentException) {
\r
410 errorThrown = true;
\r
412 Assert("#E62", errorThrown);
\r
415 bool errorThrown = false;
\r
417 Char[,] c1 = new Char[2,2];
\r
418 Char[] c2 = new Char[2];
\r
420 } catch (RankException) {
\r
421 errorThrown = true;
\r
423 Assert("#E63", errorThrown);
\r
426 bool errorThrown = false;
\r
428 Char[,] c1 = new Char[2,2];
\r
429 Char[] c2 = new Char[2];
\r
431 } catch (RankException) {
\r
432 errorThrown = true;
\r
434 Assert("#E64", errorThrown);
\r
437 bool errorThrown = false;
\r
439 Char[] c1 = new Char[2];
\r
440 Char[] c2 = new Char[2];
\r
442 } catch (ArgumentOutOfRangeException) {
\r
443 errorThrown = true;
\r
445 Assert("#E65", errorThrown);
\r
448 bool errorThrown = false;
\r
450 Char[] c1 = new Char[2];
\r
451 Char[] c2 = new Char[2];
\r
453 } catch (ArgumentException) {
\r
454 errorThrown = true;
\r
456 Assert("#E66", errorThrown);
\r
459 bool errorThrown = false;
\r
461 Char[] c1 = new Char[2];
\r
462 Char[] c2 = new Char[2];
\r
464 } catch (ArgumentException) {
\r
465 errorThrown = true;
\r
467 Assert("#E67", errorThrown);
\r
470 bool errorThrown = false;
\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
479 } catch (ArrayTypeMismatchException) {
\r
480 errorThrown = true;
\r
482 Assert("#E68", errorThrown);
\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
501 // The following is valid and must not throw an exception.
\r
502 bool errorThrown = false;
\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
510 Assert("#E79", !errorThrown);
\r
514 public void TestCreateInstance() {
\r
516 bool errorThrown = false;
\r
518 Array.CreateInstance(null, 12);
\r
519 } catch (ArgumentNullException) {
\r
520 errorThrown = true;
\r
522 Assert("#F01", errorThrown);
\r
525 bool errorThrown = false;
\r
527 Array.CreateInstance(Type.GetType("System.Char"), -3);
\r
528 } catch (ArgumentOutOfRangeException) {
\r
529 errorThrown = true;
\r
531 Assert("#F02", errorThrown);
\r
534 bool errorThrown = false;
\r
536 Array.CreateInstance(Type.GetType("System.Char"), null);
\r
537 } catch (ArgumentNullException) {
\r
538 errorThrown = true;
\r
540 Assert("#F03", errorThrown);
\r
543 bool errorThrown = false;
\r
545 Array.CreateInstance(Type.GetType("System.Char"), null, null);
\r
546 } catch (ArgumentNullException) {
\r
547 errorThrown = true;
\r
549 Assert("#F04", errorThrown);
\r
552 bool errorThrown = false;
\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
559 Assert("#F05", errorThrown);
\r
562 bool errorThrown = false;
\r
564 int[] lengths = new int [1];
\r
565 int[] bounds = new int [2];
\r
567 // Array.CreateInstance(Type.GetType("System.Char"), lengths, bounds);
\r
568 errorThrown = true;
\r
569 } catch (ArgumentException) {
\r
570 errorThrown = true;
\r
572 Assert("#F06", errorThrown);
\r
575 char[] c1 = (char[])Array.CreateInstance(Type.GetType("System.Char"), 12);
\r
576 AssertEquals("#F07", 12, c1.Length);
\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
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
589 AssertEquals("#F10", 3, array.Length);
\r
590 AssertEquals("#F11", 5, array.GetLowerBound(0));
\r
591 AssertEquals("#F12", 7, array.GetUpperBound(0));
\r
593 src.CopyTo (array, 5);
\r
595 for (int i = 0; i < src.Length; i++)
\r
596 AssertEquals("#F13(" + i + ")", src[i], array.GetValue(i+5));
\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
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
617 Assert("#G11", en.MoveNext ());
\r
618 AssertEquals ("#G12", "this", en.Current);
\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
626 public void TestGetEnumeratorMultipleDimension() {
\r
627 String[,] s1 = {{"this", "is"}, {"a", "test"}};
\r
628 IEnumerator en = s1.GetEnumerator ();
\r
629 AssertNotNull ("#AA01", en);
\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
642 Assert("#AA11", en.MoveNext ());
\r
643 AssertEquals ("#AA12", "this", en.Current);
\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
652 public void TestGetEnumeratorNonZeroLowerBounds() {
\r
653 int[] myLengthsArray = new int[2] { 3, 5 };
\r
654 int[] myBoundsArray = new int[2] { 2, 3 };
\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
662 IEnumerator en = myArray.GetEnumerator ();
\r
663 AssertNotNull ("#AB01", en);
\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
671 // then check the last element's value
\r
672 string lastElement;
\r
674 lastElement = (string)en.Current;
\r
675 } while (en.MoveNext());
\r
676 AssertEquals ("#AB06", "47", lastElement);
\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
683 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
\r
685 ((IList)myArray).Add ("can not");
\r
686 Fail ("IList.Add should throw");
\r
688 catch (NotSupportedException) {
\r
691 catch (Exception) {
\r
692 Fail ("IList.Add threw wrong exception type");
\r
695 Fail("IList.Add shouldn't get this far");
\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
702 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
\r
704 ((IList)myArray).Insert (0, "can not");
\r
705 Fail ("IList.Insert should throw");
\r
707 catch (NotSupportedException) {
\r
710 catch (Exception) {
\r
711 Fail ("IList.Insert threw wrong exception type");
\r
714 Fail("IList.Insert shouldn't get this far");
\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
721 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
\r
723 ((IList)myArray).Remove ("can not");
\r
724 Fail ("IList.Remove should throw");
\r
726 catch (NotSupportedException) {
\r
729 catch (Exception) {
\r
730 Fail ("IList.Remove threw wrong exception type");
\r
733 Fail("IList.Remove shouldn't get this far");
\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
740 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
\r
742 ((IList)myArray).RemoveAt (0);
\r
743 Fail ("IList.RemoveAt should throw");
\r
745 catch (NotSupportedException) {
\r
748 catch (Exception) {
\r
749 Fail ("IList.RemoveAt threw wrong exception type");
\r
752 Fail("IList.RemoveAt shouldn't get this far");
\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
759 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
\r
762 bool b = ((IList)myArray).Contains ("23");
\r
763 Fail("IList.Contains should throw with multi-dimensional arrays");
\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
771 // and one that is definately not there
\r
772 Assert("AC03", !((IList)iArr).Contains (42));
\r
776 Fail("Should not get here");
\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
783 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
\r
786 bool b = ((IList)myArray).Contains ("23");
\r
787 Fail("IList.Contains should throw with multi-dimensional arrays");
\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
795 // and one that is definately not there
\r
796 AssertEquals("AD03", -1, ((IList)iArr).IndexOf (42));
\r
798 catch (Exception) {
\r
799 Fail("Should not get here");
\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
811 public void TestGetLength() {
\r
813 bool errorThrown = false;
\r
815 char[] c1 = {'a', 'b', 'c'};
\r
817 } catch (IndexOutOfRangeException) {
\r
818 errorThrown = true;
\r
820 Assert("#H01", errorThrown);
\r
823 bool errorThrown = false;
\r
825 char[] c1 = {'a', 'b', 'c'};
\r
827 } catch (IndexOutOfRangeException) {
\r
828 errorThrown = true;
\r
830 Assert("#H02", errorThrown);
\r
833 char[] c2 = new Char[5];
\r
834 AssertEquals("#H03",
\r
835 5, c2.GetLength(0));
\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
844 public void TestGetLowerBound() {
\r
846 bool errorThrown = false;
\r
848 char[] c = {'a', 'b', 'c'};
\r
849 c.GetLowerBound(-1);
\r
850 } catch (IndexOutOfRangeException) {
\r
851 errorThrown = true;
\r
853 Assert("#H31", errorThrown);
\r
856 bool errorThrown = false;
\r
858 char[] c = {'a', 'b', 'c'};
\r
859 c.GetLowerBound(1);
\r
860 } catch (IndexOutOfRangeException) {
\r
861 errorThrown = true;
\r
863 Assert("#H32", errorThrown);
\r
866 char[] c1 = new Char[5];
\r
867 AssertEquals("#H33",
\r
868 0, c1.GetLowerBound(0));
\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
877 public void TestGetUpperBound() {
\r
879 bool errorThrown = false;
\r
881 char[] c = {'a', 'b', 'c'};
\r
882 c.GetUpperBound(-1);
\r
883 } catch (IndexOutOfRangeException) {
\r
884 errorThrown = true;
\r
886 Assert("#H61", errorThrown);
\r
889 bool errorThrown = false;
\r
891 char[] c = {'a', 'b', 'c'};
\r
892 c.GetUpperBound(1);
\r
893 } catch (IndexOutOfRangeException) {
\r
894 errorThrown = true;
\r
896 Assert("#H62", errorThrown);
\r
899 char[] c1 = new Char[5];
\r
900 AssertEquals("#H63",
\r
901 4, c1.GetUpperBound(0));
\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
910 public void TestGetValue1() {
\r
912 bool errorThrown = false;
\r
914 char[,] c = new Char[2,2];
\r
916 } catch (ArgumentException) {
\r
917 errorThrown = true;
\r
919 Assert("#I01", errorThrown);
\r
922 bool errorThrown = false;
\r
924 char[] c = {'a', 'b', 'c'};
\r
926 } catch (IndexOutOfRangeException) {
\r
927 errorThrown = true;
\r
929 Assert("#I02", errorThrown);
\r
932 bool errorThrown = false;
\r
934 char[] c = {'a', 'b', 'c'};
\r
936 } catch (IndexOutOfRangeException) {
\r
937 errorThrown = true;
\r
939 Assert("#I03", errorThrown);
\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
947 public void TestGetValue2() {
\r
949 bool errorThrown = false;
\r
951 char[] c = new Char[2];
\r
953 } catch (ArgumentException) {
\r
954 errorThrown = true;
\r
956 Assert("#I21", errorThrown);
\r
959 bool errorThrown = false;
\r
961 char[,] c = new Char[2,2];
\r
963 } catch (IndexOutOfRangeException) {
\r
964 errorThrown = true;
\r
966 Assert("#I22", errorThrown);
\r
969 bool errorThrown = false;
\r
971 char[,] c = new Char[2,2];
\r
973 } catch (IndexOutOfRangeException) {
\r
974 errorThrown = true;
\r
976 Assert("#I23", errorThrown);
\r
979 char[,] c1 = new Char[4,6];
\r
980 for (int i = 0; i < 24; i++) {
\r
982 int second = i % 6;
\r
983 c1[first,second] = (char)(((int)'a')+i);
\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
992 public void TestGetValue3() {
\r
994 bool errorThrown = false;
\r
996 char[] c = new Char[2];
\r
998 } catch (ArgumentException) {
\r
999 errorThrown = true;
\r
1001 Assert("#I41", errorThrown);
\r
1004 bool errorThrown = false;
\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
1011 Assert("#I42", errorThrown);
\r
1014 bool errorThrown = false;
\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
1021 Assert("#I43", errorThrown);
\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
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
1041 public void TestGetValueN() {
\r
1043 bool errorThrown = false;
\r
1045 char[] c = new Char[2];
\r
1047 } catch (ArgumentNullException) {
\r
1048 errorThrown = true;
\r
1050 Assert("#I61", errorThrown);
\r
1053 bool errorThrown = false;
\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
1061 Assert("#I62", errorThrown);
\r
1064 bool errorThrown = false;
\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
1072 Assert("#I63", errorThrown);
\r
1075 bool errorThrown = false;
\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
1083 Assert("#I64", errorThrown);
\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
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
1101 public void TestIndexOf1() {
\r
1103 bool errorThrown = false;
\r
1105 Array.IndexOf(null, "huh?");
\r
1106 } catch (ArgumentNullException) {
\r
1107 errorThrown = true;
\r
1109 Assert("#J01", errorThrown);
\r
1112 bool errorThrown = false;
\r
1114 char[,] c = new Char[2,2];
\r
1115 Array.IndexOf(c, "huh?");
\r
1116 } catch (RankException) {
\r
1117 errorThrown = true;
\r
1119 Assert("#J02", errorThrown);
\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
1128 public void TestIndexOf2() {
\r
1130 bool errorThrown = false;
\r
1132 Array.IndexOf(null, "huh?", 0);
\r
1133 } catch (ArgumentNullException) {
\r
1134 errorThrown = true;
\r
1136 Assert("#J21", errorThrown);
\r
1139 bool errorThrown = false;
\r
1141 char[,] c = new Char[2,2];
\r
1142 Array.IndexOf(c, "huh?", 0);
\r
1143 } catch (RankException) {
\r
1144 errorThrown = true;
\r
1146 Assert("#J22", errorThrown);
\r
1149 bool errorThrown = false;
\r
1151 char[] c = new Char[2];
\r
1152 Array.IndexOf(c, "huh?", 3);
\r
1153 } catch (ArgumentOutOfRangeException) {
\r
1154 errorThrown = true;
\r
1156 Assert("#J23", errorThrown);
\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
1166 public void TestIndexOf3() {
\r
1168 bool errorThrown = false;
\r
1170 Array.IndexOf(null, "huh?", 0, 1);
\r
1171 } catch (ArgumentNullException) {
\r
1172 errorThrown = true;
\r
1174 Assert("#J41", errorThrown);
\r
1177 bool errorThrown = false;
\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
1184 Assert("#J42", errorThrown);
\r
1187 bool errorThrown = false;
\r
1189 char[] c = new Char[2];
\r
1190 Array.IndexOf(c, "huh?", 3, 1);
\r
1191 } catch (ArgumentOutOfRangeException) {
\r
1192 errorThrown = true;
\r
1194 Assert("#J43", errorThrown);
\r
1197 bool errorThrown = false;
\r
1199 char[] c = new Char[2];
\r
1200 Array.IndexOf(c, "huh?", 0, 5);
\r
1201 } catch (ArgumentOutOfRangeException) {
\r
1202 errorThrown = true;
\r
1204 Assert("#J44", errorThrown);
\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
1216 public void TestLastIndexOf1() {
\r
1218 bool errorThrown = false;
\r
1220 Array.LastIndexOf(null, "huh?");
\r
1221 } catch (ArgumentNullException) {
\r
1222 errorThrown = true;
\r
1224 Assert("#K01", errorThrown);
\r
1227 bool errorThrown = false;
\r
1229 char[,] c = new Char[2,2];
\r
1230 Array.LastIndexOf(c, "huh?");
\r
1231 } catch (RankException) {
\r
1232 errorThrown = true;
\r
1234 Assert("#K02", errorThrown);
\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
1244 public void TestLastIndexOf2() {
\r
1246 bool errorThrown = false;
\r
1248 Array.LastIndexOf(null, "huh?", 0);
\r
1249 } catch (ArgumentNullException) {
\r
1250 errorThrown = true;
\r
1252 Assert("#K21", errorThrown);
\r
1255 bool errorThrown = false;
\r
1257 char[,] c = new Char[2,2];
\r
1258 Array.LastIndexOf(c, "huh?", 0);
\r
1259 } catch (RankException) {
\r
1260 errorThrown = true;
\r
1262 Assert("#K22", errorThrown);
\r
1265 bool errorThrown = false;
\r
1267 char[] c = new Char[2];
\r
1268 Array.LastIndexOf(c, "huh?", 3);
\r
1269 } catch (ArgumentOutOfRangeException) {
\r
1270 errorThrown = true;
\r
1272 Assert("#K23", errorThrown);
\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
1282 public void TestLastIndexOf3() {
\r
1284 bool errorThrown = false;
\r
1286 Array.LastIndexOf(null, "huh?", 0, 1);
\r
1287 } catch (ArgumentNullException) {
\r
1288 errorThrown = true;
\r
1290 Assert("#K41", errorThrown);
\r
1293 bool errorThrown = false;
\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
1300 Assert("#K42", errorThrown);
\r
1303 bool errorThrown = false;
\r
1305 char[] c = new Char[2];
\r
1306 Array.LastIndexOf(c, "huh?", 3, 1);
\r
1307 } catch (ArgumentOutOfRangeException) {
\r
1308 errorThrown = true;
\r
1310 Assert("#K43", errorThrown);
\r
1313 bool errorThrown = false;
\r
1315 char[] c = new Char[2];
\r
1316 Array.LastIndexOf(c, "huh?", 0, 5);
\r
1317 } catch (ArgumentOutOfRangeException) {
\r
1318 errorThrown = true;
\r
1320 Assert("#K44", errorThrown);
\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
1338 public void TestReverse() {
\r
1340 bool errorThrown = false;
\r
1342 Array.Reverse(null);
\r
1343 } catch (ArgumentNullException) {
\r
1344 errorThrown = true;
\r
1346 Assert("#L01", errorThrown);
\r
1349 bool errorThrown = false;
\r
1351 char[,] c = new Char[2,2];
\r
1353 } catch (RankException) {
\r
1354 errorThrown = true;
\r
1356 Assert("#L02", errorThrown);
\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
1367 bool errorThrown = false;
\r
1369 Array.Reverse(null, 0, 0);
\r
1370 } catch (ArgumentNullException) {
\r
1371 errorThrown = true;
\r
1373 Assert("#L07", errorThrown);
\r
1376 bool errorThrown = false;
\r
1378 char[,] c = new Char[2,2];
\r
1379 Array.Reverse(c, 0, 0);
\r
1380 } catch (RankException) {
\r
1381 errorThrown = true;
\r
1383 Assert("#L08", errorThrown);
\r
1386 //bool errorThrown = false;
\r
1388 // char[] c = new Char[2];
\r
1389 // Array.Reverse(c, 0, 3);
\r
1390 //} catch (ArgumentOutOfRangeException) {
\r
1391 // errorThrown = true;
\r
1393 //Assert("#L09", errorThrown);
\r
1396 //bool errorThrown = false;
\r
1398 // char[] c = new Char[2];
\r
1399 // Array.Reverse(c, 3, 0);
\r
1400 //} catch (ArgumentOutOfRangeException) {
\r
1401 // errorThrown = true;
\r
1403 //Assert("#L10", errorThrown);
\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
1414 public void TestSetValue1() {
\r
1416 bool errorThrown = false;
\r
1418 char[,] c = new Char[2,2];
\r
1419 c.SetValue("buh", 1);
\r
1420 } catch (ArgumentException) {
\r
1421 errorThrown = true;
\r
1423 Assert("#M01", errorThrown);
\r
1426 bool errorThrown = false;
\r
1428 char[] c = {'a', 'b', 'c'};
\r
1429 c.SetValue("buh", -1);
\r
1430 } catch (IndexOutOfRangeException) {
\r
1431 errorThrown = true;
\r
1433 Assert("#M02", errorThrown);
\r
1436 bool errorThrown = false;
\r
1438 char[] c = {'a', 'b', 'c'};
\r
1439 c.SetValue("buh", 4);
\r
1440 } catch (IndexOutOfRangeException) {
\r
1441 errorThrown = true;
\r
1443 Assert("#M03", errorThrown);
\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
1451 for (int i = 0; i < c1.Length; i++) {
\r
1452 AssertEquals("#M04(" + i + ")", c1[i], c2[i]);
\r
1455 int[] c3 = { 1, 2, 3 };
\r
1456 long[] c4 = new long [3];
\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
1464 Object[] c5 = new Object [3];
\r
1465 long[] c6 = new long [3];
\r
1467 c4.CopyTo (c5, 0);
\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
1474 public void TestSetValue2() {
\r
1476 bool errorThrown = false;
\r
1478 char[] c = new Char[2];
\r
1479 c.SetValue("buh", 1,1);
\r
1480 } catch (ArgumentException) {
\r
1481 errorThrown = true;
\r
1483 Assert("#M21", errorThrown);
\r
1486 bool errorThrown = false;
\r
1488 char[,] c = new Char[2,2];
\r
1489 c.SetValue("buh", -1, 1);
\r
1490 } catch (IndexOutOfRangeException) {
\r
1491 errorThrown = true;
\r
1493 Assert("#M22", errorThrown);
\r
1496 bool errorThrown = false;
\r
1498 char[,] c = new Char[2,2];
\r
1499 c.SetValue("buh", 4,1);
\r
1500 } catch (IndexOutOfRangeException) {
\r
1501 errorThrown = true;
\r
1503 Assert("#M23", errorThrown);
\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
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
1521 public void TestSetValue3() {
\r
1523 bool errorThrown = false;
\r
1525 char[] c = new Char[2];
\r
1526 c.SetValue("buh", 1,1,1);
\r
1527 } catch (ArgumentException) {
\r
1528 errorThrown = true;
\r
1530 Assert("#M41", errorThrown);
\r
1533 bool errorThrown = false;
\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
1540 Assert("#M42", errorThrown);
\r
1543 bool errorThrown = false;
\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
1550 Assert("#M43", errorThrown);
\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
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
1572 public void TestSetValueN() {
\r
1574 bool errorThrown = false;
\r
1576 char[] c = new Char[2];
\r
1577 c.SetValue("buh", null);
\r
1578 } catch (ArgumentNullException) {
\r
1579 errorThrown = true;
\r
1581 Assert("#M61", errorThrown);
\r
1584 bool errorThrown = false;
\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
1592 Assert("#M62", errorThrown);
\r
1595 bool errorThrown = false;
\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
1603 Assert("#M63", errorThrown);
\r
1606 bool errorThrown = false;
\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
1614 Assert("#M64", errorThrown);
\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
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
1634 public void TestSetValue4() {
\r
1636 int[] c1 = { 1, 2, 3 };
\r
1637 long[] c2 = new long [3];
\r
1639 for (int i = 0; i < c1.Length; i++)
\r
1640 c2.SetValue (c1 [i], i);
\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
1648 long[] c1 = { 1, 2, 3 };
\r
1649 int[] c2 = new int [3];
\r
1650 bool errorThrown = false;
\r
1652 c2.SetValue (c1 [0], 0);
\r
1653 } catch (ArgumentException) {
\r
1654 errorThrown = true;
\r
1656 Assert("#M83", errorThrown);
\r
1659 int[] c1 = { 1, 2, 3 };
\r
1660 Object[] c2 = new Object [3];
\r
1662 for (int i = 0; i < c1.Length; i++)
\r
1663 c2.SetValue (c1 [i], i);
\r
1665 for (int i = 0; i < c1.Length; i++)
\r
1666 AssertEquals ("#M84(" + i + ")", c1[i], Convert.ToInt32 (c2[i]));
\r
1669 Object[] c1 = new Object [3];
\r
1670 Object[] c2 = new Object [3];
\r
1671 c1[0] = new Object ();
\r
1673 for (int i = 0; i < c1.Length; i++)
\r
1674 c2.SetValue (c1 [i], i);
\r
1676 for (int i = 0; i < c1.Length; i++)
\r
1677 AssertEquals ("#M85(" + i + ")", c1[i], c2[i]);
\r
1680 Object[] c1 = new Object [3];
\r
1681 string[] c2 = new String [3];
\r
1682 string test = "hello";
\r
1685 c2.SetValue (c1 [0], 0);
\r
1686 AssertEquals ("#M86", c1[0], c2[0]);
\r
1687 AssertEquals ("#M87", "hello", c2[0]);
\r
1690 char[] c1 = { 'a', 'b', 'c' };
\r
1691 string[] c2 = new string [3];
\r
1692 bool errorThrown = false;
\r
1694 c2.SetValue (c1 [0], 0);
\r
1696 errorThrown = true;
\r
1697 } catch (InvalidCastException) {
\r
1698 errorThrown = true;
\r
1700 Assert("#M88", errorThrown);
\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
1707 c2.SetValue (c1 [0], 0);
\r
1709 errorThrown = true;
\r
1710 } catch (ArgumentException) {
\r
1711 errorThrown = true;
\r
1713 Assert("#M89", errorThrown);
\r
1737 Int64 v7 = -34523;
\r
1739 Single v9 = -4.8F;
\r
1740 UInt16 v10 = 24234;
\r
1741 UInt32 v11 = 235354;
\r
1742 UInt64 v12 = 234552;
\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
1748 Object[][] vt = { va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1 };
\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
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
1771 Object value = vt[j][i];
\r
1773 bool errorThrown = false;
\r
1775 array.SetValue (value, 0);
\r
1776 } catch (ArgumentException) {
\r
1777 errorThrown = true;
\r
1780 int ex_index = (i * types.Length) + j;
\r
1782 AssertEquals ("#M90(" + types [i] + "," + types [j] + ")",
\r
1783 errorThrown, arg_ex [ex_index] == 1);
\r
1787 for (int i = 0; i < types.Length; i++) {
\r
1788 String[] array = new String [2];
\r
1790 Object value = va1 [i];
\r
1792 bool errorThrown = false;
\r
1794 array.SetValue (value, 0);
\r
1795 } catch (InvalidCastException) {
\r
1796 errorThrown = true;
\r
1799 Assert ("#M91(" + types [i] + ")", errorThrown);
\r
1802 for (int i = 0; i < types.Length; i++) {
\r
1803 Array array = Array.CreateInstance (types [i], 2);
\r
1805 Object value = va2 [i];
\r
1807 bool errorThrown = false;
\r
1809 array.SetValue (value, 0);
\r
1810 } catch (InvalidCastException) {
\r
1811 errorThrown = true;
\r
1814 Assert ("#M92(" + types [i] + ")", errorThrown);
\r
1817 for (int i = 0; i < types.Length; i++) {
\r
1818 Array array = Array.CreateInstance (types [i], 2);
\r
1820 Object value = null;
\r
1822 bool errorThrown = false;
\r
1824 array.SetValue (value, 0);
\r
1825 } catch (InvalidCastException) {
\r
1826 errorThrown = true;
\r
1829 Assert ("#M93(" + types [i] + ")", !errorThrown);
\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
1839 source.SetValue (vt[j][i], 0);
\r
1840 source.SetValue (vt[j][i], 1);
\r
1842 bool errorThrown = false;
\r
1844 Array.Copy (source, array, 2);
\r
1845 } catch (ArrayTypeMismatchException) {
\r
1846 errorThrown = true;
\r
1849 int ex_index = (i * types.Length) + j;
\r
1851 AssertEquals ("#M94(" + types [i] + "," + types [j] + ")",
\r
1852 errorThrown, arg_ex [ex_index] == 1);
\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
1860 source.SetValue (va1 [i], 0);
\r
1861 source.SetValue (va1 [i], 1);
\r
1863 bool errorThrown = false;
\r
1865 Array.Copy (source, array, 2);
\r
1866 } catch (ArrayTypeMismatchException) {
\r
1867 errorThrown = true;
\r
1870 Assert ("#M95(" + types [i] + ")", errorThrown);
\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
1877 source.SetValue (va2 [i], 0);
\r
1878 source.SetValue (va2 [i], 1);
\r
1880 bool errorThrown = false;
\r
1882 Array.Copy (source, array, 2);
\r
1883 } catch (ArrayTypeMismatchException) {
\r
1884 errorThrown = true;
\r
1887 Assert ("#M96(" + types [i] + ")", errorThrown);
\r
1893 public void TestSort() {
\r
1895 bool errorThrown = false;
\r
1898 } catch (ArgumentNullException) {
\r
1899 errorThrown = true;
\r
1901 Assert("#N01", errorThrown);
\r
1904 bool errorThrown = false;
\r
1906 Array.Sort(null, 0, 1);
\r
1907 } catch (ArgumentNullException) {
\r
1908 errorThrown = true;
\r
1910 Assert("#N02", errorThrown);
\r
1913 bool errorThrown = false;
\r
1915 char[] c1 = new Char[2];
\r
1916 Array.Sort(null, c1);
\r
1917 } catch (ArgumentNullException) {
\r
1918 errorThrown = true;
\r
1920 Assert("#N03", errorThrown);
\r
1923 bool errorThrown = false;
\r
1925 char[] c1 = new Char[2];
\r
1926 Array.Sort(null, c1, 0, 1);
\r
1927 } catch (ArgumentNullException) {
\r
1928 errorThrown = true;
\r
1930 Assert("#N04", errorThrown);
\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
1937 char[] c1 = (char[])starter.Clone();
\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
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
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
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
1992 // TODO - TestSort passed-in IComparable versions
\r