1 // ArrayTest.cs - NUnit Test Cases for the System.Array class
3 // David Brandt (bucky@keystreams.com)
4 // Eduardo Garcia (kiwnix@yahoo.es)
6 // (C) Ximian, Inc. http://www.ximian.com
7 // Copyright (C) 2004 Novell (http://www.novell.com)
10 using NUnit.Framework;
12 using System.Collections;
13 using System.Globalization;
16 using System.Collections.Generic;
19 namespace MonoTests.System
22 enum enua {hola,adios,mas,menos};
45 //End Auxiliary Things
48 public class ArrayTest : Assertion
50 char [] arrsort = {'d', 'b', 'f', 'e', 'a', 'c'};
55 public void TestIsFixedSize() {
57 Assert("All arrays are fixed", a1.IsFixedSize);
61 public void TestIsReadOnly() {
63 Assert("No array is readonly", !a1.IsReadOnly);
67 public void TestIsSynchronized() {
69 Assert("No array is synchronized", !a1.IsSynchronized);
73 public void TestLength() {
76 AssertEquals("Zero length array", 0, a1.Length);
80 AssertEquals("One-length array", 1, a1.Length);
83 char[] a1 = {'c', 'c'};
84 AssertEquals("Two-length array", 2, a1.Length);
89 public void TestRank() {
90 char[] a1 = { 'c', 'd', 'e' };
91 AssertEquals("Rank one", 1, a1.Rank);
93 char[,] a2 = new Char[3,3];
94 AssertEquals("Rank two", 2, a2.Rank);
96 char[,,] a3 = new Char[3,3,3];
97 AssertEquals("Rank three", 3, a3.Rank);
101 public void TestBinarySearch1() {
102 bool errorThrown = false;
104 Array.BinarySearch(null, "blue");
105 } catch (ArgumentNullException) {
108 Assert("#B01", errorThrown);
111 char[,] c1 = new Char[2,2];
112 Array.BinarySearch(c1, "needle");
113 } catch (RankException) {
116 Assert("#B02", errorThrown);
119 char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
120 Assert("#B05", Array.BinarySearch(arr, 'c') >= 3);
121 Assert("#B06", Array.BinarySearch(arr, 'c') < 6);
124 char[] arr = {'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
125 AssertEquals("#B07", -4, Array.BinarySearch(arr, 'c'));
128 char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
129 AssertEquals("#B08", -9, Array.BinarySearch(arr, 'e'));
134 public void TestBinarySearch2() {
135 bool errorThrown = false;
137 Array.BinarySearch(null, 0, 1, "blue");
138 } catch (ArgumentNullException) {
141 Assert("#B20", errorThrown);
144 char[,] c1 = new Char[2,2];
145 Array.BinarySearch(c1, 0, 1, "needle");
146 } catch (RankException) {
149 Assert("#B21", errorThrown);
153 Array.BinarySearch(c1, -1, 1, 'a');
154 } catch (ArgumentOutOfRangeException) {
157 Assert("#B22", errorThrown);
161 Array.BinarySearch(c1, 0, -1, 'a');
162 } catch (ArgumentOutOfRangeException) {
165 Assert("#B23", errorThrown);
169 Array.BinarySearch(c1, 0, 4, 'a');
170 } catch (ArgumentException) {
173 Assert("#B24", errorThrown);
176 char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
177 Assert("#B26", Array.BinarySearch(arr, 2, 8, 'c') >= 5);
178 Assert("#B27", Array.BinarySearch(arr, 2, 8, 'c') < 8);
181 char[] arr = {'z', 'z', 'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
182 AssertEquals("#B28", -6, Array.BinarySearch(arr, 2, 8, 'c'));
185 char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
186 AssertEquals("#B29", -11, Array.BinarySearch(arr, 2, 8, 'e'));
190 public void TestBinarySearch3()
192 int[] array = new int[100];
194 for (int i = 0; i < 100; i++)
197 AssertEquals("#B30", 49, Array.BinarySearch(array, 10));
201 public void BinarySearch_NullValue ()
203 int[] array = new int[1];
204 AssertEquals ("I=a,o", -1, Array.BinarySearch (array, null));
205 AssertEquals ("I=a,o,c", -1, Array.BinarySearch (array, null, null));
206 AssertEquals ("I=a,i,i,o", -1, Array.BinarySearch (array, 0, 1, null));
207 AssertEquals ("I=a,i,i,o,c", -1, Array.BinarySearch (array, 0, 1, null,null));
209 object[] o = new object [3] { this, this, null };
210 AssertEquals ("O=a,o", -1, Array.BinarySearch (o, null));
211 AssertEquals ("O=a,o,c", -1, Array.BinarySearch (o, null, null));
212 AssertEquals ("O=a,i,i,o", -1, Array.BinarySearch (o, 0, 3, null));
213 AssertEquals ("O=a,i,i,o,c", -1, Array.BinarySearch (o, 0, 3, null, null));
216 // TODO - testBinarySearch with explicit IComparer args
219 public void TestClear() {
220 bool errorThrown = false;
222 Array.Clear(null, 0, 1);
223 } catch (ArgumentNullException) {
226 Assert("#C01", errorThrown);
228 int[] i1 = { 1, 2, 3, 4 };
230 int[] compare = {1,2,3,4};
231 AssertEquals("#C02", compare[0], i1[0]);
232 AssertEquals("#C03", compare[1], i1[1]);
233 AssertEquals("#C04", compare[2], i1[2]);
234 AssertEquals("#C05", compare[3], i1[3]);
236 Array.Clear(i1, 3, 1);
238 int[] compare = {1,2,3,0};
239 AssertEquals("#C06", compare[0], i1[0]);
240 AssertEquals("#C07", compare[1], i1[1]);
241 AssertEquals("#C08", compare[2], i1[2]);
242 AssertEquals("#C09", compare[3], i1[3]);
244 Array.Clear(i1, 1, 1);
246 int[] compare = {1,0,3,0};
247 AssertEquals("#C10", compare[0], i1[0]);
248 AssertEquals("#C11", compare[1], i1[1]);
249 AssertEquals("#C12", compare[2], i1[2]);
250 AssertEquals("#C13", compare[3], i1[3]);
252 Array.Clear(i1, 1, 3);
254 int[] compare = {1,0,0,0};
255 AssertEquals("#C14", compare[0], i1[0]);
256 AssertEquals("#C15", compare[1], i1[1]);
257 AssertEquals("#C16", compare[2], i1[2]);
258 AssertEquals("#C17", compare[3], i1[3]);
261 string[] s1 = { "red", "green", "blue" };
262 Array.Clear(s1, 0, 3);
264 string[] compare = {null, null, null};
265 AssertEquals("#C18", compare[0], s1[0]);
266 AssertEquals("#C19", compare[1], s1[1]);
267 AssertEquals("#C20", compare[2], s1[2]);
272 public void TestClone() {
273 char[] c1 = {'a', 'b', 'c'};
274 char[] c2 = (char[])c1.Clone();
275 AssertEquals("#D01", c1[0], c2[0]);
276 AssertEquals("#D02", c1[1], c2[1]);
277 AssertEquals("#D03", c1[2], c2[2]);
279 char[] d10 = {'a', 'b'};
280 char[] d11 = {'a', 'c'};
281 char[] d12 = {'b', 'c'};
282 char[][] d1 = {d10, d11, d12};
283 char[][] d2 = (char[][])d1.Clone();
284 AssertEquals("#D04", d1[0], d2[0]);
285 AssertEquals("#D05", d1[1], d2[1]);
286 AssertEquals("#D06", d1[2], d2[2]);
289 AssertEquals("#D07", d1[0], d2[0]);
293 public void TestCopy() {
295 bool errorThrown = false;
298 Array.Copy(c1, null, 1);
299 } catch (ArgumentNullException) {
302 Assert("#E01", errorThrown);
305 bool errorThrown = false;
308 Array.Copy(null, c1, 1);
309 } catch (ArgumentNullException) {
312 Assert("#E02", errorThrown);
315 bool errorThrown = false;
317 Char[] c1 = new Char[1];
318 Char[,] c2 = new Char[1,1];
319 Array.Copy(c1, c2, 1);
320 } catch (RankException) {
323 Assert("#E03", errorThrown);
326 bool errorThrown = false;
328 Char[] c1 = new Char[1];
329 string[] s1 = new String[1];
330 Array.Copy(c1, s1, 1);
331 } catch (ArrayTypeMismatchException) {
334 Assert("#E04", errorThrown);
337 bool errorThrown = false;
339 Char[] c1 = new Char[1];
340 Object[] o1 = new Object[1];
342 Array.Copy(o1, c1, 1);
343 } catch (InvalidCastException) {
346 Assert("#E05", errorThrown);
349 bool errorThrown = false;
351 Char[] c1 = new Char[1];
352 Char[] c2 = new Char[1];
353 Array.Copy(c1, c2, -1);
354 } catch (ArgumentOutOfRangeException) {
357 Assert("#E06", errorThrown);
360 bool errorThrown = false;
362 Char[] c1 = new Char[1];
363 Char[] c2 = new Char[2];
364 Array.Copy(c1, c2, 2);
365 } catch (ArgumentException) {
368 Assert("#E07", errorThrown);
371 bool errorThrown = false;
373 Char[] c1 = new Char[1];
374 Char[] c2 = new Char[2];
375 Array.Copy(c2, c1, 2);
376 } catch (ArgumentException) {
379 Assert("#E08", errorThrown);
382 char[] orig = {'a', 'b', 'd', 'a'};
383 char[] copy = new Char[4];
384 Array.Copy(orig, copy, 4);
385 for (int i = 0; i < orig.Length; i++) {
386 AssertEquals("#E09(" + i + ")", orig[i], copy[i]);
388 Array.Clear(copy, 0, copy.Length);
389 for (int i = 0; i < orig.Length; i++) {
390 AssertEquals("#E10(" + i + ")", (char)0, copy[i]);
392 Array.Copy(orig, copy, 2);
393 AssertEquals("#E11", orig[0], copy[0]);
394 AssertEquals("#E12", orig[1], copy[1]);
395 Assert("#E13", orig[2] != copy[2]);
396 Assert("#E14", orig[3] != copy[3]);
400 public void TestCopy2() {
402 bool errorThrown = false;
404 Char[] c1 = new Char[2];
405 Char[] c2 = new Char[2];
406 Array.Copy(c2, 1, c1, 0, 2);
407 } catch (ArgumentException) {
410 Assert("#E31", errorThrown);
413 bool errorThrown = false;
415 Char[] c1 = new Char[2];
416 Char[] c2 = new Char[2];
417 Array.Copy(c2, 0, c1, 1, 2);
418 } catch (ArgumentException) {
421 Assert("#E32", errorThrown);
424 char[] orig = {'a', 'b', 'd', 'a'};
425 char[] copy = new Char[4];
426 Array.Copy(orig, 1, copy, 1, 3);
427 Assert("#E33", copy[0] != orig[0]);
428 for (int i = 1; i < orig.Length; i++) {
429 AssertEquals("#E34(" + i + ")", orig[i], copy[i]);
431 Array.Clear(copy, 0, copy.Length);
432 Array.Copy(orig, 1, copy, 0, 2);
433 AssertEquals("#E35", orig[1], copy[0]);
434 AssertEquals("#E36", orig[2], copy[1]);
435 Assert("#E37", copy[2] != orig[2]);
436 Assert("#E38", copy[3] != orig[3]);
440 public void TestCopyTo() {
442 bool errorThrown = false;
444 Char[] c1 = new Char[2];
446 } catch (ArgumentNullException) {
449 Assert("#E61", errorThrown);
452 bool errorThrown = false;
454 Char[] c1 = new Char[2];
455 Char[,] c2 = new Char[2,2];
457 } catch (ArgumentException) {
460 #if TARGET_JVM // This is really implementation dependent behaviour.
461 catch (RankException) {
465 Assert("#E62", errorThrown);
468 bool errorThrown = false;
470 Char[,] c1 = new Char[2,2];
471 Char[] c2 = new Char[2];
473 } catch (RankException) {
476 Assert("#E63", errorThrown);
479 bool errorThrown = false;
481 Char[,] c1 = new Char[2,2];
482 Char[] c2 = new Char[2];
484 } catch (RankException) {
487 Assert("#E64", errorThrown);
490 bool errorThrown = false;
492 Char[] c1 = new Char[2];
493 Char[] c2 = new Char[2];
495 } catch (ArgumentOutOfRangeException) {
498 Assert("#E65", errorThrown);
501 bool errorThrown = false;
503 Char[] c1 = new Char[2];
504 Char[] c2 = new Char[2];
506 } catch (ArgumentException) {
509 Assert("#E66", errorThrown);
512 bool errorThrown = false;
514 Char[] c1 = new Char[2];
515 Char[] c2 = new Char[2];
517 } catch (ArgumentException) {
520 Assert("#E67", errorThrown);
524 bool errorThrown = false;
526 String[] c1 = new String[2];
527 // TODO: this crashes mono if there are null
528 // values in the array.
531 Char[] c2 = new Char[2];
535 } catch (ArrayTypeMismatchException) {
538 Assert("#E68", errorThrown);
541 Char[] orig = {'a', 'b', 'c', 'd'};
542 Char[] copy = new Char[10];
543 Array.Clear(copy, 0, copy.Length);
544 orig.CopyTo(copy, 3);
545 AssertEquals("#E69", (char)0, copy[0]);
546 AssertEquals("#E70", (char)0, copy[1]);
547 AssertEquals("#E71", (char)0, copy[2]);
548 AssertEquals("#E72", orig[0], copy[3]);
549 AssertEquals("#E73", orig[1], copy[4]);
550 AssertEquals("#E74", orig[2], copy[5]);
551 AssertEquals("#E75", orig[3], copy[6]);
552 AssertEquals("#E76", (char)0, copy[7]);
553 AssertEquals("#E77", (char)0, copy[8]);
554 AssertEquals("#E78", (char)0, copy[9]);
557 // The following is valid and must not throw an exception.
558 bool errorThrown = false;
560 int[] src = new int [0];
561 int[] dest = new int [0];
562 src.CopyTo (dest, 0);
563 } catch (ArgumentException) {
566 Assert("#E79", !errorThrown);
571 bool errorThrown = false;
573 CClass[] src = new CClass [] { new CClass () };
574 BClass[] dest = new BClass [1];
576 src.CopyTo (dest, 0);
578 } catch (ArrayTypeMismatchException) {
581 Assert("#E80", errorThrown);
586 public void TestCreateInstance() {
588 bool errorThrown = false;
590 Array.CreateInstance(null, 12);
591 } catch (ArgumentNullException) {
594 Assert("#F01", errorThrown);
597 bool errorThrown = false;
599 Array.CreateInstance(Type.GetType("System.Char"), -3);
600 } catch (ArgumentOutOfRangeException) {
603 Assert("#F02", errorThrown);
606 bool errorThrown = false;
608 Array.CreateInstance(Type.GetType("System.Char"), (int [])null);
609 } catch (ArgumentNullException) {
612 Assert("#F03a", errorThrown);
616 bool errorThrown = false;
618 Array.CreateInstance(Type.GetType("System.Char"), (int [])null);
619 } catch (ArgumentNullException) {
622 Assert("#F03b", errorThrown);
625 #if !TARGET_JVM // Arrays lower bounds are not supported for TARGET_JVM
627 bool errorThrown = false;
629 Array.CreateInstance(Type.GetType("System.Char"), null, null);
630 } catch (ArgumentNullException) {
633 Assert("#F04", errorThrown);
637 bool errorThrown = false;
639 int[] lengths = new int [0];
640 Array.CreateInstance(Type.GetType("System.Char"), lengths);
641 } catch (ArgumentException) {
644 Assert("#F05", errorThrown);
646 #if !TARGET_JVM // CreateInstance with lower bounds not supported for TARGET_JVM
648 bool errorThrown = false;
650 int[] lengths = new int [1];
651 int[] bounds = new int [2];
652 Array.CreateInstance(Type.GetType("System.Char"), lengths, bounds);
654 } catch (ArgumentException) {
657 Assert("#F06", errorThrown);
660 char[] c1 = (char[])Array.CreateInstance(Type.GetType("System.Char"), 12);
661 AssertEquals("#F07", 12, c1.Length);
663 Array c2 = Array.CreateInstance(Type.GetType("System.Char"), 12, 5);
664 AssertEquals("#F08", 2, c2.Rank);
665 AssertEquals("#F09", 60, c2.Length);
669 int[] lengths = { 3 };
670 int[] bounds = { 5 };
671 int[] src = { 512, 718, 912 };
672 Array array = Array.CreateInstance(typeof(int), lengths, bounds);
674 AssertEquals("#F10", 3, array.Length);
675 AssertEquals("#F11", 5, array.GetLowerBound(0));
676 AssertEquals("#F12", 7, array.GetUpperBound(0));
678 src.CopyTo (array, 5);
680 for (int i = 0; i < src.Length; i++)
681 AssertEquals("#F13(" + i + ")", src[i], array.GetValue(i+5));
684 // Test that a 1 dimensional array with 0 lower bound is the
685 // same as an szarray
686 Type szarrayType = new int [10].GetType ();
687 Assert (szarrayType == (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0})).GetType ());
688 Assert (szarrayType != (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {1})).GetType ());
693 [ExpectedException (typeof (ArgumentNullException))]
694 public void TestCreateInstance2 ()
696 Array.CreateInstance (typeof (Int32), (int[])null);
701 [ExpectedException (typeof (ArgumentNullException))]
703 [ExpectedException (typeof (NullReferenceException))]
705 public void TestCreateInstance2b ()
707 Array.CreateInstance (typeof (Int32), (long[])null);
711 public void TestGetEnumerator() {
712 String[] s1 = {"this", "is", "a", "test"};
713 IEnumerator en = s1.GetEnumerator ();
714 AssertNotNull ("#G01", en);
716 Assert ("#G02", en.MoveNext ());
717 AssertEquals ("#G03", "this", en.Current);
718 Assert ("#G04", en.MoveNext ());
719 AssertEquals ("#G05", "is", en.Current);
720 Assert ("#G06", en.MoveNext ());
721 AssertEquals ("#G07", "a", en.Current);
722 Assert ("#G08", en.MoveNext ());
723 AssertEquals ("#G09", "test", en.Current);
724 Assert ("#G10", !en.MoveNext ());
727 Assert("#G11", en.MoveNext ());
728 AssertEquals ("#G12", "this", en.Current);
730 // mutation does not invalidate array enumerator!
731 s1.SetValue ("change", 1);
732 Assert ("#G13", en.MoveNext ());
733 AssertEquals ("#G14", "change", en.Current);
737 public void TestGetEnumeratorMultipleDimension() {
738 String[,] s1 = {{"this", "is"}, {"a", "test"}};
739 IEnumerator en = s1.GetEnumerator ();
740 AssertNotNull ("#AA01", en);
742 Assert ("#AA02", en.MoveNext ());
743 AssertEquals ("#AA03", "this", en.Current);
744 Assert ("#AA04", en.MoveNext ());
745 AssertEquals ("#AA05", "is", en.Current);
746 Assert ("#AA06", en.MoveNext ());
747 AssertEquals ("#AA07", "a", en.Current);
748 Assert ("#AA08", en.MoveNext ());
749 AssertEquals ("#AA09", "test", en.Current);
750 Assert ("#AA10", !en.MoveNext ());
753 Assert("#AA11", en.MoveNext ());
754 AssertEquals ("#AA12", "this", en.Current);
757 // mutation does not invalidate array enumerator!
758 s1.SetValue ("change", idxs);
759 Assert ("#AA13", en.MoveNext ());
760 AssertEquals ("#AA14", "change", en.Current);
764 [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
765 public void TestGetEnumeratorNonZeroLowerBounds() {
766 int[] myLengthsArray = new int[2] { 3, 5 };
767 int[] myBoundsArray = new int[2] { 2, 3 };
769 Array myArray=Array.CreateInstance( typeof(String), myLengthsArray, myBoundsArray );
770 for ( int i = myArray.GetLowerBound(0); i <= myArray.GetUpperBound(0); i++ )
771 for ( int j = myArray.GetLowerBound(1); j <= myArray.GetUpperBound(1); j++ ) {
772 int[] myIndicesArray = new int[2] { i, j };
773 myArray.SetValue( Convert.ToString(i) + j, myIndicesArray );
775 IEnumerator en = myArray.GetEnumerator ();
776 AssertNotNull ("#AB01", en);
778 // check the first couple of values
779 Assert ("#AB02", en.MoveNext ());
780 AssertEquals ("#AB03", "23", en.Current);
781 Assert ("#AB04", en.MoveNext ());
782 AssertEquals ("#AB05", "24", en.Current);
784 // then check the last element's value
787 lastElement = (string)en.Current;
788 } while (en.MoveNext());
789 AssertEquals ("#AB06", "47", lastElement);
793 [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
794 public void TestIList_Add () {
795 int[] myLengthsArray = new int[2] { 3, 5 };
796 int[] myBoundsArray = new int[2] { 2, 3 };
798 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
800 ((IList)myArray).Add ("can not");
801 Fail ("IList.Add should throw");
803 catch (NotSupportedException) {
807 Fail ("IList.Add threw wrong exception type");
810 Fail("IList.Add shouldn't get this far");
814 [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
815 public void TestIList_Insert () {
816 int[] myLengthsArray = new int[2] { 3, 5 };
817 int[] myBoundsArray = new int[2] { 2, 3 };
819 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
821 ((IList)myArray).Insert (0, "can not");
822 Fail ("IList.Insert should throw");
824 catch (NotSupportedException) {
828 Fail ("IList.Insert threw wrong exception type");
831 Fail("IList.Insert shouldn't get this far");
835 [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
836 public void TestIList_Remove () {
837 int[] myLengthsArray = new int[2] { 3, 5 };
838 int[] myBoundsArray = new int[2] { 2, 3 };
840 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
842 ((IList)myArray).Remove ("can not");
843 Fail ("IList.Remove should throw");
845 catch (NotSupportedException) {
849 Fail ("IList.Remove threw wrong exception type");
852 Fail("IList.Remove shouldn't get this far");
856 [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
857 public void TestIList_RemoveAt () {
858 int[] myLengthsArray = new int[2] { 3, 5 };
859 int[] myBoundsArray = new int[2] { 2, 3 };
861 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
863 ((IList)myArray).RemoveAt (0);
864 Fail ("IList.RemoveAt should throw");
866 catch (NotSupportedException) {
870 Fail ("IList.RemoveAt threw wrong exception type");
873 Fail("IList.RemoveAt shouldn't get this far");
877 [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
878 public void TestIList_Contains () {
879 int[] myLengthsArray = new int[2] { 3, 5 };
880 int[] myBoundsArray = new int[2] { 2, 3 };
882 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
885 bool b = ((IList)myArray).Contains ("23");
886 Fail("IList.Contains should throw with multi-dimensional arrays");
888 catch (RankException) {
889 int[] iArr = new int[3] { 1, 2, 3};
890 // check the first and last items
891 Assert("AC01", ((IList)iArr).Contains (1));
892 Assert("AC02", ((IList)iArr).Contains (3));
894 // and one that is definately not there
895 Assert("AC03", !((IList)iArr).Contains (42));
899 Fail("Should not get here");
903 [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
904 public void TestIList_IndexOf () {
905 int[] myLengthsArray = new int[2] { 3, 5 };
906 int[] myBoundsArray = new int[2] { 2, 3 };
908 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
911 bool b = ((IList)myArray).Contains ("23");
912 Fail("IList.Contains should throw with multi-dimensional arrays");
914 catch (RankException) {
915 int[] iArr = new int[3] { 1, 2, 3};
916 // check the first and last items
917 AssertEquals("AD01", 0, ((IList)iArr).IndexOf (1));
918 AssertEquals("AD02", 2, ((IList)iArr).IndexOf (3));
920 // and one that is definately not there
921 AssertEquals("AD03", -1, ((IList)iArr).IndexOf (42));
923 catch (Exception e) {
924 Fail("Unexpected exception: " + e.ToString());
927 // check that wierd case whem lowerbound is Int32.MinValue,
928 // so that IndexOf() needs to return Int32.MaxValue when it cannot find the object
929 int[] myLengthArray = new int[1] { 3 };
930 int[] myBoundArray = new int[1] { Int32.MinValue };
931 Array myExtremeArray=Array.CreateInstance ( typeof(String), myLengthArray, myBoundArray );
932 AssertEquals("AD04", Int32.MaxValue, ((IList)myExtremeArray).IndexOf (42));
937 public void TestGetLength() {
939 bool errorThrown = false;
941 char[] c1 = {'a', 'b', 'c'};
943 } catch (IndexOutOfRangeException) {
946 Assert("#H01", errorThrown);
949 bool errorThrown = false;
951 char[] c1 = {'a', 'b', 'c'};
953 } catch (IndexOutOfRangeException) {
956 Assert("#H02", errorThrown);
959 char[] c2 = new Char[5];
960 AssertEquals("#H03", 5, c2.GetLength(0));
962 char[,] c3 = new Char[6,7];
963 AssertEquals("#H04", 6, c3.GetLength(0));
964 AssertEquals("#H05", 7, c3.GetLength(1));
968 public void TestGetLowerBound() {
970 bool errorThrown = false;
972 char[] c = {'a', 'b', 'c'};
974 } catch (IndexOutOfRangeException) {
977 Assert("#H31", errorThrown);
980 bool errorThrown = false;
982 char[] c = {'a', 'b', 'c'};
984 } catch (IndexOutOfRangeException) {
987 Assert("#H32", errorThrown);
990 char[] c1 = new Char[5];
991 AssertEquals("#H33", 0, c1.GetLowerBound(0));
993 char[,] c2 = new Char[4,4];
994 AssertEquals("#H34", 0, c2.GetLowerBound(0));
995 AssertEquals("#H35", 0, c2.GetLowerBound(1));
999 public void TestGetUpperBound() {
1001 bool errorThrown = false;
1003 char[] c = {'a', 'b', 'c'};
1004 c.GetUpperBound(-1);
1005 } catch (IndexOutOfRangeException) {
1008 Assert("#H61", errorThrown);
1011 bool errorThrown = false;
1013 char[] c = {'a', 'b', 'c'};
1015 } catch (IndexOutOfRangeException) {
1018 Assert("#H62", errorThrown);
1021 char[] c1 = new Char[5];
1022 AssertEquals("#H63", 4, c1.GetUpperBound(0));
1024 char[,] c2 = new Char[4,6];
1025 AssertEquals("#H64", 3, c2.GetUpperBound(0));
1026 AssertEquals("#H65", 5, c2.GetUpperBound(1));
1030 public void TestGetValue1() {
1032 bool errorThrown = false;
1034 char[,] c = new Char[2,2];
1036 } catch (ArgumentException) {
1039 Assert("#I01", errorThrown);
1042 bool errorThrown = false;
1044 char[] c = {'a', 'b', 'c'};
1046 } catch (IndexOutOfRangeException) {
1049 Assert("#I02", errorThrown);
1052 bool errorThrown = false;
1054 char[] c = {'a', 'b', 'c'};
1056 } catch (IndexOutOfRangeException) {
1059 Assert("#I03", errorThrown);
1062 char[] c1 = {'a', 'b', 'c', 'd'};
1063 for (int i = 0; i < c1.Length; i++) {
1064 AssertEquals("#I04(" + i + ")", c1[i], c1.GetValue(i));
1069 public void TestGetValue2() {
1071 bool errorThrown = false;
1073 char[] c = new Char[2];
1075 } catch (ArgumentException) {
1078 Assert("#I21", errorThrown);
1081 bool errorThrown = false;
1083 char[,] c = new Char[2,2];
1085 } catch (IndexOutOfRangeException) {
1088 Assert("#I22", errorThrown);
1091 bool errorThrown = false;
1093 char[,] c = new Char[2,2];
1095 } catch (IndexOutOfRangeException) {
1098 Assert("#I23", errorThrown);
1101 char[,] c1 = new Char[4,6];
1102 for (int i = 0; i < 24; i++) {
1105 c1[first,second] = (char)(((int)'a')+i);
1107 for (int i = 0; i < c1.GetLength(0); i++) {
1108 for (int j = 0; j < c1.GetLength(1); j++) {
1109 AssertEquals("#I24(" + i + "," + j + ")",
1110 c1[i,j], c1.GetValue(i, j));
1116 public void TestGetValue3() {
1118 bool errorThrown = false;
1120 char[] c = new Char[2];
1122 } catch (ArgumentException) {
1125 Assert("#I41", errorThrown);
1128 bool errorThrown = false;
1130 char[,,] c = new Char[2,2,2];
1131 c.GetValue(-1, 1, 1);
1132 } catch (IndexOutOfRangeException) {
1135 Assert("#I42", errorThrown);
1138 bool errorThrown = false;
1140 char[,,] c = new Char[2,2,2];
1142 } catch (IndexOutOfRangeException) {
1145 Assert("#I43", errorThrown);
1148 char[,,] c1 = new Char[4,2,3];
1149 for (int i = 0; i < 24; i++) {
1151 int remains = i % 6;
1152 int second = remains / 3;
1153 int third = remains % 3;
1154 c1[first,second, third] = (char)(((int)'a')+i);
1156 for (int i = 0; i < c1.GetLength(0); i++) {
1157 for (int j = 0; j < c1.GetLength(1); j++) {
1158 for (int k = 0; k < c1.GetLength(2); k++) {
1159 AssertEquals("#I44(" + i + "," + j + ")",
1160 c1[i,j,k], c1.GetValue(i,j,k));
1168 [ExpectedException (typeof (ArgumentNullException))]
1170 [ExpectedException (typeof (NullReferenceException))]
1172 public void TestGetValueLongArray ()
1174 char[] c = new Char[2];
1175 c.GetValue((long [])null);
1179 public void TestGetValueN() {
1181 bool errorThrown = false;
1183 char[] c = new Char[2];
1184 c.GetValue((int [])null);
1185 } catch (ArgumentNullException) {
1188 Assert("#I61a", errorThrown);
1191 bool errorThrown = false;
1193 char[] c = new Char[2];
1194 int[] coords = {1, 1};
1196 } catch (ArgumentException) {
1199 Assert("#I62", errorThrown);
1202 bool errorThrown = false;
1204 char[,] c = new Char[2,2];
1205 int[] coords = {-1, 1};
1207 } catch (IndexOutOfRangeException) {
1210 Assert("#I63", errorThrown);
1213 bool errorThrown = false;
1215 char[,] c = new Char[2,2];
1216 int[] coords = {4, 1};
1218 } catch (IndexOutOfRangeException) {
1221 Assert("#I64", errorThrown);
1224 char[,] c1 = new Char[4,6];
1225 for (int i = 0; i < 24; i++) {
1228 c1[first,second] = (char)(((int)'a')+i);
1230 for (int i = 0; i < c1.GetLength(0); i++) {
1231 for (int j = 0; j < c1.GetLength(1); j++) {
1232 int[] coords = {i, j};
1233 AssertEquals("#I65(" + i + "," + j + ")",
1234 c1[i,j], c1.GetValue(coords));
1240 public void TestIndexOf1() {
1242 bool errorThrown = false;
1244 Array.IndexOf(null, "huh?");
1245 } catch (ArgumentNullException) {
1248 Assert("#J01", errorThrown);
1251 bool errorThrown = false;
1253 char[,] c = new Char[2,2];
1254 Array.IndexOf(c, "huh?");
1255 } catch (RankException) {
1258 Assert("#J02", errorThrown);
1261 String[] s1 = {"this", "is", "a", "test"};
1262 AssertEquals("#J03", -1, Array.IndexOf(s1, null));
1263 AssertEquals("#J04", -1, Array.IndexOf(s1, "nothing"));
1264 AssertEquals("#J05", 0, Array.IndexOf(s1, "this"));
1265 AssertEquals("#J06", 3, Array.IndexOf(s1, "test"));
1269 public void TestIndexOf2() {
1271 bool errorThrown = false;
1273 Array.IndexOf(null, "huh?", 0);
1274 } catch (ArgumentNullException) {
1277 Assert("#J21", errorThrown);
1280 bool errorThrown = false;
1282 char[,] c = new Char[2,2];
1283 Array.IndexOf(c, "huh?", 0);
1284 } catch (RankException) {
1287 Assert("#J22", errorThrown);
1290 bool errorThrown = false;
1292 char[] c = new Char[2];
1293 Array.IndexOf(c, "huh?", 3);
1294 } catch (ArgumentOutOfRangeException) {
1297 Assert("#J23", errorThrown);
1300 String[] s1 = {"this", "is", "really", "a", "test"};
1301 AssertEquals("#J24", -1, Array.IndexOf(s1, null, 1));
1302 AssertEquals("#J25", -1, Array.IndexOf(s1, "nothing", 1));
1303 AssertEquals("#J26", -1, Array.IndexOf(s1, "this", 1));
1304 AssertEquals("#J27", 1, Array.IndexOf(s1, "is", 1));
1305 AssertEquals("#J28", 4, Array.IndexOf(s1, "test", 1));
1309 public void TestIndexOf3() {
1311 bool errorThrown = false;
1313 Array.IndexOf(null, "huh?", 0, 1);
1314 } catch (ArgumentNullException) {
1317 Assert("#J41", errorThrown);
1320 bool errorThrown = false;
1322 char[,] c = new Char[2,2];
1323 Array.IndexOf(c, "huh?", 0, 1);
1324 } catch (RankException) {
1327 Assert("#J42", errorThrown);
1330 bool errorThrown = false;
1332 char[] c = new Char[2];
1333 Array.IndexOf(c, "huh?", 3, 1);
1334 } catch (ArgumentOutOfRangeException) {
1337 Assert("#J43", errorThrown);
1340 bool errorThrown = false;
1342 char[] c = new Char[2];
1343 Array.IndexOf(c, "huh?", 0, 5);
1344 } catch (ArgumentOutOfRangeException) {
1347 Assert("#J44", errorThrown);
1350 String[] s1 = {"this", "is", "really", "a", "test"};
1351 AssertEquals("#J45", -1, Array.IndexOf(s1, null, 1, 3));
1352 AssertEquals("#J46", -1, Array.IndexOf(s1, "nothing", 1, 3));
1353 AssertEquals("#J47", -1, Array.IndexOf(s1, "this", 1, 3));
1354 AssertEquals("#J48", 1, Array.IndexOf(s1, "is", 1, 3));
1355 AssertEquals("#J49", -1, Array.IndexOf(s1, "test", 1, 3));
1356 AssertEquals("#J50", 3, Array.IndexOf(s1, "a", 1, 3));
1360 public void TestLastIndexOf1() {
1362 bool errorThrown = false;
1364 Array.LastIndexOf(null, "huh?");
1365 } catch (ArgumentNullException) {
1368 Assert("#K01", errorThrown);
1371 bool errorThrown = false;
1373 char[,] c = new Char[2,2];
1374 Array.LastIndexOf(c, "huh?");
1375 } catch (RankException) {
1378 Assert("#K02", errorThrown);
1381 String[] s1 = {"this", "is", "a", "a", "test"};
1382 AssertEquals("#K03", -1, Array.LastIndexOf(s1, null));
1383 AssertEquals("#K04", -1, Array.LastIndexOf(s1, "nothing"));
1384 AssertEquals("#K05", 0, Array.LastIndexOf(s1, "this"));
1385 AssertEquals("#K06", 4, Array.LastIndexOf(s1, "test"));
1386 AssertEquals("#K07", 3, Array.LastIndexOf(s1, "a"));
1390 public void TestLastIndexOf2() {
1392 bool errorThrown = false;
1394 Array.LastIndexOf(null, "huh?", 0);
1395 } catch (ArgumentNullException) {
1398 Assert("#K21", errorThrown);
1401 bool errorThrown = false;
1403 char[,] c = new Char[2,2];
1404 Array.LastIndexOf(c, "huh?", 0);
1405 } catch (RankException) {
1408 Assert("#K22", errorThrown);
1411 bool errorThrown = false;
1413 char[] c = new Char[2];
1414 Array.LastIndexOf(c, "huh?", 3);
1415 } catch (ArgumentOutOfRangeException) {
1418 Assert("#K23", errorThrown);
1421 String[] s1 = {"this", "is", "really", "a", "test"};
1422 AssertEquals("#K24", -1, Array.LastIndexOf(s1, null, 3));
1423 AssertEquals("#K25", -1, Array.LastIndexOf(s1, "nothing", 3));
1424 AssertEquals("#K26", -1, Array.LastIndexOf(s1, "test", 3));
1425 AssertEquals("#K27", 3, Array.LastIndexOf(s1, "a", 3));
1426 AssertEquals("#K28", 0, Array.LastIndexOf(s1, "this", 3));
1430 public void TestLastIndexOf3() {
1432 bool errorThrown = false;
1434 Array.LastIndexOf(null, "huh?", 0, 1);
1435 } catch (ArgumentNullException) {
1438 Assert("#K41", errorThrown);
1441 bool errorThrown = false;
1443 char[,] c = new Char[2,2];
1444 Array.LastIndexOf(c, "huh?", 0, 1);
1445 } catch (RankException) {
1448 Assert("#K42", errorThrown);
1451 bool errorThrown = false;
1453 char[] c = new Char[2];
1454 Array.LastIndexOf(c, "huh?", 3, 1);
1455 } catch (ArgumentOutOfRangeException) {
1458 Assert("#K43", errorThrown);
1461 bool errorThrown = false;
1463 char[] c = new Char[2];
1464 Array.LastIndexOf(c, "huh?", 0, 5);
1465 } catch (ArgumentOutOfRangeException) {
1468 Assert("#K44", errorThrown);
1471 String[] s1 = {"this", "is", "really", "a", "test"};
1472 AssertEquals("#K45", -1, Array.LastIndexOf(s1, null, 3, 3));
1473 AssertEquals("#K46", -1, Array.LastIndexOf(s1, "nothing", 3, 3));
1474 AssertEquals("#K47", -1, Array.LastIndexOf(s1, "this", 3, 3));
1475 AssertEquals("#K48", 1, Array.LastIndexOf(s1, "is", 3, 3));
1476 AssertEquals("#K49", -1, Array.LastIndexOf(s1, "test", 3, 3));
1477 AssertEquals("#K50", 3, Array.LastIndexOf(s1, "a", 3, 3));
1481 [ExpectedException (typeof (ArgumentOutOfRangeException))]
1482 public void TestLastIndexOf4 ()
1484 short [] a = new short [] { 19, 238, 317, 6, 565, 0, -52, 60, -563, 753, 238, 238};
1485 Array.LastIndexOf (a, 16, -1);
1489 public void TestLastIndexOf5 ()
1491 char [] a = new char [] {'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a', 'j', 'i', 'h'};
1496 for (int i = a.Length - 1; i >= 0 ; i--) {
1498 retval = Array.LastIndexOf(a, a [i], i, i + 1);
1506 [ExpectedException (typeof (ArgumentOutOfRangeException))]
1507 public void LastIndexOf_StartIndexOverflow ()
1509 // legal - no exception
1510 byte[] array = new byte [16];
1511 Array.LastIndexOf (array, this, Int32.MaxValue, 1);
1515 [ExpectedException (typeof (ArgumentOutOfRangeException))]
1516 public void LastIndexOf_CountOverflow ()
1518 // legal - no exception
1519 byte[] array = new byte [16];
1520 Array.LastIndexOf (array, this, 1, Int32.MaxValue);
1524 public void TestReverse() {
1526 bool errorThrown = false;
1528 Array.Reverse(null);
1529 } catch (ArgumentNullException) {
1532 Assert("#L01", errorThrown);
1535 bool errorThrown = false;
1537 char[,] c = new Char[2,2];
1539 } catch (RankException) {
1542 Assert("#L02", errorThrown);
1545 char[] c1 = {'a', 'b', 'c', 'd'};
1547 AssertEquals("#L03", 'd', c1[0]);
1548 AssertEquals("#L04", 'c', c1[1]);
1549 AssertEquals("#L05", 'b', c1[2]);
1550 AssertEquals("#L06", 'a', c1[3]);
1553 bool errorThrown = false;
1555 Array.Reverse(null, 0, 0);
1556 } catch (ArgumentNullException) {
1559 Assert("#L07", errorThrown);
1562 bool errorThrown = false;
1564 char[,] c = new Char[2,2];
1565 Array.Reverse(c, 0, 0);
1566 } catch (RankException) {
1569 Assert("#L08", errorThrown);
1572 //bool errorThrown = false;
1574 // char[] c = new Char[2];
1575 // Array.Reverse(c, 0, 3);
1576 //} catch (ArgumentOutOfRangeException) {
1577 // errorThrown = true;
1579 //Assert("#L09", errorThrown);
1582 //bool errorThrown = false;
1584 // char[] c = new Char[2];
1585 // Array.Reverse(c, 3, 0);
1586 //} catch (ArgumentOutOfRangeException) {
1587 // errorThrown = true;
1589 //Assert("#L10", errorThrown);
1592 char[] c2 = { 'a', 'b', 'c', 'd'};
1593 Array.Reverse(c2, 1, 2);
1594 AssertEquals("#L11", 'a', c2[0]);
1595 AssertEquals("#L12", 'c', c2[1]);
1596 AssertEquals("#L13", 'b', c2[2]);
1597 AssertEquals("#L14", 'd', c2[3]);
1601 public void TestSetValue1() {
1603 bool errorThrown = false;
1605 char[,] c = new Char[2,2];
1606 c.SetValue("buh", 1);
1607 } catch (ArgumentException) {
1610 Assert("#M01", errorThrown);
1613 bool errorThrown = false;
1615 char[] c = {'a', 'b', 'c'};
1616 c.SetValue("buh", -1);
1617 } catch (IndexOutOfRangeException) {
1620 Assert("#M02", errorThrown);
1623 bool errorThrown = false;
1625 char[] c = {'a', 'b', 'c'};
1626 c.SetValue("buh", 4);
1627 } catch (IndexOutOfRangeException) {
1630 Assert("#M03", errorThrown);
1633 char[] c1 = {'a', 'b', 'c', 'd'};
1634 char[] c2 = new char[4];
1635 for (int i = 0; i < c1.Length; i++) {
1636 c2.SetValue(c1[i], i);
1638 for (int i = 0; i < c1.Length; i++) {
1639 AssertEquals("#M04(" + i + ")", c1[i], c2[i]);
1642 int[] c3 = { 1, 2, 3 };
1643 long[] c4 = new long [3];
1645 for (int i = 0; i < c3.Length; i++)
1646 c4.SetValue (c3 [i], i);
1650 } catch (Exception e) {
1651 Fail ("c3.CopyTo(): e=" + e);
1653 for (int i = 0; i < c3.Length; i++)
1654 Assert ("#M05(" + i + ")", c3[i] == c4[i]);
1656 Object[] c5 = new Object [3];
1657 long[] c6 = new long [3];
1661 } catch (Exception e) {
1662 Fail ("c4.CopyTo(): e=" + e);
1667 } catch (Exception e) {
1668 Fail ("c5.CopyTo(): e=" + e);
1670 // for (int i = 0; i < c5.Length; i++)
1671 // Assert ("#M06(" + i + ")", c5[i] == c6[i]);
1675 public void TestSetValue2() {
1677 bool errorThrown = false;
1679 char[] c = new Char[2];
1680 c.SetValue("buh", 1,1);
1681 } catch (ArgumentException) {
1684 Assert("#M21", errorThrown);
1687 bool errorThrown = false;
1689 char[,] c = new Char[2,2];
1690 c.SetValue("buh", -1, 1);
1691 } catch (IndexOutOfRangeException) {
1694 Assert("#M22", errorThrown);
1697 bool errorThrown = false;
1699 char[,] c = new Char[2,2];
1700 c.SetValue("buh", 4,1);
1701 } catch (IndexOutOfRangeException) {
1704 Assert("#M23", errorThrown);
1707 char[,] c1 = new Char[4,6];
1708 char[,] c2 = new Char[4,6];
1709 for (int i = 0; i < 24; i++) {
1712 c1[first,second] = (char)(((int)'a')+i);
1713 c2.SetValue(c1[first,second], first, second);
1715 for (int i = 0; i < c1.GetLength(0); i++) {
1716 for (int j = 0; j < c1.GetLength(1); j++) {
1717 AssertEquals("#M24(" + i + "," + j + ")",
1724 public void TestSetValue3() {
1726 bool errorThrown = false;
1728 char[] c = new Char[2];
1729 c.SetValue("buh", 1,1,1);
1730 } catch (ArgumentException) {
1733 Assert("#M41", errorThrown);
1736 bool errorThrown = false;
1738 char[,,] c = new Char[2,2,2];
1739 c.SetValue("buh", -1, 1, 1);
1740 } catch (IndexOutOfRangeException) {
1743 Assert("#M42", errorThrown);
1746 bool errorThrown = false;
1748 char[,,] c = new Char[2,2,2];
1749 c.SetValue("buh", 4,1,1);
1750 } catch (IndexOutOfRangeException) {
1753 Assert("#M43", errorThrown);
1756 char[,,] c1 = new Char[4,2,3];
1757 char[,,] c2 = new Char[4,2,3];
1758 for (int i = 0; i < 24; i++) {
1760 int remains = i % 6;
1761 int second = remains / 3;
1762 int third = remains % 3;
1763 c1[first,second, third] = (char)(((int)'a')+i);
1764 c2.SetValue(c1[first, second, third], first, second, third);
1766 for (int i = 0; i < c1.GetLength(0); i++) {
1767 for (int j = 0; j < c1.GetLength(1); j++) {
1768 for (int k = 0; k < c1.GetLength(2); k++) {
1769 AssertEquals("#M44(" + i + "," + j + " )",
1770 c1[i,j,k], c2[i,j,k]);
1778 [ExpectedException (typeof (ArgumentNullException))]
1780 [ExpectedException (typeof (NullReferenceException))]
1782 public void TestSetValueLongArray ()
1784 char[] c = new Char[2];
1785 c.SetValue("buh", (long [])null);
1789 public void TestSetValueN() {
1791 bool errorThrown = false;
1793 char[] c = new Char[2];
1794 c.SetValue("buh", (int [])null);
1795 } catch (ArgumentNullException) {
1798 Assert("#M61a", errorThrown);
1801 bool errorThrown = false;
1803 char[] c = new Char[2];
1804 int[] coords = {1, 1};
1805 c.SetValue("buh", coords);
1806 } catch (ArgumentException) {
1809 Assert("#M62", errorThrown);
1812 bool errorThrown = false;
1814 char[,] c = new Char[2,2];
1815 int[] coords = {-1, 1};
1816 c.SetValue("buh", coords);
1817 } catch (IndexOutOfRangeException) {
1820 Assert("#M63", errorThrown);
1823 bool errorThrown = false;
1825 char[,] c = new Char[2,2];
1826 int[] coords = {4, 1};
1827 c.SetValue("buh", coords);
1828 } catch (IndexOutOfRangeException) {
1831 Assert("#M64", errorThrown);
1834 char[,] c1 = new Char[4,6];
1835 char[,] c2 = new Char[4,6];
1836 for (int i = 0; i < 24; i++) {
1839 c1[first,second] = (char)(((int)'a')+i);
1840 int[] coords = {first, second};
1841 c2.SetValue(c1[first,second], coords);
1843 for (int i = 0; i < c1.GetLength(0); i++) {
1844 for (int j = 0; j < c1.GetLength(1); j++) {
1845 AssertEquals("#M65(" + i + "," + j + ")",
1852 public void TestSetValue4() {
1854 int[] c1 = { 1, 2, 3 };
1855 long[] c2 = new long [3];
1857 for (int i = 0; i < c1.Length; i++)
1858 c2.SetValue (c1 [i], i);
1860 for (int i = 0; i < c1.Length; i++) {
1861 Assert ("#M81(" + i + ")", c1[i] == c2[i]);
1862 AssertEquals ("#M82(" + i + ")", typeof (long), c2[i].GetType ());
1866 long[] c1 = { 1, 2, 3 };
1867 int[] c2 = new int [3];
1868 bool errorThrown = false;
1870 c2.SetValue (c1 [0], 0);
1871 } catch (ArgumentException) {
1874 Assert("#M83", errorThrown);
1877 int[] c1 = { 1, 2, 3 };
1878 Object[] c2 = new Object [3];
1880 for (int i = 0; i < c1.Length; i++)
1881 c2.SetValue (c1 [i], i);
1883 for (int i = 0; i < c1.Length; i++)
1884 AssertEquals ("#M84(" + i + ")", c1[i], Convert.ToInt32 (c2[i]));
1887 Object[] c1 = new Object [3];
1888 Object[] c2 = new Object [3];
1889 c1[0] = new Object ();
1891 for (int i = 0; i < c1.Length; i++)
1892 c2.SetValue (c1 [i], i);
1894 for (int i = 0; i < c1.Length; i++)
1895 AssertEquals ("#M85(" + i + ")", c1[i], c2[i]);
1898 Object[] c1 = new Object [3];
1899 string[] c2 = new String [3];
1900 string test = "hello";
1903 c2.SetValue (c1 [0], 0);
1904 AssertEquals ("#M86", c1[0], c2[0]);
1905 AssertEquals ("#M87", "hello", c2[0]);
1908 char[] c1 = { 'a', 'b', 'c' };
1909 string[] c2 = new string [3];
1911 c2.SetValue (c1 [0], 0);
1913 } catch (InvalidCastException) {}
1916 Single[] c1 = { 1.2F, 2.3F, 3.4F, 4.5F };
1917 long[] c2 = new long [3];
1919 c2.SetValue (c1 [0], 0);
1921 } catch (ArgumentException) {}
1949 UInt32 v11 = 235354;
1950 UInt64 v12 = 234552;
1952 Object[] va1 = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 };
1953 Object[] va2 = { "true", "1", "a", "-1.2", "-32", "-234", "-34523", "-1",
1954 "-4.8F", "24234", "235354", "234552" };
1956 Object[][] vt = { va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1 };
1959 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1960 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
1961 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
1962 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
1963 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1,
1964 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1,
1965 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1,
1966 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1,
1967 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1,
1968 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
1969 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0,
1970 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0
1975 for (int i = 0; i < types.Length; i++) {
1976 for (int j = 0; j < types.Length; j++) {
1977 Array array = Array.CreateInstance (types [j], 2);
1979 Object value = vt[j][i];
1981 bool errorThrown = false;
1983 array.SetValue (value, 0);
1984 } catch (ArgumentException) {
1988 int ex_index = (i * types.Length) + j;
1990 AssertEquals ("#M90(" + types [i] + "," + types [j] + ")",
1991 errorThrown, arg_ex [ex_index] == 1);
1995 for (int i = 0; i < types.Length; i++) {
1996 String[] array = new String [2];
1998 Object value = va1 [i];
2000 bool errorThrown = false;
2002 array.SetValue (value, 0);
2003 } catch (InvalidCastException) {
2007 Assert ("#M91(" + types [i] + ")", errorThrown);
2010 for (int i = 0; i < types.Length; i++) {
2011 Array array = Array.CreateInstance (types [i], 2);
2013 Object value = va2 [i];
2015 bool errorThrown = false;
2017 array.SetValue (value, 0);
2018 } catch (InvalidCastException) {
2022 Assert ("#M92(" + types [i] + ")", errorThrown);
2025 for (int i = 0; i < types.Length; i++) {
2026 Array array = Array.CreateInstance (types [i], 2);
2028 Object value = null;
2030 bool errorThrown = false;
2032 array.SetValue (value, 0);
2033 } catch (InvalidCastException) {
2037 Assert ("#M93(" + types [i] + ")", !errorThrown);
2042 for (int i = 0; i < types.Length; i++) {
2043 for (int j = 0; j < types.Length; j++) {
2044 Array source = Array.CreateInstance (types [i], 2);
2045 Array array = Array.CreateInstance (types [j], 2);
2047 source.SetValue (vt[j][i], 0);
2048 source.SetValue (vt[j][i], 1);
2050 bool errorThrown = false;
2052 Array.Copy (source, array, 2);
2053 } catch (ArrayTypeMismatchException) {
2057 int ex_index = (i * types.Length) + j;
2059 AssertEquals ("#M94(" + types [i] + "," + types [j] + ")",
2060 errorThrown, arg_ex [ex_index] == 1);
2064 for (int i = 0; i < types.Length; i++) {
2065 Array source = Array.CreateInstance (types [i], 2);
2066 String[] array = new String [2];
2068 source.SetValue (va1 [i], 0);
2069 source.SetValue (va1 [i], 1);
2071 bool errorThrown = false;
2073 Array.Copy (source, array, 2);
2074 } catch (ArrayTypeMismatchException) {
2078 Assert ("#M95(" + types [i] + ")", errorThrown);
2081 for (int i = 0; i < types.Length; i++) {
2082 String[] source = new String [2];
2083 Array array = Array.CreateInstance (types [i], 2);
2085 source.SetValue (va2 [i], 0);
2086 source.SetValue (va2 [i], 1);
2088 bool errorThrown = false;
2090 Array.Copy (source, array, 2);
2091 } catch (ArrayTypeMismatchException) {
2095 Assert ("#M96(" + types [i] + ")", errorThrown);
2101 public void TestSort() {
2103 bool errorThrown = false;
2106 } catch (ArgumentNullException) {
2109 Assert("#N01", errorThrown);
2112 bool errorThrown = false;
2114 Array.Sort(null, 0, 1);
2115 } catch (ArgumentNullException) {
2118 Assert("#N02", errorThrown);
2121 bool errorThrown = false;
2123 char[] c1 = new Char[2];
2124 Array.Sort(null, c1);
2125 } catch (ArgumentNullException) {
2128 Assert("#N03", errorThrown);
2131 bool errorThrown = false;
2133 char[] c1 = new Char[2];
2134 Array.Sort(null, c1, 0, 1);
2135 } catch (ArgumentNullException) {
2138 Assert("#N04", errorThrown);
2142 char[] arr = {'d', 'b', 'f', 'e', 'a', 'c'};
2145 Array.Sort (null, 0, 1);
2146 Fail ("#N" + tc.ToString ());
2148 catch (ArgumentException) {}
2149 catch (Exception) { Fail ("#N" + tc.ToString ()); }
2153 Array.Sort (arr, -1, 3);
2154 Fail ("#N" + tc.ToString ());
2156 catch (ArgumentException) {}
2157 catch (Exception) { Fail ("#N" + tc.ToString ()); }
2161 Array.Sort (arr, 1, -3);
2162 Fail ("#N" + tc.ToString ());
2164 catch (ArgumentException) {}
2165 catch (Exception) { Fail ("#N" + tc.ToString ()); }
2169 Array.Sort (arr, arr.Length, arr.Length + 2);
2170 Fail ("#N" + tc.ToString ());
2172 catch (ArgumentException) {}
2173 catch (Exception) { Fail ("#N" + tc.ToString ()); }
2176 // note: null second array => just sort first array
2177 char[] starter = {'d', 'b', 'f', 'e', 'a', 'c'};
2178 int[] starter1 = {1,2,3,4,5,6};
2180 char[] c1 = (char[])starter.Clone();
2182 AssertEquals("#N21", 'a', c1[0]);
2183 AssertEquals("#N22", 'b', c1[1]);
2184 AssertEquals("#N23", 'c', c1[2]);
2185 AssertEquals("#N24", 'd', c1[3]);
2186 AssertEquals("#N25", 'e', c1[4]);
2187 AssertEquals("#N26", 'f', c1[5]);
2190 char[] c1 = (char[])starter.Clone();
2191 int[] i1 = (int[])starter1.Clone();
2193 AssertEquals("#N41", 'a', c1[0]);
2194 AssertEquals("#N42", 'b', c1[1]);
2195 AssertEquals("#N43", 'c', c1[2]);
2196 AssertEquals("#N44", 'd', c1[3]);
2197 AssertEquals("#N45", 'e', c1[4]);
2198 AssertEquals("#N46", 'f', c1[5]);
2199 AssertEquals("#N47", 5, i1[0]);
2200 AssertEquals("#N48", 2, i1[1]);
2201 AssertEquals("#N49", 6, i1[2]);
2202 AssertEquals("#N50", 1, i1[3]);
2203 AssertEquals("#N51", 4, i1[4]);
2204 AssertEquals("#N52", 3, i1[5]);
2207 char[] c1 = (char[])starter.Clone();
2208 Array.Sort(c1, 1, 4);
2209 AssertEquals("#N61", 'd', c1[0]);
2210 AssertEquals("#N62", 'a', c1[1]);
2211 AssertEquals("#N63", 'b', c1[2]);
2212 AssertEquals("#N64", 'e', c1[3]);
2213 AssertEquals("#N65", 'f', c1[4]);
2214 AssertEquals("#N66", 'c', c1[5]);
2217 char[] c1 = (char[])starter.Clone();
2218 int[] i1 = (int[])starter1.Clone();
2219 Array.Sort(c1, i1, 1, 4);
2220 AssertEquals("#N81", 'd', c1[0]);
2221 AssertEquals("#N82", 'a', c1[1]);
2222 AssertEquals("#N83", 'b', c1[2]);
2223 AssertEquals("#N84", 'e', c1[3]);
2224 AssertEquals("#N85", 'f', c1[4]);
2225 AssertEquals("#N86", 'c', c1[5]);
2226 AssertEquals("#N87", 1, i1[0]);
2227 AssertEquals("#N88", 5, i1[1]);
2228 AssertEquals("#N89", 2, i1[2]);
2229 AssertEquals("#N90", 4, i1[3]);
2230 AssertEquals("#N91", 3, i1[4]);
2231 AssertEquals("#N92", 6, i1[5]);
2236 public void TestInitializeEmpty()
2248 Assert("#TI01",!catched);
2252 public void TestInitializeInt()
2257 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2259 AssertEquals("#TI02 " + i ,a[i],b[i]);
2264 public void TestInitializeDouble()
2266 double[] a = {1.0,2.0,0.0};
2268 double[] b = {1.0,2.0,0.0};
2269 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2271 AssertEquals("#TI03 " + i ,a[i],b[i]);
2276 public void TestInitializeFloat()
2278 float[] a = {1.0F,2.0F,0.0F};
2280 float[] b = {1.0F,2.0F,0.0F};
2281 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2283 AssertEquals("#TI04 " + i ,a[i],b[i]);
2288 public void TestInitializeChar()
2290 char[] a = {'1','.','0','F','2','.','0','F'};
2292 char[] b = {'1','.','0','F','2','.','0','F'};
2293 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2295 AssertEquals("#TI05 " + i ,a[i],b[i]);
2300 public void TestInitializeString()
2302 string[] a = {"hola","adios","menos","mas"};
2304 string[] b = {"hola","adios","menos","mas"};
2305 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2307 AssertEquals("#TI06 " + i ,a[i],b[i]);
2312 public void TestInitializeEnum()
2314 enua[] a = {enua.hola,enua.adios,enua.menos,enua.mas};
2316 enua[] b = {enua.hola,enua.adios,enua.menos,enua.mas};
2317 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2319 AssertEquals("#TI07 " + i ,a[i],b[i]);
2324 public void TestInitializeIntNI()
2326 int[] a = new int[20];
2330 AssertEquals("#TI08",b,0);
2335 public void TestInitializeCharNI()
2337 char[] a = new char[20];
2339 foreach(char b in a)
2341 AssertEquals("#TI09",b,0);
2346 public void TestInitializeDoubleNI()
2348 double[] a = new double[20];
2350 foreach(double b in a)
2352 AssertEquals("#TI09",b,0.0);
2357 public void TestInitializeStringNI()
2359 string[] a = new string[20];
2361 foreach(string b in a)
2363 AssertEquals("#TI10",b,null);
2368 public void TestInitializeObjectNI()
2370 object[] a = new object[20];
2372 foreach(object b in a)
2374 AssertEquals("#TI11",b,null);
2379 public void TestInitializeAClassNI()
2381 AClass[] a = new AClass[20];
2383 foreach(AClass b in a)
2385 AssertEquals("#TI12",b,null);
2391 public void TestInitializeAStructNI()
2393 AStruct[] a = new AStruct[20];
2395 foreach(AStruct b in a)
2397 AssertEquals("#TI14",b,new AStruct());
2402 public void TestInitializeAStruct()
2404 AStruct[] a = new AStruct[3];
2408 AStruct[] b = new AStruct[3];
2411 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2413 AssertEquals("#TI15 " + i ,a[i],b[i]);
2418 public void TestInitializeDateTimeNI()
2420 DateTime[] a = new DateTime[20];
2422 foreach(DateTime b in a)
2424 AssertEquals("#TI16",b,new DateTime());
2429 [ExpectedException (typeof (ArgumentNullException))]
2430 public void MoreSort1 ()
2432 Array.Sort (null, 0, 1);
2436 [ExpectedException (typeof (ArgumentOutOfRangeException))]
2437 public void MoreSort2 ()
2439 Array.Sort (arrsort, -1, 3);
2443 [ExpectedException (typeof (ArgumentOutOfRangeException))]
2444 public void MoreSort3 ()
2446 Array.Sort (arrsort, 1, -3);
2450 [ExpectedException (typeof (ArgumentException))]
2451 public void MoreSort4 ()
2453 Array.Sort (arrsort, arrsort.Length, arrsort.Length + 2);
2457 [ExpectedException (typeof (RankException))]
2458 public void MoreSort5 ()
2460 char [,] arr = new char [,] {{'a'}, {'b'}};
2461 Array.Sort (arr, 0, 1);
2465 public void MoreSort6 ()
2467 Array.Sort (arrsort, 0, 0);
2471 [ExpectedException (typeof (ArgumentException))]
2472 public void MoreSort7 ()
2474 Array.Sort (arrsort, arrsort.Length - 1, 2);
2478 [ExpectedException (typeof (ArgumentException))]
2479 public void MoreSort8 ()
2481 Array.Sort (arrsort, 0, arrsort.Length + 1);
2485 public void MoreSort9 ()
2487 Array.Sort (arrsort, null, 0, arrsort.Length, null);
2491 [ExpectedException (typeof (InvalidOperationException))]
2492 public void MoreSort10 ()
2494 object [] array = {true, 'k', SByte.MinValue, Byte.MinValue, (short) 2, 634, (long) 436, (float) 1.1, 1.23, "Hello World"};
2495 Array.Sort (array, (IComparer) null);
2498 [Test] // bug #81941
2501 double [] a = new double [2] { 0.9, 0.3 };
2502 uint [] b = new uint [2] { 4, 7 };
2504 AssertEquals ("#1", 0.3, a [0]);
2505 AssertEquals ("#2", 0.9, a [1]);
2506 AssertEquals ("#3", 7, b [0]);
2507 AssertEquals ("#4", 4, b [1]);
2511 public void ClearJaggedArray ()
2513 byte[][] matrix = new byte [8][];
2514 for (int i=0; i < 8; i++) {
2515 matrix [i] = new byte [8];
2516 for (int j=0; j < 8; j++) {
2520 Array.Clear (matrix, 0, 8);
2521 for (int i=0; i < 8; i++) {
2522 AssertNull (i.ToString (), matrix [i]);
2527 public void ClearMultidimentionalArray ()
2529 byte[,] matrix = new byte [2,2] { {1, 1}, {2, 2} };
2530 Array.Clear (matrix, 0, 2);
2531 AssertEquals ("0,0", 0, matrix [0,0]);
2532 AssertEquals ("0,1", 0, matrix [0,1]);
2533 AssertEquals ("1,0", 2, matrix [1,0]);
2534 AssertEquals ("1,1", 2, matrix [1,1]);
2538 [ExpectedException (typeof (IndexOutOfRangeException))]
2539 public void ClearOutsideMultidimentionalArray ()
2541 byte[,] matrix = new byte [2,2] { {1, 1}, {2, 2} };
2542 Array.Clear (matrix, 0, 5);
2546 [ExpectedException (typeof (IndexOutOfRangeException))]
2547 public void Clear_IndexOverflow ()
2549 byte[] array = new byte [16];
2550 Array.Clear (array, 4, Int32.MaxValue);
2554 [ExpectedException (typeof (IndexOutOfRangeException))]
2555 public void Clear_LengthOverflow ()
2557 byte[] array = new byte [16];
2558 Array.Clear (array, Int32.MaxValue, 4);
2562 [ExpectedException (typeof (ArgumentException))]
2563 public void Copy_SourceIndexOverflow ()
2565 byte[] array = new byte [16];
2566 Array.Copy (array, Int32.MaxValue, array, 8, 8);
2570 [ExpectedException (typeof (ArgumentException))]
2571 public void Copy_DestinationIndexOverflow ()
2573 byte[] array = new byte [16];
2574 Array.Copy (array, 8, array, Int32.MaxValue, 8);
2578 [ExpectedException (typeof (ArgumentException))]
2579 public void Copy_LengthOverflow ()
2581 byte[] array = new byte [16];
2582 Array.Copy (array, 8, array, 8, Int32.MaxValue);
2586 [ExpectedException (typeof (ArgumentException))]
2587 public void Reverse_IndexOverflow ()
2589 byte[] array = new byte [16];
2590 Array.Reverse (array, Int32.MaxValue, 8);
2594 [ExpectedException (typeof (ArgumentException))]
2595 public void Reverse_LengthOverflow ()
2597 byte[] array = new byte [16];
2598 Array.Reverse (array, 8, Int32.MaxValue);
2601 public struct CharX : IComparable {
2604 public CharX (char c)
2609 public int CompareTo (object obj)
2612 return c.CompareTo (((CharX) obj).c);
2614 return c.CompareTo (obj);
2619 public void BinarySearch_ArgPassingOrder ()
2622 // This tests that arguments are passed to the comprer in the correct
2623 // order. The IComparable of the *array* elements must get called, not
2624 // that of the search object.
2626 CharX [] x = { new CharX ('a'), new CharX ('b'), new CharX ('c') };
2627 AssertEquals (1, Array.BinarySearch (x, 'b'));
2630 class Comparer: IComparer {
2632 private bool called = false;
2634 public bool Called {
2636 bool result = called;
2642 public int Compare (object x, object y)
2650 public void BinarySearch1_EmptyList ()
2652 int[] array = new int[0];
2653 AssertEquals ("BinarySearch", - 1, Array.BinarySearch (array, 0));
2657 public void BinarySearch2_EmptyList ()
2659 int[] array = new int[0];
2660 AssertEquals ("BinarySearch", -1, Array.BinarySearch (array, 0, 0, 0));
2664 public void BinarySearch3_EmptyList ()
2666 Comparer comparer = new Comparer ();
2667 int[] array = new int[0];
2668 AssertEquals ("BinarySearch", -1, Array.BinarySearch (array, 0, comparer));
2669 // bug 77030 - the comparer isn't called for an empty array/list
2670 Assert ("Called", !comparer.Called);
2674 public void BinarySearch4_EmptyList ()
2676 Comparer comparer = new Comparer ();
2677 int[] array = new int[0];
2678 AssertEquals ("BinarySearch", -1, Array.BinarySearch (array, 0, 0, comparer));
2679 // bug 77030 - the comparer isn't called for an empty array/list
2680 Assert ("Called", !comparer.Called);
2685 [ExpectedException (typeof (ArgumentNullException))]
2686 public void AsReadOnly_NullArray ()
2688 Array.AsReadOnly <int> (null);
2692 public void ReadOnly_Count ()
2694 AssertEquals (10, Array.AsReadOnly (new int [10]).Count);
2698 public void ReadOnly_Contains ()
2700 int[] arr = new int [2];
2703 IList<int> a = Array.AsReadOnly (arr);
2705 Assert (a.Contains (3));
2706 Assert (!a.Contains (6));
2710 public void ReadOnly_IndexOf ()
2712 int[] arr = new int [2];
2715 IList<int> a = Array.AsReadOnly (arr);
2717 AssertEquals (0, a.IndexOf (3));
2718 AssertEquals (1, a.IndexOf (5));
2719 AssertEquals (-1, a.IndexOf (6));
2723 public void ReadOnly_Indexer ()
2725 int[] arr = new int [2];
2728 IList<int> a = Array.AsReadOnly (arr);
2730 AssertEquals (3, a [0]);
2731 AssertEquals (5, a [1]);
2733 /* Check that modifications to the original array are visible */
2735 AssertEquals (6, a [0]);
2739 public void ReadOnly_Enumerator ()
2741 int[] arr = new int [10];
2743 for (int i = 0; i < 10; ++i)
2747 foreach (int i in Array.AsReadOnly (arr))
2750 AssertEquals (45, sum);
2754 public void Resize ()
2756 int [] arr = new int [] { 1, 3, 5 };
2757 Array.Resize <int> (ref arr, 3);
2758 AssertEquals ("#A1", 3, arr.Length);
2759 AssertEquals ("#A2", 1, arr [0]);
2760 AssertEquals ("#A3", 3, arr [1]);
2761 AssertEquals ("#A4", 5, arr [2]);
2763 Array.Resize <int> (ref arr, 2);
2764 AssertEquals ("#B1", 2, arr.Length);
2765 AssertEquals ("#B2", 1, arr [0]);
2766 AssertEquals ("#B3", 3, arr [1]);
2768 Array.Resize <int> (ref arr, 4);
2769 AssertEquals ("#C1", 4, arr.Length);
2770 AssertEquals ("#C2", 1, arr [0]);
2771 AssertEquals ("#C3", 3, arr [1]);
2772 AssertEquals ("#C4", 0, arr [2]);
2773 AssertEquals ("#C5", 0, arr [3]);
2777 public void Resize_null ()
2780 Array.Resize (ref arr, 10);
2781 AssertEquals (arr.Length, 10);
2785 public void Test_ContainsAndIndexOf_EquatableItem ()
2787 EquatableClass[] list = new EquatableClass[] {new EquatableClass (0), new EquatableClass (1), new EquatableClass (0)};
2789 AssertEquals ("#0", 0, Array.IndexOf<EquatableClass> (list, list[0]));
2790 AssertEquals ("#1", 0, Array.IndexOf<EquatableClass> (list, new EquatableClass (0)));
2791 AssertEquals ("#2", 2, Array.LastIndexOf<EquatableClass> (list, list[0]));
2792 AssertEquals ("#3", 2, Array.LastIndexOf<EquatableClass> (list, new EquatableClass (0)));
2795 public class EquatableClass : IEquatable<EquatableClass>
2798 public EquatableClass (int x)
2803 public bool Equals (EquatableClass other)
2805 return this._x == other._x;
2809 #if !TARGET_JVM // BugBUG: T[] is not yet ICollection<T> under TARGET_JVM
2812 public void ICollectionNull ()
2814 ICollection<object> test;
2816 test = new List<object>();
2817 AssertEquals ("list<o>", test.Contains (null), false);
2819 test = new object[] {};
2820 AssertEquals ("empty array", test.Contains (null), false);
2822 test = new object[] {null};
2823 AssertEquals ("array with null", test.Contains (null), true);
2825 test = new List<object>(test);
2826 AssertEquals ("List<object> with test", test.Contains (null), true);
2828 test = new object[] {new object()};
2829 AssertEquals ("array with object", test.Contains (null), false);
2831 test = new List<object>(test);
2832 AssertEquals ("array with test", test.Contains (null), false);
2834 #endif // TARGET_JVM
2839 enum ByteEnum : byte {}
2840 enum IntEnum : int {}
2843 public void TestByteEnumArrayToByteArray ()
2845 ByteEnum[] a = new ByteEnum[] {(ByteEnum) 1, (ByteEnum) 2};
2846 byte[] b = new byte[a.Length];
2851 public void TestByteEnumArrayToIntArray ()
2853 ByteEnum[] a = new ByteEnum[] {(ByteEnum) 1, (ByteEnum) 2};
2854 int[] b = new int[a.Length];
2859 [ExpectedException (typeof (ArrayTypeMismatchException))]
2860 public void TestIntEnumArrayToByteArray ()
2862 IntEnum[] a = new IntEnum[] {(IntEnum) 1, (IntEnum) 2};
2863 byte[] b = new byte[a.Length];
2868 public void TestIntEnumArrayToIntArray ()
2870 IntEnum[] a = new IntEnum[] {(IntEnum) 1, (IntEnum) 2};
2871 int[] b = new int[a.Length];