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[] bad = {'d', 'a', 'd', 'a', 'c', 'a'};
\r
95 AssertEquals("#B03", -1, Array.BinarySearch(bad, 'c'));
\r
98 char[] bad = {'a', 'd', 'a', 'd', 'a', 'c', 'a'};
\r
99 AssertEquals("#B04", -2, Array.BinarySearch(bad, 'c'));
\r
102 char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
\r
104 Array.BinarySearch(arr, 'c') >= 3);
\r
106 Array.BinarySearch(arr, 'c') < 6);
\r
109 char[] arr = {'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
\r
110 AssertEquals("#B07",
\r
111 -4, Array.BinarySearch(arr, 'c'));
\r
114 char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
\r
115 AssertEquals("#B08",
\r
116 -9, Array.BinarySearch(arr, 'e'));
\r
119 public void TestBinarySearch2() {
\r
120 bool errorThrown = false;
\r
122 Array.BinarySearch(null, 0, 1, "blue");
\r
123 } catch (ArgumentNullException) {
\r
124 errorThrown = true;
\r
126 Assert("#B20", errorThrown);
\r
127 errorThrown = false;
\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
134 Assert("#B21", errorThrown);
\r
135 errorThrown = false;
\r
138 Array.BinarySearch(c1, -1, 1, 'a');
\r
139 } catch (ArgumentOutOfRangeException) {
\r
140 errorThrown = true;
\r
142 Assert("#B22", errorThrown);
\r
143 errorThrown = false;
\r
146 Array.BinarySearch(c1, 0, -1, 'a');
\r
147 } catch (ArgumentOutOfRangeException) {
\r
148 errorThrown = true;
\r
150 Assert("#B23", errorThrown);
\r
151 errorThrown = false;
\r
154 Array.BinarySearch(c1, 0, 4, 'a');
\r
155 } catch (ArgumentException) {
\r
156 errorThrown = true;
\r
158 Assert("#B24", errorThrown);
\r
160 // FIXME - see commented-out tests in TestBinarySearch1, above
\r
163 char[] bad = {'z', 'z', 'd', 'a', 'd', 'a', 'c', 'a'};
\r
164 AssertEquals("#B25", -3, Array.BinarySearch(bad, 2, 6, 'c'));
\r
167 char[] bad = {'z', 'z', 'a', 'd', 'a', 'd', 'a', 'c', 'a'};
\r
168 AssertEquals("#B25", -4, Array.BinarySearch(bad, 2, 7, 'c'));
\r
171 char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
\r
173 Array.BinarySearch(arr, 2, 8, 'c') >= 5);
\r
175 Array.BinarySearch(arr, 2, 8, 'c') < 8);
\r
178 char[] arr = {'z', 'z', 'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
\r
179 AssertEquals("#B28",
\r
180 -6, Array.BinarySearch(arr, 2, 8, 'c'));
\r
183 char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
\r
184 AssertEquals("#B29",
\r
185 -11, Array.BinarySearch(arr, 2, 8, 'e'));
\r
189 // TODO - testBinarySearch with explicit IComparer args
\r
191 public void TestClear() {
\r
192 bool errorThrown = false;
\r
194 Array.Clear(null, 0, 1);
\r
195 } catch (ArgumentNullException) {
\r
196 errorThrown = true;
\r
198 Assert("#C01", errorThrown);
\r
200 int[] i1 = { 1, 2, 3, 4 };
\r
202 int[] compare = {1,2,3,4};
\r
203 AssertEquals("#C02", compare[0], i1[0]);
\r
204 AssertEquals("#C03", compare[1], i1[1]);
\r
205 AssertEquals("#C04", compare[2], i1[2]);
\r
206 AssertEquals("#C05", compare[3], i1[3]);
\r
208 Array.Clear(i1, 3, 1);
\r
210 int[] compare = {1,2,3,0};
\r
211 AssertEquals("#C06", compare[0], i1[0]);
\r
212 AssertEquals("#C07", compare[1], i1[1]);
\r
213 AssertEquals("#C08", compare[2], i1[2]);
\r
214 AssertEquals("#C09", compare[3], i1[3]);
\r
216 Array.Clear(i1, 1, 1);
\r
218 int[] compare = {1,0,3,0};
\r
219 AssertEquals("#C10", compare[0], i1[0]);
\r
220 AssertEquals("#C11", compare[1], i1[1]);
\r
221 AssertEquals("#C12", compare[2], i1[2]);
\r
222 AssertEquals("#C13", compare[3], i1[3]);
\r
224 Array.Clear(i1, 1, 3);
\r
226 int[] compare = {1,0,0,0};
\r
227 AssertEquals("#C14", compare[0], i1[0]);
\r
228 AssertEquals("#C15", compare[1], i1[1]);
\r
229 AssertEquals("#C16", compare[2], i1[2]);
\r
230 AssertEquals("#C17", compare[3], i1[3]);
\r
233 string[] s1 = { "red", "green", "blue" };
\r
234 Array.Clear(s1, 0, 3);
\r
236 string[] compare = {null, null, null};
\r
237 AssertEquals("#C18", compare[0], s1[0]);
\r
238 AssertEquals("#C19", compare[1], s1[1]);
\r
239 AssertEquals("#C20", compare[2], s1[2]);
\r
243 public void TestClone() {
\r
244 char[] c1 = {'a', 'b', 'c'};
\r
245 char[] c2 = (char[])c1.Clone();
\r
246 AssertEquals("#D01", c1[0], c2[0]);
\r
247 AssertEquals("#D02", c1[1], c2[1]);
\r
248 AssertEquals("#D03", c1[2], c2[2]);
\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("#D04", d1[0], d2[0]);
\r
256 AssertEquals("#D05", d1[1], d2[1]);
\r
257 AssertEquals("#D06", d1[2], d2[2]);
\r
260 AssertEquals("#D07", d1[0], d2[0]);
\r
263 public void TestCopy() {
\r
265 bool errorThrown = false;
\r
268 Array.Copy(c1, null, 1);
\r
269 } catch (ArgumentNullException) {
\r
270 errorThrown = true;
\r
272 Assert("#E01", errorThrown);
\r
275 bool errorThrown = false;
\r
278 Array.Copy(null, c1, 1);
\r
279 } catch (ArgumentNullException) {
\r
280 errorThrown = true;
\r
282 Assert("#E02", errorThrown);
\r
285 bool errorThrown = false;
\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
293 Assert("#E03", errorThrown);
\r
296 bool errorThrown = false;
\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
304 Assert("#E04", errorThrown);
\r
307 bool errorThrown = false;
\r
309 Char[] c1 = new Char[1];
\r
310 Object[] o1 = new Object[1];
\r
312 Array.Copy(o1, c1, 1);
\r
313 } catch (InvalidCastException) {
\r
314 errorThrown = true;
\r
315 } catch (ArrayTypeMismatchException) {
\r
316 // FIXME: Our implementation currently doesn't distinguish
\r
317 // between InvalidCastException and ArrayTypeMismatchException
\r
318 errorThrown = true;
\r
320 Assert("#E05", errorThrown);
\r
323 bool errorThrown = false;
\r
325 Char[] c1 = new Char[1];
\r
326 Char[] c2 = new Char[1];
\r
327 Array.Copy(c1, c2, -1);
\r
328 } catch (ArgumentOutOfRangeException) {
\r
329 errorThrown = true;
\r
331 Assert("#E06", errorThrown);
\r
334 bool errorThrown = false;
\r
336 Char[] c1 = new Char[1];
\r
337 Char[] c2 = new Char[2];
\r
338 Array.Copy(c1, c2, 2);
\r
339 } catch (ArgumentException) {
\r
340 errorThrown = true;
\r
342 Assert("#E07", errorThrown);
\r
345 bool errorThrown = false;
\r
347 Char[] c1 = new Char[1];
\r
348 Char[] c2 = new Char[2];
\r
349 Array.Copy(c2, c1, 2);
\r
350 } catch (ArgumentException) {
\r
351 errorThrown = true;
\r
353 Assert("#E08", errorThrown);
\r
356 char[] orig = {'a', 'b', 'd', 'a'};
\r
357 char[] copy = new Char[4];
\r
358 Array.Copy(orig, copy, 4);
\r
359 for (int i = 0; i < orig.Length; i++) {
\r
360 AssertEquals("#E09(" + i + ")",
\r
363 Array.Clear(copy, 0, copy.Length);
\r
364 for (int i = 0; i < orig.Length; i++) {
\r
365 AssertEquals("#E10(" + i + ")",
\r
368 Array.Copy(orig, copy, 2);
\r
369 AssertEquals("#E11", orig[0], copy[0]);
\r
370 AssertEquals("#E12", orig[1], copy[1]);
\r
371 Assert("#E13", orig[2] != copy[2]);
\r
372 Assert("#E14", orig[3] != copy[3]);
\r
374 public void TestCopy2() {
\r
376 bool errorThrown = false;
\r
378 Char[] c1 = new Char[2];
\r
379 Char[] c2 = new Char[2];
\r
380 Array.Copy(c2, 1, c1, 0, 2);
\r
381 } catch (ArgumentException) {
\r
382 errorThrown = true;
\r
384 Assert("#E31", errorThrown);
\r
387 bool errorThrown = false;
\r
389 Char[] c1 = new Char[2];
\r
390 Char[] c2 = new Char[2];
\r
391 Array.Copy(c2, 0, c1, 1, 2);
\r
392 } catch (ArgumentException) {
\r
393 errorThrown = true;
\r
395 Assert("#E32", errorThrown);
\r
398 char[] orig = {'a', 'b', 'd', 'a'};
\r
399 char[] copy = new Char[4];
\r
400 Array.Copy(orig, 1, copy, 1, 3);
\r
401 Assert("#E33", copy[0] != orig[0]);
\r
402 for (int i = 1; i < orig.Length; i++) {
\r
403 AssertEquals("#E34(" + i + ")",
\r
406 Array.Clear(copy, 0, copy.Length);
\r
407 Array.Copy(orig, 1, copy, 0, 2);
\r
408 AssertEquals("#E35", orig[1], copy[0]);
\r
409 AssertEquals("#E36", orig[2], copy[1]);
\r
410 Assert("#E37", copy[2] != orig[2]);
\r
411 Assert("#E38", copy[3] != orig[3]);
\r
414 public void TestCopyTo() {
\r
416 bool errorThrown = false;
\r
418 Char[] c1 = new Char[2];
\r
419 c1.CopyTo(null, 2);
\r
420 } catch (ArgumentNullException) {
\r
421 errorThrown = true;
\r
423 Assert("#E61", errorThrown);
\r
426 bool errorThrown = false;
\r
428 Char[] c1 = new Char[2];
\r
429 Char[,] c2 = new Char[2,2];
\r
431 } catch (ArgumentException) {
\r
432 errorThrown = true;
\r
434 Assert("#E62", errorThrown);
\r
437 bool errorThrown = false;
\r
439 Char[,] c1 = new Char[2,2];
\r
440 Char[] c2 = new Char[2];
\r
442 } catch (RankException) {
\r
443 errorThrown = true;
\r
445 Assert("#E63", errorThrown);
\r
448 bool errorThrown = false;
\r
450 Char[,] c1 = new Char[2,2];
\r
451 Char[] c2 = new Char[2];
\r
453 } catch (RankException) {
\r
454 errorThrown = true;
\r
456 Assert("#E64", errorThrown);
\r
459 bool errorThrown = false;
\r
461 Char[] c1 = new Char[2];
\r
462 Char[] c2 = new Char[2];
\r
464 } catch (ArgumentOutOfRangeException) {
\r
465 errorThrown = true;
\r
467 Assert("#E65", errorThrown);
\r
470 bool errorThrown = false;
\r
472 Char[] c1 = new Char[2];
\r
473 Char[] c2 = new Char[2];
\r
475 } catch (ArgumentException) {
\r
476 errorThrown = true;
\r
478 Assert("#E66", errorThrown);
\r
481 bool errorThrown = false;
\r
483 Char[] c1 = new Char[2];
\r
484 Char[] c2 = new Char[2];
\r
486 } catch (ArgumentException) {
\r
487 errorThrown = true;
\r
489 Assert("#E67", errorThrown);
\r
492 bool errorThrown = false;
\r
494 String[] c1 = new String[2];
\r
495 Char[] c2 = new Char[2];
\r
496 // FIXME: Our implementation doesn't throw an exception if
\r
497 // this is uninitialized.
\r
501 } catch (ArrayTypeMismatchException) {
\r
502 errorThrown = true;
\r
504 Assert("#E68", errorThrown);
\r
507 Char[] orig = {'a', 'b', 'c', 'd'};
\r
508 Char[] copy = new Char[10];
\r
509 Array.Clear(copy, 0, copy.Length);
\r
510 orig.CopyTo(copy, 3);
\r
511 AssertEquals("#E69", (char)0, copy[0]);
\r
512 AssertEquals("#E70", (char)0, copy[1]);
\r
513 AssertEquals("#E71", (char)0, copy[2]);
\r
514 AssertEquals("#E72", orig[0], copy[3]);
\r
515 AssertEquals("#E73", orig[1], copy[4]);
\r
516 AssertEquals("#E74", orig[2], copy[5]);
\r
517 AssertEquals("#E75", orig[3], copy[6]);
\r
518 AssertEquals("#E76", (char)0, copy[7]);
\r
519 AssertEquals("#E77", (char)0, copy[8]);
\r
520 AssertEquals("#E78", (char)0, copy[9]);
\r
523 // The following is valid and must not throw an exception.
\r
524 bool errorThrown = false;
\r
526 int[] src = new int [0];
\r
527 int[] dest = new int [0];
\r
528 src.CopyTo (dest, 0);
\r
529 } catch (ArgumentException) {
\r
530 errorThrown = true;
\r
532 Assert("#E79", !errorThrown);
\r
536 public void TestCreateInstance() {
\r
538 bool errorThrown = false;
\r
540 Array.CreateInstance(null, 12);
\r
541 } catch (ArgumentNullException) {
\r
542 errorThrown = true;
\r
544 Assert("#F01", errorThrown);
\r
547 bool errorThrown = false;
\r
549 Array.CreateInstance(Type.GetType("System.Char"), -3);
\r
550 } catch (ArgumentOutOfRangeException) {
\r
551 errorThrown = true;
\r
553 Assert("#F02", errorThrown);
\r
556 bool errorThrown = false;
\r
558 Array.CreateInstance(Type.GetType("System.Char"), null);
\r
559 } catch (ArgumentNullException) {
\r
560 errorThrown = true;
\r
562 Assert("#F03", errorThrown);
\r
565 bool errorThrown = false;
\r
567 Array.CreateInstance(Type.GetType("System.Char"), null, null);
\r
568 } catch (ArgumentNullException) {
\r
569 errorThrown = true;
\r
571 Assert("#F04", errorThrown);
\r
574 bool errorThrown = false;
\r
576 int[] lengths = new int [0];
\r
577 Array.CreateInstance(Type.GetType("System.Char"), lengths);
\r
578 } catch (ArgumentException) {
\r
579 errorThrown = true;
\r
581 Assert("#F05", errorThrown);
\r
584 bool errorThrown = false;
\r
586 int[] lengths = new int [1];
\r
587 int[] bounds = new int [2];
\r
589 // Array.CreateInstance(Type.GetType("System.Char"), lengths, bounds);
\r
590 errorThrown = true;
\r
591 } catch (ArgumentException) {
\r
592 errorThrown = true;
\r
594 Assert("#F06", errorThrown);
\r
597 char[] c1 = (char[])Array.CreateInstance(Type.GetType("System.Char"), 12);
\r
598 AssertEquals("#F07", 12, c1.Length);
\r
600 Array c2 = Array.CreateInstance(Type.GetType("System.Char"), 12, 5);
\r
601 AssertEquals("#F08", 2, c2.Rank);
\r
602 AssertEquals("#F09", 60, c2.Length);
\r
606 int[] lengths = { 3 };
\r
607 int[] bounds = { 5 };
\r
608 int[] src = { 512, 718, 912 };
\r
609 Array array = Array.CreateInstance(typeof(int), lengths, bounds);
\r
611 AssertEquals("#F10", 3, array.Length);
\r
612 AssertEquals("#F11", 5, array.GetLowerBound(0));
\r
613 AssertEquals("#F12", 7, array.GetUpperBound(0));
\r
615 src.CopyTo (array, 5);
\r
617 for (int i = 0; i < src.Length; i++)
\r
618 AssertEquals("#F13(" + i + ")", src[i], array.GetValue(i+5));
\r
623 public void TestGetEnumerator() {
\r
624 // FIXME: Not yet implemented
\r
626 String[] s1 = {"this", "is", "a", "test"};
\r
627 IEnumerator en = s1.GetEnumerator();
\r
628 AssertNotNull("#G01", en);
\r
630 for (int i = 0; i < s1.Length; i++) {
\r
632 AssertEquals("#G02", s1[i], en.Current);
\r
636 public void TestGetLength() {
\r
638 bool errorThrown = false;
\r
640 char[] c1 = {'a', 'b', 'c'};
\r
642 } catch (IndexOutOfRangeException) {
\r
643 errorThrown = true;
\r
645 Assert("#H01", errorThrown);
\r
648 bool errorThrown = false;
\r
650 char[] c1 = {'a', 'b', 'c'};
\r
652 } catch (IndexOutOfRangeException) {
\r
653 errorThrown = true;
\r
655 Assert("#H02", errorThrown);
\r
658 char[] c2 = new Char[5];
\r
659 AssertEquals("#H03",
\r
660 5, c2.GetLength(0));
\r
662 char[,] c3 = new Char[6,7];
\r
663 AssertEquals("#H04",
\r
664 6, c3.GetLength(0));
\r
665 AssertEquals("#H05",
\r
666 7, c3.GetLength(1));
\r
669 public void TestGetLowerBound() {
\r
671 bool errorThrown = false;
\r
673 char[] c = {'a', 'b', 'c'};
\r
674 c.GetLowerBound(-1);
\r
675 } catch (IndexOutOfRangeException) {
\r
676 errorThrown = true;
\r
678 Assert("#H31", errorThrown);
\r
681 bool errorThrown = false;
\r
683 char[] c = {'a', 'b', 'c'};
\r
684 c.GetLowerBound(1);
\r
685 } catch (IndexOutOfRangeException) {
\r
686 errorThrown = true;
\r
688 Assert("#H32", errorThrown);
\r
691 char[] c1 = new Char[5];
\r
692 AssertEquals("#H33",
\r
693 0, c1.GetLowerBound(0));
\r
695 char[,] c2 = new Char[4,4];
\r
696 AssertEquals("#H34",
\r
697 0, c2.GetLowerBound(0));
\r
698 AssertEquals("#H35",
\r
699 0, c2.GetLowerBound(1));
\r
702 public void TestGetUpperBound() {
\r
704 bool errorThrown = false;
\r
706 char[] c = {'a', 'b', 'c'};
\r
707 c.GetUpperBound(-1);
\r
708 } catch (IndexOutOfRangeException) {
\r
709 errorThrown = true;
\r
711 Assert("#H61", errorThrown);
\r
714 bool errorThrown = false;
\r
716 char[] c = {'a', 'b', 'c'};
\r
717 c.GetUpperBound(1);
\r
718 } catch (IndexOutOfRangeException) {
\r
719 errorThrown = true;
\r
721 Assert("#H62", errorThrown);
\r
724 char[] c1 = new Char[5];
\r
725 AssertEquals("#H63",
\r
726 4, c1.GetUpperBound(0));
\r
728 char[,] c2 = new Char[4,6];
\r
729 AssertEquals("#H64",
\r
730 3, c2.GetUpperBound(0));
\r
731 AssertEquals("#H65",
\r
732 5, c2.GetUpperBound(1));
\r
735 public void TestGetValue1() {
\r
737 bool errorThrown = false;
\r
739 char[,] c = new Char[2,2];
\r
741 } catch (ArgumentException) {
\r
742 errorThrown = true;
\r
744 Assert("#I01", errorThrown);
\r
747 bool errorThrown = false;
\r
749 char[] c = {'a', 'b', 'c'};
\r
751 } catch (IndexOutOfRangeException) {
\r
752 errorThrown = true;
\r
754 Assert("#I02", errorThrown);
\r
757 bool errorThrown = false;
\r
759 char[] c = {'a', 'b', 'c'};
\r
761 } catch (IndexOutOfRangeException) {
\r
762 errorThrown = true;
\r
764 Assert("#I03", errorThrown);
\r
767 char[] c1 = {'a', 'b', 'c', 'd'};
\r
768 for (int i = 0; i < c1.Length; i++) {
\r
769 AssertEquals("#I04(" + i + ")", c1[i], c1.GetValue(i));
\r
772 public void TestGetValue2() {
\r
774 bool errorThrown = false;
\r
776 char[] c = new Char[2];
\r
778 } catch (ArgumentException) {
\r
779 errorThrown = true;
\r
781 Assert("#I21", errorThrown);
\r
784 bool errorThrown = false;
\r
786 char[,] c = new Char[2,2];
\r
788 } catch (IndexOutOfRangeException) {
\r
789 errorThrown = true;
\r
791 Assert("#I22", errorThrown);
\r
794 bool errorThrown = false;
\r
796 char[,] c = new Char[2,2];
\r
798 } catch (IndexOutOfRangeException) {
\r
799 errorThrown = true;
\r
801 Assert("#I23", errorThrown);
\r
804 char[,] c1 = new Char[4,6];
\r
805 for (int i = 0; i < 24; i++) {
\r
807 int second = i % 6;
\r
808 c1[first,second] = (char)(((int)'a')+i);
\r
810 for (int i = 0; i < c1.GetLength(0); i++) {
\r
811 for (int j = 0; j < c1.GetLength(1); j++) {
\r
812 AssertEquals("#I24(" + i + "," + j + ")",
\r
813 c1[i,j], c1.GetValue(i, j));
\r
817 public void TestGetValue3() {
\r
819 bool errorThrown = false;
\r
821 char[] c = new Char[2];
\r
823 } catch (ArgumentException) {
\r
824 errorThrown = true;
\r
826 Assert("#I41", errorThrown);
\r
829 bool errorThrown = false;
\r
831 char[,,] c = new Char[2,2,2];
\r
832 c.GetValue(-1, 1, 1);
\r
833 } catch (IndexOutOfRangeException) {
\r
834 errorThrown = true;
\r
836 Assert("#I42", errorThrown);
\r
839 bool errorThrown = false;
\r
841 char[,,] c = new Char[2,2,2];
\r
843 } catch (IndexOutOfRangeException) {
\r
844 errorThrown = true;
\r
846 Assert("#I43", errorThrown);
\r
849 char[,,] c1 = new Char[4,2,3];
\r
850 for (int i = 0; i < 24; i++) {
\r
852 int remains = i % 6;
\r
853 int second = remains / 3;
\r
854 int third = remains % 3;
\r
855 c1[first,second, third] = (char)(((int)'a')+i);
\r
857 for (int i = 0; i < c1.GetLength(0); i++) {
\r
858 for (int j = 0; j < c1.GetLength(1); j++) {
\r
859 for (int k = 0; k < c1.GetLength(2); k++) {
\r
860 AssertEquals("#I44(" + i + "," + j + ")",
\r
861 c1[i,j,k], c1.GetValue(i,j,k));
\r
866 public void TestGetValueN() {
\r
868 bool errorThrown = false;
\r
870 char[] c = new Char[2];
\r
872 } catch (ArgumentNullException) {
\r
873 errorThrown = true;
\r
875 Assert("#I61", errorThrown);
\r
878 bool errorThrown = false;
\r
880 char[] c = new Char[2];
\r
881 int[] coords = {1, 1};
\r
882 c.GetValue(coords);
\r
883 } catch (ArgumentException) {
\r
884 errorThrown = true;
\r
886 Assert("#I62", errorThrown);
\r
889 bool errorThrown = false;
\r
891 char[,] c = new Char[2,2];
\r
892 int[] coords = {-1, 1};
\r
893 c.GetValue(coords);
\r
894 } catch (IndexOutOfRangeException) {
\r
895 errorThrown = true;
\r
897 Assert("#I63", errorThrown);
\r
900 bool errorThrown = false;
\r
902 char[,] c = new Char[2,2];
\r
903 int[] coords = {4, 1};
\r
904 c.GetValue(coords);
\r
905 } catch (IndexOutOfRangeException) {
\r
906 errorThrown = true;
\r
908 Assert("#I64", errorThrown);
\r
911 char[,] c1 = new Char[4,6];
\r
912 for (int i = 0; i < 24; i++) {
\r
914 int second = i % 6;
\r
915 c1[first,second] = (char)(((int)'a')+i);
\r
917 for (int i = 0; i < c1.GetLength(0); i++) {
\r
918 for (int j = 0; j < c1.GetLength(1); j++) {
\r
919 int[] coords = {i, j};
\r
920 AssertEquals("#I65(" + i + "," + j + ")",
\r
921 c1[i,j], c1.GetValue(coords));
\r
926 public void TestIndexOf1() {
\r
928 bool errorThrown = false;
\r
930 Array.IndexOf(null, "huh?");
\r
931 } catch (ArgumentNullException) {
\r
932 errorThrown = true;
\r
934 Assert("#J01", errorThrown);
\r
937 bool errorThrown = false;
\r
939 char[,] c = new Char[2,2];
\r
940 Array.IndexOf(c, "huh?");
\r
941 } catch (RankException) {
\r
942 errorThrown = true;
\r
944 Assert("#J02", errorThrown);
\r
947 String[] s1 = {"this", "is", "a", "test"};
\r
948 AssertEquals("#J03", -1, Array.IndexOf(s1, null));
\r
949 AssertEquals("#J04", -1, Array.IndexOf(s1, "nothing"));
\r
950 AssertEquals("#J05", 0, Array.IndexOf(s1, "this"));
\r
951 AssertEquals("#J06", 3, Array.IndexOf(s1, "test"));
\r
953 public void TestIndexOf2() {
\r
955 bool errorThrown = false;
\r
957 Array.IndexOf(null, "huh?", 0);
\r
958 } catch (ArgumentNullException) {
\r
959 errorThrown = true;
\r
961 Assert("#J21", errorThrown);
\r
964 bool errorThrown = false;
\r
966 char[,] c = new Char[2,2];
\r
967 Array.IndexOf(c, "huh?", 0);
\r
968 } catch (RankException) {
\r
969 errorThrown = true;
\r
971 Assert("#J22", errorThrown);
\r
974 bool errorThrown = false;
\r
976 char[] c = new Char[2];
\r
977 Array.IndexOf(c, "huh?", 3);
\r
978 } catch (ArgumentOutOfRangeException) {
\r
979 errorThrown = true;
\r
981 Assert("#J23", errorThrown);
\r
984 String[] s1 = {"this", "is", "really", "a", "test"};
\r
985 AssertEquals("#J24", -1, Array.IndexOf(s1, null, 1));
\r
986 AssertEquals("#J25", -1, Array.IndexOf(s1, "nothing", 1));
\r
987 AssertEquals("#J26", -1, Array.IndexOf(s1, "this", 1));
\r
988 AssertEquals("#J27", 1, Array.IndexOf(s1, "is", 1));
\r
989 AssertEquals("#J28", 4, Array.IndexOf(s1, "test", 1));
\r
991 public void TestIndexOf3() {
\r
993 bool errorThrown = false;
\r
995 Array.IndexOf(null, "huh?", 0, 1);
\r
996 } catch (ArgumentNullException) {
\r
997 errorThrown = true;
\r
999 Assert("#J41", errorThrown);
\r
1002 bool errorThrown = false;
\r
1004 char[,] c = new Char[2,2];
\r
1005 Array.IndexOf(c, "huh?", 0, 1);
\r
1006 } catch (RankException) {
\r
1007 errorThrown = true;
\r
1009 Assert("#J42", errorThrown);
\r
1012 bool errorThrown = false;
\r
1014 char[] c = new Char[2];
\r
1015 Array.IndexOf(c, "huh?", 3, 1);
\r
1016 } catch (ArgumentOutOfRangeException) {
\r
1017 errorThrown = true;
\r
1019 Assert("#J43", errorThrown);
\r
1022 bool errorThrown = false;
\r
1024 char[] c = new Char[2];
\r
1025 Array.IndexOf(c, "huh?", 0, 5);
\r
1026 } catch (ArgumentOutOfRangeException) {
\r
1027 errorThrown = true;
\r
1029 Assert("#J44", errorThrown);
\r
1032 String[] s1 = {"this", "is", "really", "a", "test"};
\r
1033 AssertEquals("#J45", -1, Array.IndexOf(s1, null, 1, 3));
\r
1034 AssertEquals("#J46", -1, Array.IndexOf(s1, "nothing", 1, 3));
\r
1035 AssertEquals("#J47", -1, Array.IndexOf(s1, "this", 1, 3));
\r
1036 AssertEquals("#J48", 1, Array.IndexOf(s1, "is", 1, 3));
\r
1037 AssertEquals("#J49", -1, Array.IndexOf(s1, "test", 1, 3));
\r
1038 AssertEquals("#J50", 3, Array.IndexOf(s1, "a", 1, 3));
\r
1041 public void TestLastIndexOf1() {
\r
1043 bool errorThrown = false;
\r
1045 Array.LastIndexOf(null, "huh?");
\r
1046 } catch (ArgumentNullException) {
\r
1047 errorThrown = true;
\r
1049 Assert("#K01", errorThrown);
\r
1052 bool errorThrown = false;
\r
1054 char[,] c = new Char[2,2];
\r
1055 Array.LastIndexOf(c, "huh?");
\r
1056 } catch (RankException) {
\r
1057 errorThrown = true;
\r
1059 Assert("#K02", errorThrown);
\r
1062 String[] s1 = {"this", "is", "a", "a", "test"};
\r
1063 AssertEquals("#K03", -1, Array.LastIndexOf(s1, null));
\r
1064 AssertEquals("#K04", -1, Array.LastIndexOf(s1, "nothing"));
\r
1065 AssertEquals("#K05", 0, Array.LastIndexOf(s1, "this"));
\r
1066 AssertEquals("#K06", 4, Array.LastIndexOf(s1, "test"));
\r
1067 AssertEquals("#K07", 3, Array.LastIndexOf(s1, "a"));
\r
1069 public void TestLastIndexOf2() {
\r
1071 bool errorThrown = false;
\r
1073 Array.LastIndexOf(null, "huh?", 0);
\r
1074 } catch (ArgumentNullException) {
\r
1075 errorThrown = true;
\r
1077 Assert("#K21", errorThrown);
\r
1080 bool errorThrown = false;
\r
1082 char[,] c = new Char[2,2];
\r
1083 Array.LastIndexOf(c, "huh?", 0);
\r
1084 } catch (RankException) {
\r
1085 errorThrown = true;
\r
1087 Assert("#K22", errorThrown);
\r
1090 bool errorThrown = false;
\r
1092 char[] c = new Char[2];
\r
1093 Array.LastIndexOf(c, "huh?", 3);
\r
1094 } catch (ArgumentOutOfRangeException) {
\r
1095 errorThrown = true;
\r
1097 Assert("#K23", errorThrown);
\r
1100 String[] s1 = {"this", "is", "really", "a", "test"};
\r
1101 AssertEquals("#K24", -1, Array.LastIndexOf(s1, null, 3));
\r
1102 AssertEquals("#K25", -1, Array.LastIndexOf(s1, "nothing", 3));
\r
1103 AssertEquals("#K26", -1, Array.LastIndexOf(s1, "test", 3));
\r
1104 AssertEquals("#K27", 3, Array.LastIndexOf(s1, "a", 3));
\r
1105 AssertEquals("#K28", 0, Array.LastIndexOf(s1, "this", 3));
\r
1107 public void TestLastIndexOf3() {
\r
1109 bool errorThrown = false;
\r
1111 Array.LastIndexOf(null, "huh?", 0, 1);
\r
1112 } catch (ArgumentNullException) {
\r
1113 errorThrown = true;
\r
1115 Assert("#K41", errorThrown);
\r
1118 bool errorThrown = false;
\r
1120 char[,] c = new Char[2,2];
\r
1121 Array.LastIndexOf(c, "huh?", 0, 1);
\r
1122 } catch (RankException) {
\r
1123 errorThrown = true;
\r
1125 Assert("#K42", errorThrown);
\r
1128 bool errorThrown = false;
\r
1130 char[] c = new Char[2];
\r
1131 Array.LastIndexOf(c, "huh?", 3, 1);
\r
1132 } catch (ArgumentOutOfRangeException) {
\r
1133 errorThrown = true;
\r
1135 Assert("#K43", errorThrown);
\r
1138 bool errorThrown = false;
\r
1140 char[] c = new Char[2];
\r
1141 Array.LastIndexOf(c, "huh?", 0, 5);
\r
1142 } catch (ArgumentOutOfRangeException) {
\r
1143 errorThrown = true;
\r
1145 Assert("#K44", errorThrown);
\r
1148 String[] s1 = {"this", "is", "really", "a", "test"};
\r
1149 AssertEquals("#K45",
\r
1150 -1, Array.LastIndexOf(s1, null, 3, 3));
\r
1151 AssertEquals("#K46",
\r
1152 -1, Array.LastIndexOf(s1, "nothing", 3, 3));
\r
1153 AssertEquals("#K47",
\r
1154 -1, Array.LastIndexOf(s1, "this", 3, 3));
\r
1155 AssertEquals("#K48",
\r
1156 1, Array.LastIndexOf(s1, "is", 3, 3));
\r
1157 AssertEquals("#K49",
\r
1158 -1, Array.LastIndexOf(s1, "test", 3, 3));
\r
1159 AssertEquals("#K50",
\r
1160 3, Array.LastIndexOf(s1, "a", 3, 3));
\r
1163 public void TestReverse() {
\r
1165 bool errorThrown = false;
\r
1167 Array.Reverse(null);
\r
1168 } catch (ArgumentNullException) {
\r
1169 errorThrown = true;
\r
1171 Assert("#L01", errorThrown);
\r
1174 bool errorThrown = false;
\r
1176 char[,] c = new Char[2,2];
\r
1178 } catch (RankException) {
\r
1179 errorThrown = true;
\r
1181 Assert("#L02", errorThrown);
\r
1184 char[] c1 = {'a', 'b', 'c', 'd'};
\r
1185 Array.Reverse(c1);
\r
1186 AssertEquals("#L03", 'd', c1[0]);
\r
1187 AssertEquals("#L04", 'c', c1[1]);
\r
1188 AssertEquals("#L05", 'b', c1[2]);
\r
1189 AssertEquals("#L06", 'a', c1[3]);
\r
1192 bool errorThrown = false;
\r
1194 Array.Reverse(null, 0, 0);
\r
1195 } catch (ArgumentNullException) {
\r
1196 errorThrown = true;
\r
1198 Assert("#L07", errorThrown);
\r
1201 bool errorThrown = false;
\r
1203 char[,] c = new Char[2,2];
\r
1204 Array.Reverse(c, 0, 0);
\r
1205 } catch (RankException) {
\r
1206 errorThrown = true;
\r
1208 Assert("#L08", errorThrown);
\r
1211 //bool errorThrown = false;
\r
1213 // char[] c = new Char[2];
\r
1214 // Array.Reverse(c, 0, 3);
\r
1215 //} catch (ArgumentOutOfRangeException) {
\r
1216 // errorThrown = true;
\r
1218 //Assert("#L09", errorThrown);
\r
1221 //bool errorThrown = false;
\r
1223 // char[] c = new Char[2];
\r
1224 // Array.Reverse(c, 3, 0);
\r
1225 //} catch (ArgumentOutOfRangeException) {
\r
1226 // errorThrown = true;
\r
1228 //Assert("#L10", errorThrown);
\r
1231 char[] c2 = { 'a', 'b', 'c', 'd'};
\r
1232 Array.Reverse(c2, 1, 2);
\r
1233 AssertEquals("#L11", 'a', c2[0]);
\r
1234 AssertEquals("#L12", 'c', c2[1]);
\r
1235 AssertEquals("#L13", 'b', c2[2]);
\r
1236 AssertEquals("#L14", 'd', c2[3]);
\r
1239 public void TestSetValue1() {
\r
1241 bool errorThrown = false;
\r
1243 char[,] c = new Char[2,2];
\r
1244 c.SetValue("buh", 1);
\r
1245 } catch (ArgumentException) {
\r
1246 errorThrown = true;
\r
1248 Assert("#M01", errorThrown);
\r
1251 bool errorThrown = false;
\r
1253 char[] c = {'a', 'b', 'c'};
\r
1254 c.SetValue("buh", -1);
\r
1255 } catch (IndexOutOfRangeException) {
\r
1256 errorThrown = true;
\r
1258 Assert("#M02", errorThrown);
\r
1261 bool errorThrown = false;
\r
1263 char[] c = {'a', 'b', 'c'};
\r
1264 c.SetValue("buh", 4);
\r
1265 } catch (IndexOutOfRangeException) {
\r
1266 errorThrown = true;
\r
1268 Assert("#M03", errorThrown);
\r
1271 char[] c1 = {'a', 'b', 'c', 'd'};
\r
1272 char[] c2 = new char[4];
\r
1273 for (int i = 0; i < c1.Length; i++) {
\r
1274 c2.SetValue(c1[i], i);
\r
1276 for (int i = 0; i < c1.Length; i++) {
\r
1277 AssertEquals("#M04(" + i + ")", c1[i], c2[i]);
\r
1280 int[] c3 = { 1, 2, 3 };
\r
1281 long[] c4 = new long [3];
\r
1283 for (int i = 0; i < c3.Length; i++)
\r
1284 c4.SetValue (c3 [i], i);
\r
1285 c3.CopyTo (c4, 0);
\r
1286 for (int i = 0; i < c3.Length; i++)
\r
1287 Assert ("#M05(" + i + ")", c3[i] == c4[i]);
\r
1289 Object[] c5 = new Object [3];
\r
1290 long[] c6 = new long [3];
\r
1292 c4.CopyTo (c5, 0);
\r
1294 c5.CopyTo (c6, 0);
\r
1295 // for (int i = 0; i < c5.Length; i++)
\r
1296 // Assert ("#M06(" + i + ")", c5[i] == c6[i]);
\r
1299 public void TestSetValue2() {
\r
1301 bool errorThrown = false;
\r
1303 char[] c = new Char[2];
\r
1304 c.SetValue("buh", 1,1);
\r
1305 } catch (ArgumentException) {
\r
1306 errorThrown = true;
\r
1308 Assert("#M21", errorThrown);
\r
1311 bool errorThrown = false;
\r
1313 char[,] c = new Char[2,2];
\r
1314 c.SetValue("buh", -1, 1);
\r
1315 } catch (IndexOutOfRangeException) {
\r
1316 errorThrown = true;
\r
1318 Assert("#M22", errorThrown);
\r
1321 bool errorThrown = false;
\r
1323 char[,] c = new Char[2,2];
\r
1324 c.SetValue("buh", 4,1);
\r
1325 } catch (IndexOutOfRangeException) {
\r
1326 errorThrown = true;
\r
1328 Assert("#M23", errorThrown);
\r
1331 char[,] c1 = new Char[4,6];
\r
1332 char[,] c2 = new Char[4,6];
\r
1333 for (int i = 0; i < 24; i++) {
\r
1334 int first = i / 6;
\r
1335 int second = i % 6;
\r
1336 c1[first,second] = (char)(((int)'a')+i);
\r
1337 c2.SetValue(c1[first,second], first, second);
\r
1339 for (int i = 0; i < c1.GetLength(0); i++) {
\r
1340 for (int j = 0; j < c1.GetLength(1); j++) {
\r
1341 AssertEquals("#M24(" + i + "," + j + ")",
\r
1342 c1[i,j], c2[i, j]);
\r
1346 public void TestSetValue3() {
\r
1348 bool errorThrown = false;
\r
1350 char[] c = new Char[2];
\r
1351 c.SetValue("buh", 1,1,1);
\r
1352 } catch (ArgumentException) {
\r
1353 errorThrown = true;
\r
1355 Assert("#M41", errorThrown);
\r
1358 bool errorThrown = false;
\r
1360 char[,,] c = new Char[2,2,2];
\r
1361 c.SetValue("buh", -1, 1, 1);
\r
1362 } catch (IndexOutOfRangeException) {
\r
1363 errorThrown = true;
\r
1365 Assert("#M42", errorThrown);
\r
1368 bool errorThrown = false;
\r
1370 char[,,] c = new Char[2,2,2];
\r
1371 c.SetValue("buh", 4,1,1);
\r
1372 } catch (IndexOutOfRangeException) {
\r
1373 errorThrown = true;
\r
1375 Assert("#M43", errorThrown);
\r
1378 char[,,] c1 = new Char[4,2,3];
\r
1379 char[,,] c2 = new Char[4,2,3];
\r
1380 for (int i = 0; i < 24; i++) {
\r
1381 int first = i / 6;
\r
1382 int remains = i % 6;
\r
1383 int second = remains / 3;
\r
1384 int third = remains % 3;
\r
1385 c1[first,second, third] = (char)(((int)'a')+i);
\r
1386 c2.SetValue(c1[first, second, third], first, second, third);
\r
1388 for (int i = 0; i < c1.GetLength(0); i++) {
\r
1389 for (int j = 0; j < c1.GetLength(1); j++) {
\r
1390 for (int k = 0; k < c1.GetLength(2); k++) {
\r
1391 AssertEquals("#M44(" + i + "," + j + " )",
\r
1392 c1[i,j,k], c2[i,j,k]);
\r
1397 public void TestSetValueN() {
\r
1399 bool errorThrown = false;
\r
1401 char[] c = new Char[2];
\r
1402 c.SetValue("buh", null);
\r
1403 } catch (ArgumentNullException) {
\r
1404 errorThrown = true;
\r
1406 Assert("#M61", errorThrown);
\r
1409 bool errorThrown = false;
\r
1411 char[] c = new Char[2];
\r
1412 int[] coords = {1, 1};
\r
1413 c.SetValue("buh", coords);
\r
1414 } catch (ArgumentException) {
\r
1415 errorThrown = true;
\r
1417 Assert("#M62", errorThrown);
\r
1420 bool errorThrown = false;
\r
1422 char[,] c = new Char[2,2];
\r
1423 int[] coords = {-1, 1};
\r
1424 c.SetValue("buh", coords);
\r
1425 } catch (IndexOutOfRangeException) {
\r
1426 errorThrown = true;
\r
1428 Assert("#M63", errorThrown);
\r
1431 bool errorThrown = false;
\r
1433 char[,] c = new Char[2,2];
\r
1434 int[] coords = {4, 1};
\r
1435 c.SetValue("buh", coords);
\r
1436 } catch (IndexOutOfRangeException) {
\r
1437 errorThrown = true;
\r
1439 Assert("#M64", errorThrown);
\r
1442 char[,] c1 = new Char[4,6];
\r
1443 char[,] c2 = new Char[4,6];
\r
1444 for (int i = 0; i < 24; i++) {
\r
1445 int first = i / 6;
\r
1446 int second = i % 6;
\r
1447 c1[first,second] = (char)(((int)'a')+i);
\r
1448 int[] coords = {first, second};
\r
1449 c2.SetValue(c1[first,second], coords);
\r
1451 for (int i = 0; i < c1.GetLength(0); i++) {
\r
1452 for (int j = 0; j < c1.GetLength(1); j++) {
\r
1453 AssertEquals("#M65(" + i + "," + j + ")",
\r
1454 c1[i,j], c2[i,j]);
\r
1459 public void TestSetValue4() {
\r
1461 int[] c1 = { 1, 2, 3 };
\r
1462 long[] c2 = new long [3];
\r
1464 for (int i = 0; i < c1.Length; i++)
\r
1465 c2.SetValue (c1 [i], i);
\r
1467 for (int i = 0; i < c1.Length; i++) {
\r
1468 Assert ("#M81(" + i + ")", c1[i] == c2[i]);
\r
1469 AssertEquals ("#M82(" + i + ")", typeof (long), c2[i].GetType ());
\r
1473 long[] c1 = { 1, 2, 3 };
\r
1474 int[] c2 = new int [3];
\r
1475 bool errorThrown = false;
\r
1477 c2.SetValue (c1 [0], 0);
\r
1478 } catch (ArgumentException) {
\r
1479 errorThrown = true;
\r
1481 Assert("#M83", errorThrown);
\r
1484 int[] c1 = { 1, 2, 3 };
\r
1485 Object[] c2 = new Object [3];
\r
1487 for (int i = 0; i < c1.Length; i++)
\r
1488 c2.SetValue (c1 [i], i);
\r
1490 for (int i = 0; i < c1.Length; i++)
\r
1491 AssertEquals ("#M84(" + i + ")", c1[i], Convert.ToInt32 (c2[i]));
\r
1494 Object[] c1 = new Object [3];
\r
1495 Object[] c2 = new Object [3];
\r
1496 c1[0] = new Object ();
\r
1498 for (int i = 0; i < c1.Length; i++)
\r
1499 c2.SetValue (c1 [i], i);
\r
1501 for (int i = 0; i < c1.Length; i++)
\r
1502 AssertEquals ("#M85(" + i + ")", c1[i], c2[i]);
\r
1505 Object[] c1 = new Object [3];
\r
1506 string[] c2 = new String [3];
\r
1507 string test = "hello";
\r
1510 c2.SetValue (c1 [0], 0);
\r
1511 AssertEquals ("#M86", c1[0], c2[0]);
\r
1512 AssertEquals ("#M87", "hello", c2[0]);
\r
1515 char[] c1 = { 'a', 'b', 'c' };
\r
1516 string[] c2 = new string [3];
\r
1517 bool errorThrown = false;
\r
1519 c2.SetValue (c1 [0], 0);
\r
1521 errorThrown = true;
\r
1522 } catch (InvalidCastException) {
\r
1523 errorThrown = true;
\r
1525 Assert("#M88", errorThrown);
\r
1528 Single[] c1 = { 1.2F, 2.3F, 3.4F, 4.5F };
\r
1529 long[] c2 = new long [3];
\r
1530 bool errorThrown = false;
\r
1532 c2.SetValue (c1 [0], 0);
\r
1534 errorThrown = true;
\r
1535 } catch (ArgumentException) {
\r
1536 errorThrown = true;
\r
1538 Assert("#M89", errorThrown);
\r
1562 Int64 v7 = -34523;
\r
1564 Single v9 = -4.8F;
\r
1565 UInt16 v10 = 24234;
\r
1566 UInt32 v11 = 235354;
\r
1567 UInt64 v12 = 234552;
\r
1569 Object[] va1 = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 };
\r
1570 Object[] va2 = { "true", "1", "a", "-1.2", "-32", "-234", "-34523", "-1",
\r
1571 "-4.8F", "24234", "235354", "234552" };
\r
1573 Object[][] vt = { va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1 };
\r
1576 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
\r
1577 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
\r
1578 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
\r
1579 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
\r
1580 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1,
\r
1581 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1,
\r
1582 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1,
\r
1583 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1,
\r
1584 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1,
\r
1585 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
\r
1586 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0,
\r
1587 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0
\r
1592 for (int i = 0; i < types.Length; i++) {
\r
1593 for (int j = 0; j < types.Length; j++) {
\r
1594 Array array = Array.CreateInstance (types [j], 2);
\r
1596 Object value = vt[j][i];
\r
1598 bool errorThrown = false;
\r
1600 array.SetValue (value, 0);
\r
1601 } catch (ArgumentException) {
\r
1602 errorThrown = true;
\r
1605 int ex_index = (i * types.Length) + j;
\r
1607 AssertEquals ("#M90(" + types [i] + "," + types [j] + ")",
\r
1608 errorThrown, arg_ex [ex_index] == 1);
\r
1612 for (int i = 0; i < types.Length; i++) {
\r
1613 String[] array = new String [2];
\r
1615 Object value = va1 [i];
\r
1617 bool errorThrown = false;
\r
1619 array.SetValue (value, 0);
\r
1620 } catch (InvalidCastException) {
\r
1621 errorThrown = true;
\r
1624 Assert ("#M91(" + types [i] + ")", errorThrown);
\r
1627 for (int i = 0; i < types.Length; i++) {
\r
1628 Array array = Array.CreateInstance (types [i], 2);
\r
1630 Object value = va2 [i];
\r
1632 bool errorThrown = false;
\r
1634 array.SetValue (value, 0);
\r
1635 } catch (InvalidCastException) {
\r
1636 errorThrown = true;
\r
1639 Assert ("#M92(" + types [i] + ")", errorThrown);
\r
1642 for (int i = 0; i < types.Length; i++) {
\r
1643 Array array = Array.CreateInstance (types [i], 2);
\r
1645 Object value = null;
\r
1647 bool errorThrown = false;
\r
1649 array.SetValue (value, 0);
\r
1650 } catch (InvalidCastException) {
\r
1651 errorThrown = true;
\r
1654 Assert ("#M93(" + types [i] + ")", !errorThrown);
\r
1659 for (int i = 0; i < types.Length; i++) {
\r
1660 for (int j = 0; j < types.Length; j++) {
\r
1661 Array source = Array.CreateInstance (types [i], 2);
\r
1662 Array array = Array.CreateInstance (types [j], 2);
\r
1664 source.SetValue (vt[j][i], 0);
\r
1665 source.SetValue (vt[j][i], 1);
\r
1667 bool errorThrown = false;
\r
1669 Array.Copy (source, array, 2);
\r
1670 } catch (ArrayTypeMismatchException) {
\r
1671 errorThrown = true;
\r
1674 int ex_index = (i * types.Length) + j;
\r
1676 AssertEquals ("#M94(" + types [i] + "," + types [j] + ")",
\r
1677 errorThrown, arg_ex [ex_index] == 1);
\r
1681 for (int i = 0; i < types.Length; i++) {
\r
1682 Array source = Array.CreateInstance (types [i], 2);
\r
1683 String[] array = new String [2];
\r
1685 source.SetValue (va1 [i], 0);
\r
1686 source.SetValue (va1 [i], 1);
\r
1688 bool errorThrown = false;
\r
1690 Array.Copy (source, array, 2);
\r
1691 } catch (ArrayTypeMismatchException) {
\r
1692 errorThrown = true;
\r
1695 Assert ("#M95(" + types [i] + ")", errorThrown);
\r
1698 for (int i = 0; i < types.Length; i++) {
\r
1699 String[] source = new String [2];
\r
1700 Array array = Array.CreateInstance (types [i], 2);
\r
1702 source.SetValue (va2 [i], 0);
\r
1703 source.SetValue (va2 [i], 1);
\r
1705 bool errorThrown = false;
\r
1707 Array.Copy (source, array, 2);
\r
1708 } catch (ArrayTypeMismatchException) {
\r
1709 errorThrown = true;
\r
1712 Assert ("#M96(" + types [i] + ")", errorThrown);
\r
1718 public void TestSort() {
\r
1720 bool errorThrown = false;
\r
1723 } catch (ArgumentNullException) {
\r
1724 errorThrown = true;
\r
1726 Assert("#N01", errorThrown);
\r
1729 bool errorThrown = false;
\r
1731 Array.Sort(null, 0, 1);
\r
1732 } catch (ArgumentNullException) {
\r
1733 errorThrown = true;
\r
1735 Assert("#N02", errorThrown);
\r
1738 bool errorThrown = false;
\r
1740 char[] c1 = new Char[2];
\r
1741 Array.Sort(null, c1);
\r
1742 } catch (ArgumentNullException) {
\r
1743 errorThrown = true;
\r
1745 Assert("#N03", errorThrown);
\r
1748 bool errorThrown = false;
\r
1750 char[] c1 = new Char[2];
\r
1751 Array.Sort(null, c1, 0, 1);
\r
1752 } catch (ArgumentNullException) {
\r
1753 errorThrown = true;
\r
1755 Assert("#N04", errorThrown);
\r
1758 // note: null second array => just sort first array
\r
1759 char[] starter = {'d', 'b', 'f', 'e', 'a', 'c'};
\r
1760 int[] starter1 = {1,2,3,4,5,6};
\r
1762 char[] c1 = (char[])starter.Clone();
\r
1764 AssertEquals("#N21", 'a', c1[0]);
\r
1765 AssertEquals("#N22", 'b', c1[1]);
\r
1766 AssertEquals("#N23", 'c', c1[2]);
\r
1767 AssertEquals("#N24", 'd', c1[3]);
\r
1768 AssertEquals("#N25", 'e', c1[4]);
\r
1769 AssertEquals("#N26", 'f', c1[5]);
\r
1772 char[] c1 = (char[])starter.Clone();
\r
1773 int[] i1 = (int[])starter1.Clone();
\r
1774 Array.Sort(c1, i1);
\r
1775 AssertEquals("#N41", 'a', c1[0]);
\r
1776 AssertEquals("#N42", 'b', c1[1]);
\r
1777 AssertEquals("#N43", 'c', c1[2]);
\r
1778 AssertEquals("#N44", 'd', c1[3]);
\r
1779 AssertEquals("#N45", 'e', c1[4]);
\r
1780 AssertEquals("#N46", 'f', c1[5]);
\r
1781 AssertEquals("#N47", 5, i1[0]);
\r
1782 AssertEquals("#N48", 2, i1[1]);
\r
1783 AssertEquals("#N49", 6, i1[2]);
\r
1784 AssertEquals("#N50", 1, i1[3]);
\r
1785 AssertEquals("#N51", 4, i1[4]);
\r
1786 AssertEquals("#N52", 3, i1[5]);
\r
1789 char[] c1 = (char[])starter.Clone();
\r
1790 Array.Sort(c1, 1, 4);
\r
1791 AssertEquals("#N61", 'd', c1[0]);
\r
1792 AssertEquals("#N62", 'a', c1[1]);
\r
1793 AssertEquals("#N63", 'b', c1[2]);
\r
1794 AssertEquals("#N64", 'e', c1[3]);
\r
1795 AssertEquals("#N65", 'f', c1[4]);
\r
1796 AssertEquals("#N66", 'c', c1[5]);
\r
1799 char[] c1 = (char[])starter.Clone();
\r
1800 int[] i1 = (int[])starter1.Clone();
\r
1801 Array.Sort(c1, i1, 1, 4);
\r
1802 AssertEquals("#N81", 'd', c1[0]);
\r
1803 AssertEquals("#N82", 'a', c1[1]);
\r
1804 AssertEquals("#N83", 'b', c1[2]);
\r
1805 AssertEquals("#N84", 'e', c1[3]);
\r
1806 AssertEquals("#N85", 'f', c1[4]);
\r
1807 AssertEquals("#N86", 'c', c1[5]);
\r
1808 AssertEquals("#N87", 1, i1[0]);
\r
1809 AssertEquals("#N88", 5, i1[1]);
\r
1810 AssertEquals("#N89", 2, i1[2]);
\r
1811 AssertEquals("#N90", 4, i1[3]);
\r
1812 AssertEquals("#N91", 3, i1[4]);
\r
1813 AssertEquals("#N92", 6, i1[5]);
\r
1817 // TODO - TestSort passed-in IComparable versions
\r