1 // ArrayListTest.cs - NUnit Test Cases for the System.Collections.ArrayList class
\r
3 // David Brandt (bucky@keystreams.com)
\r
5 // (C) Ximian, Inc. http://www.ximian.com
\r
9 using System.Collections;
\r
11 using NUnit.Framework;
\r
13 namespace MonoTests.System.Collections {
\r
16 public class ArrayListTest : Assertion {
\r
18 public void TestCtor() {
\r
20 ArrayList al1 = new ArrayList();
\r
21 AssertNotNull("no basic ArrayList", al1);
\r
24 bool errorThrown = false;
\r
26 ArrayList a = new ArrayList(null);
\r
27 } catch (ArgumentNullException) {
\r
30 Assert("null icollection error not thrown",
\r
34 // what can I say? I like chars. [--DB]
\r
35 char[] coll = {'a', 'b', 'c', 'd'};
\r
36 ArrayList al1 = new ArrayList(coll);
\r
37 AssertNotNull("no icollection ArrayList", al1);
\r
38 for (int i = 0; i < coll.Length; i++) {
\r
39 AssertEquals(i + " not ctor'ed properly.",
\r
45 Char[,] c1 = new Char[2,2];
\r
46 ArrayList al1 = new ArrayList(c1);
\r
47 Fail ("Should fail with multi-dimensional array in constructor.");
\r
48 } catch (RankException) {
\r
53 bool errorThrown = false;
\r
55 ArrayList a = new ArrayList(-1);
\r
56 } catch (ArgumentOutOfRangeException) {
\r
59 Assert("negative capacity error not thrown",
\r
64 public void TestCapacity() {
\r
65 for (int i = 1; i < 100; i++) {
\r
66 ArrayList al1 = new ArrayList(i);
\r
67 AssertEquals("Bad capacity of " + i,
\r
71 ArrayList al1 = new ArrayList(0);
\r
73 // AssertEquals("Bad capacity when set to 0",
\r
74 // 16, al1.Capacity);
\r
76 AssertEquals("Bad capacity when set to 0",
\r
80 ArrayList al1 = new ArrayList();
\r
81 AssertEquals("Bad default capacity",
\r
86 public void TestCount() {
\r
88 ArrayList al1 = new ArrayList();
\r
89 AssertEquals("Bad initial count",
\r
91 for (int i = 1; i <= 100; i++) {
\r
93 AssertEquals("Bad count " + i,
\r
97 for (int i = 0; i < 100; i++) {
\r
98 char[] coll = new Char[i];
\r
99 ArrayList al1 = new ArrayList(coll);
\r
100 AssertEquals("Bad count for " + i,
\r
105 public void TestIsFixed() {
\r
106 ArrayList al1 = new ArrayList();
\r
107 Assert("should not be fixed by default", !al1.IsFixedSize);
\r
108 ArrayList al2 = ArrayList.FixedSize(al1);
\r
109 Assert("fixed-size wrapper not working", al2.IsFixedSize);
\r
112 public void TestIsReadOnly() {
\r
113 ArrayList al1 = new ArrayList();
\r
114 Assert("should not be ReadOnly by default", !al1.IsReadOnly);
\r
115 ArrayList al2 = ArrayList.ReadOnly(al1);
\r
116 Assert("read-only wrapper not working", al2.IsReadOnly);
\r
119 public void TestIsSynchronized() {
\r
120 ArrayList al1 = new ArrayList();
\r
121 Assert("should not be synchronized by default",
\r
122 !al1.IsSynchronized);
\r
123 ArrayList al2 = ArrayList.Synchronized(al1);
\r
124 Assert("synchronized wrapper not working", al2.IsSynchronized);
\r
127 public void TestItem() {
\r
128 ArrayList al1 = new ArrayList();
\r
130 bool errorThrown = false;
\r
132 object o = al1[-1];
\r
133 } catch (ArgumentOutOfRangeException) {
\r
134 errorThrown = true;
\r
136 Assert("negative item error not thrown",
\r
140 bool errorThrown = false;
\r
143 } catch (ArgumentOutOfRangeException) {
\r
144 errorThrown = true;
\r
146 Assert("past-end item error not thrown",
\r
149 for (int i = 0; i <= 100; i++) {
\r
152 for (int i = 0; i <= 100; i++) {
\r
153 AssertEquals("item not fetched for " + i,
\r
158 public void TestAdapter() {
\r
160 bool errorThrown = false;
\r
162 ArrayList al1 = ArrayList.Adapter(null);
\r
163 } catch (ArgumentNullException) {
\r
164 errorThrown = true;
\r
165 } catch (Exception e) {
\r
166 Fail ("Incorrect exception thrown at 1: " + e.ToString());
\r
168 Assert("null adapter error not thrown",
\r
172 char[] list = {'a', 'b', 'c', 'd'};
\r
173 ArrayList al1 = ArrayList.Adapter(list);
\r
174 AssertNotNull("Couldn't get an adapter", al1);
\r
175 for (int i = 0; i < list.Length; i++) {
\r
176 AssertEquals("adapter not adapting", list[i], al1[i]);
\r
179 for (int i = 0; i < list.Length; i++) {
\r
180 AssertEquals("adapter not adapting", list[i], al1[i]);
\r
183 // Test Binary Search
\r
185 bool errorThrown = false;
\r
188 String[] s1 = {"This", "is", "a", "test"};
\r
189 ArrayList al1 = ArrayList.Adapter (s1);
\r
190 al1.BinarySearch(42);
\r
191 } catch (InvalidOperationException) {
\r
192 // this is what .NET throws
\r
193 errorThrown = true;
\r
194 } catch (ArgumentException) {
\r
195 // this is what the docs say it should throw
\r
196 errorThrown = true;
\r
197 } catch (Exception e) {
\r
198 Fail ("Incorrect exception thrown at 1: " + e.ToString());
\r
200 Assert("search-for-wrong-type error not thrown",
\r
205 char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
\r
206 ArrayList al1 = ArrayList.Adapter (arr);
\r
207 Assert("couldn't find elem #1",
\r
208 al1.BinarySearch('c') >= 3);
\r
209 Assert("couldn't find elem #2",
\r
210 al1.BinarySearch('c') < 6);
\r
213 char[] arr = {'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
\r
214 ArrayList al1 = ArrayList.Adapter (arr);
\r
215 AssertEquals("couldn't find next-higher elem",
\r
216 -4, al1.BinarySearch('c'));
\r
219 char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
\r
220 ArrayList al1 = ArrayList.Adapter (arr);
\r
221 AssertEquals("couldn't find end",
\r
222 -9, al1.BinarySearch('e'));
\r
226 char[] starter = {'d', 'b', 'f', 'e', 'a', 'c'};
\r
227 ArrayList al1 = ArrayList.Adapter (starter);
\r
229 AssertEquals("Should be sorted", 'a', al1[0]);
\r
230 AssertEquals("Should be sorted", 'b', al1[1]);
\r
231 AssertEquals("Should be sorted", 'c', al1[2]);
\r
232 AssertEquals("Should be sorted", 'd', al1[3]);
\r
233 AssertEquals("Should be sorted", 'e', al1[4]);
\r
234 AssertEquals("Should be sorted", 'f', al1[5]);
\r
237 // TODO - test other adapter types?
\r
240 public void TestAdd() {
\r
242 bool errorThrown = false;
\r
245 ArrayList.FixedSize(new ArrayList());
\r
247 } catch (NotSupportedException) {
\r
248 errorThrown = true;
\r
249 } catch (Exception e) {
\r
250 Fail ("Incorrect exception thrown at 1: " + e.ToString());
\r
252 Assert("add to fixed size error not thrown",
\r
256 bool errorThrown = false;
\r
259 ArrayList.ReadOnly(new ArrayList());
\r
261 } catch (NotSupportedException) {
\r
262 errorThrown = true;
\r
263 } catch (Exception e) {
\r
264 Fail ("Incorrect exception thrown at 2: " + e.ToString());
\r
266 Assert("add to read only error not thrown",
\r
270 ArrayList al1 = new ArrayList();
\r
271 for (int i = 1; i <= 100; i++) {
\r
273 AssertEquals("add failed " + i,
\r
275 AssertEquals("add failed " + i,
\r
281 string [] strArray = new string [] {};
\r
282 ArrayList al1 = new ArrayList (strArray);
\r
285 AssertEquals ("add failed", 2, al1.Count);
\r
289 public void TestAddRange() {
\r
291 bool errorThrown = false;
\r
294 ArrayList.FixedSize(new ArrayList());
\r
295 String[] s1 = {"Hi!"};
\r
297 } catch (NotSupportedException) {
\r
298 errorThrown = true;
\r
299 } catch (Exception e) {
\r
300 Fail ("Incorrect exception thrown at 1: " + e.ToString());
\r
302 Assert("add to fixed size error not thrown",
\r
306 bool errorThrown = false;
\r
309 ArrayList.ReadOnly(new ArrayList());
\r
310 String[] s1 = {"Hi!"};
\r
312 } catch (NotSupportedException) {
\r
313 errorThrown = true;
\r
314 } catch (Exception e) {
\r
315 Fail ("Incorrect exception thrown at 2: " + e.ToString());
\r
317 Assert("add to read only error not thrown",
\r
321 bool errorThrown = false;
\r
323 ArrayList al1 = new ArrayList();
\r
324 al1.AddRange(null);
\r
325 } catch (ArgumentNullException) {
\r
326 errorThrown = true;
\r
327 } catch (Exception e) {
\r
328 Fail ("Incorrect exception thrown at 3: " + e.ToString());
\r
330 Assert("add to read only error not thrown",
\r
335 ArrayList a1 = new ArrayList();
\r
336 AssertEquals("ArrayList should start empty",
\r
338 char[] coll = {'a', 'b', 'c'};
\r
340 AssertEquals("ArrayList has wrong elements",
\r
343 AssertEquals("ArrayList has wrong elements",
\r
348 ArrayList list = new ArrayList ();
\r
350 for (int i = 0; i < 100; i ++) {
\r
354 AssertEquals ("BinarySearch off-by-one bug",
\r
355 49, list.BinarySearch (1));
\r
359 public void TestBinarySearch() {
\r
361 bool errorThrown = false;
\r
363 ArrayList al1 = new ArrayList();
\r
364 String[] s1 = {"This", "is", "a", "test"};
\r
366 al1.BinarySearch(42);
\r
367 } catch (InvalidOperationException) {
\r
368 // this is what .NET throws
\r
369 errorThrown = true;
\r
370 } catch (ArgumentException) {
\r
371 // this is what the docs say it should throw
\r
372 errorThrown = true;
\r
373 } catch (Exception e) {
\r
374 Fail ("Incorrect exception thrown at 1: " + e.ToString());
\r
376 Assert("search-for-wrong-type error not thrown",
\r
381 char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
\r
382 ArrayList al1 = new ArrayList(arr);
\r
383 Assert("couldn't find elem #1",
\r
384 al1.BinarySearch('c') >= 3);
\r
385 Assert("couldn't find elem #2",
\r
386 al1.BinarySearch('c') < 6);
\r
389 char[] arr = {'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
\r
390 ArrayList al1 = new ArrayList(arr);
\r
391 AssertEquals("couldn't find next-higher elem",
\r
392 -4, al1.BinarySearch('c'));
\r
395 char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
\r
396 ArrayList al1 = new ArrayList(arr);
\r
397 AssertEquals("couldn't find end",
\r
398 -9, al1.BinarySearch('e'));
\r
404 [ExpectedException (typeof (ArgumentException))]
\r
405 public void BinarySearch_IndexOverflow ()
\r
407 ArrayList al = new ArrayList ();
\r
409 al.BinarySearch (Int32.MaxValue, 1, this, null);
\r
413 [ExpectedException (typeof (ArgumentException))]
\r
414 public void BinarySearch_CountOverflow ()
\r
416 ArrayList al = new ArrayList ();
\r
418 al.BinarySearch (1, Int32.MaxValue, this, null);
\r
422 public void BinarySearch_Null ()
\r
424 ArrayList al = new ArrayList ();
\r
426 AssertEquals ("null", -1, al.BinarySearch (null));
\r
429 // TODO - BinarySearch with IComparer
\r
431 public void TestClear() {
\r
433 bool errorThrown = false;
\r
436 ArrayList.FixedSize(new ArrayList());
\r
438 } catch (NotSupportedException) {
\r
439 errorThrown = true;
\r
441 Assert("add to fixed size error not thrown",
\r
445 bool errorThrown = false;
\r
448 ArrayList.ReadOnly(new ArrayList());
\r
450 } catch (NotSupportedException) {
\r
451 errorThrown = true;
\r
453 Assert("add to read only error not thrown",
\r
457 ArrayList al1 = new ArrayList();
\r
459 AssertEquals("should have one element",
\r
462 AssertEquals("should be empty",
\r
466 int[] i1 = {1,2,3,4};
\r
467 ArrayList al1 = new ArrayList(i1);
\r
468 AssertEquals("should have elements",
\r
469 i1.Length, al1.Count);
\r
470 int capacity = al1.Capacity;
\r
472 AssertEquals("should be empty again",
\r
474 AssertEquals("capacity shouldn't have changed",
\r
475 capacity, al1.Capacity);
\r
479 public void TestClone() {
\r
481 char[] c1 = {'a', 'b', 'c'};
\r
482 ArrayList al1 = new ArrayList(c1);
\r
483 ArrayList al2 = (ArrayList)al1.Clone();
\r
484 AssertEquals("ArrayList match", al1[0], al2[0]);
\r
485 AssertEquals("ArrayList match", al1[1], al2[1]);
\r
486 AssertEquals("ArrayList match", al1[2], al2[2]);
\r
489 char[] d10 = {'a', 'b'};
\r
490 char[] d11 = {'a', 'c'};
\r
491 char[] d12 = {'b', 'c'};
\r
492 char[][] d1 = {d10, d11, d12};
\r
493 ArrayList al1 = new ArrayList(d1);
\r
494 ArrayList al2 = (ArrayList)al1.Clone();
\r
495 AssertEquals("Array match", al1[0], al2[0]);
\r
496 AssertEquals("Array match", al1[1], al2[1]);
\r
497 AssertEquals("Array match", al1[2], al2[2]);
\r
499 ((char[])al1[0])[0] = 'z';
\r
500 AssertEquals("shallow copy", al1[0], al2[0]);
\r
504 public void TestContains() {
\r
505 char[] c1 = {'a', 'b', 'c'};
\r
506 ArrayList al1 = new ArrayList(c1);
\r
507 Assert("never find a null", !al1.Contains(null));
\r
508 Assert("can't find value", al1.Contains('b'));
\r
509 Assert("shouldn't find value", !al1.Contains('?'));
\r
512 public void TestCopyTo() {
\r
514 bool errorThrown = false;
\r
516 Char[] c1 = new Char[2];
\r
517 ArrayList al1 = new ArrayList(c1);
\r
518 al1.CopyTo(null, 2);
\r
519 } catch (ArgumentNullException) {
\r
520 errorThrown = true;
\r
521 } catch (Exception e) {
\r
522 Fail ("Incorrect exception thrown at 1: " + e.ToString());
\r
524 Assert("error not thrown 1", errorThrown);
\r
527 bool errorThrown = false;
\r
529 Char[] c1 = new Char[2];
\r
530 ArrayList al1 = new ArrayList(c1);
\r
531 Char[,] c2 = new Char[2,2];
\r
533 } catch (ArgumentException) {
\r
534 errorThrown = true;
\r
535 } catch (Exception e) {
\r
536 Fail ("Incorrect exception thrown at 2: " + e.ToString());
\r
538 Assert("error not thrown 2", errorThrown);
\r
541 bool errorThrown = false;
\r
543 // This appears to be a bug in the ArrayList Constructor.
\r
544 // It throws a RankException if a multidimensional Array
\r
545 // is passed. The docs imply that an IEnumerator is used
\r
546 // to retrieve the items from the collection, so this should
\r
547 // work. In anycase this test is for CopyTo, so use what
\r
548 // works on both platforms.
\r
549 //Char[,] c1 = new Char[2,2];
\r
550 Char[] c1 = new Char[2];
\r
551 ArrayList al1 = new ArrayList(c1);
\r
552 Char[] c2 = new Char[2];
\r
554 } catch (ArgumentException) {
\r
555 errorThrown = true;
\r
556 } catch (Exception e) {
\r
557 Fail ("Incorrect exception thrown at 3: " + e.ToString());
\r
559 Assert("error not thrown 3", errorThrown);
\r
562 bool errorThrown = false;
\r
564 Char[] c1 = new Char[2];
\r
565 ArrayList al1 = new ArrayList(c1);
\r
566 Char[] c2 = new Char[2];
\r
567 al1.CopyTo(c2, -1);
\r
568 } catch (ArgumentOutOfRangeException) {
\r
569 errorThrown = true;
\r
570 } catch (Exception e) {
\r
571 Fail ("Incorrect exception thrown at 4: " + e.ToString());
\r
573 Assert("error not thrown 4", errorThrown);
\r
576 bool errorThrown = false;
\r
578 Char[] c1 = new Char[2];
\r
579 ArrayList al1 = new ArrayList(c1);
\r
580 Char[] c2 = new Char[2];
\r
582 } catch (ArgumentException) {
\r
583 errorThrown = true;
\r
584 } catch (Exception e) {
\r
585 Fail ("Incorrect exception thrown at 5: " + e.ToString());
\r
587 Assert("error not thrown 5", errorThrown);
\r
590 bool errorThrown = false;
\r
592 Char[] c1 = new Char[2];
\r
593 ArrayList al1 = new ArrayList(c1);
\r
594 Char[] c2 = new Char[2];
\r
596 } catch (ArgumentException) {
\r
597 errorThrown = true;
\r
598 } catch (Exception e) {
\r
599 Fail ("Incorrect exception thrown at 6: " + e.ToString());
\r
601 Assert("error not thrown 6", errorThrown);
\r
604 bool errorThrown = false;
\r
606 String[] c1 = {"String", "array"};
\r
607 ArrayList al1 = new ArrayList(c1);
\r
608 Char[] c2 = new Char[2];
\r
610 } catch (InvalidCastException) {
\r
611 errorThrown = true;
\r
612 } catch (Exception e) {
\r
613 Fail ("Incorrect exception thrown at 7: " + e.ToString());
\r
615 Assert("error not thrown 7", errorThrown);
\r
618 Char[] orig = {'a', 'b', 'c', 'd'};
\r
619 ArrayList al = new ArrayList(orig);
\r
620 Char[] copy = new Char[10];
\r
621 Array.Clear(copy, 0, copy.Length);
\r
622 al.CopyTo(copy, 3);
\r
623 AssertEquals("Wrong CopyTo 0", (char)0, copy[0]);
\r
624 AssertEquals("Wrong CopyTo 1", (char)0, copy[1]);
\r
625 AssertEquals("Wrong CopyTo 2", (char)0, copy[2]);
\r
626 AssertEquals("Wrong CopyTo 3", orig[0], copy[3]);
\r
627 AssertEquals("Wrong CopyTo 4", orig[1], copy[4]);
\r
628 AssertEquals("Wrong CopyTo 5", orig[2], copy[5]);
\r
629 AssertEquals("Wrong CopyTo 6", orig[3], copy[6]);
\r
630 AssertEquals("Wrong CopyTo 7", (char)0, copy[7]);
\r
631 AssertEquals("Wrong CopyTo 8", (char)0, copy[8]);
\r
632 AssertEquals("Wrong CopyTo 9", (char)0, copy[9]);
\r
636 [ExpectedException (typeof (ArgumentException))]
\r
637 public void CopyTo_IndexOverflow ()
\r
639 ArrayList al = new ArrayList ();
\r
641 al.CopyTo (Int32.MaxValue, new byte [2], 0, 0);
\r
645 [ExpectedException (typeof (ArgumentException))]
\r
646 public void CopyTo_ArrayIndexOverflow ()
\r
648 ArrayList al = new ArrayList ();
\r
650 al.CopyTo (0, new byte [2], Int32.MaxValue, 0);
\r
654 [ExpectedException (typeof (ArgumentException))]
\r
655 public void CopyTo_CountOverflow ()
\r
657 ArrayList al = new ArrayList ();
\r
659 al.CopyTo (0, new byte [2], 0, Int32.MaxValue);
\r
662 public void TestFixedSize() {
\r
664 bool errorThrown = false;
\r
666 ArrayList al1 = ArrayList.FixedSize(null);
\r
667 } catch (ArgumentNullException) {
\r
668 errorThrown = true;
\r
670 Assert("null arg error not thrown", errorThrown);
\r
673 ArrayList al1 = new ArrayList();
\r
674 AssertEquals("arrays start un-fixed.",
\r
675 false, al1.IsFixedSize);
\r
676 ArrayList al2 = ArrayList.FixedSize(al1);
\r
677 AssertEquals("should be fixed.",
\r
678 true, al2.IsFixedSize);
\r
682 public void TestEnumerator() {
\r
683 String[] s1 = {"this", "is", "a", "test"};
\r
684 ArrayList al1 = new ArrayList(s1);
\r
685 IEnumerator en = al1.GetEnumerator();
\r
687 al1.Add("something");
\r
690 Fail("Add() didn't invalidate the enumerator");
\r
691 } catch (InvalidOperationException) {
\r
692 // do nothing...this is what we expect
\r
695 en = al1.GetEnumerator();
\r
700 Fail("AddRange() didn't invalidate the enumerator");
\r
701 } catch (InvalidOperationException) {
\r
702 // do nothing...this is what we expect
\r
705 en = al1.GetEnumerator();
\r
710 Fail("Clear() didn't invalidate the enumerator");
\r
711 } catch (InvalidOperationException) {
\r
712 // do nothing...this is what we expect
\r
715 al1 = new ArrayList(s1);
\r
716 en = al1.GetEnumerator();
\r
718 al1.Insert(0, "new first");
\r
721 Fail("Insert() didn't invalidate the enumerator");
\r
722 } catch (InvalidOperationException) {
\r
723 // do nothing...this is what we expect
\r
726 en = al1.GetEnumerator();
\r
728 al1.InsertRange(0, al1);
\r
731 Fail("InsertRange() didn't invalidate the enumerator");
\r
732 } catch (InvalidOperationException) {
\r
733 // do nothing...this is what we expect
\r
736 en = al1.GetEnumerator();
\r
738 al1.Remove("this");
\r
741 Fail("Remove() didn't invalidate the enumerator");
\r
742 } catch (InvalidOperationException) {
\r
743 // do nothing...this is what we expect
\r
746 en = al1.GetEnumerator();
\r
751 Fail("RemoveAt() didn't invalidate the enumerator");
\r
752 } catch (InvalidOperationException) {
\r
753 // do nothing...this is what we expect
\r
756 en = al1.GetEnumerator();
\r
758 al1.RemoveRange(1, 1);
\r
761 Fail("RemoveRange() didn't invalidate the enumerator");
\r
762 } catch (InvalidOperationException) {
\r
763 // do nothing...this is what we expect
\r
766 en = al1.GetEnumerator();
\r
771 Fail("Reverse() didn't invalidate the enumerator");
\r
772 } catch (InvalidOperationException) {
\r
773 // do nothing...this is what we expect
\r
776 en = al1.GetEnumerator();
\r
781 Fail("Sort() didn't invalidate the enumerator");
\r
782 } catch (InvalidOperationException) {
\r
783 // do nothing...this is what we expect
\r
787 public void TestGetEnumerator() {
\r
789 bool errorThrown = false;
\r
791 ArrayList a = new ArrayList();
\r
792 IEnumerator en = a.GetEnumerator(-1,1);
\r
793 } catch (ArgumentOutOfRangeException) {
\r
794 errorThrown = true;
\r
796 Assert("negative index error not thrown",
\r
800 bool errorThrown = false;
\r
802 ArrayList a = new ArrayList();
\r
803 IEnumerator en = a.GetEnumerator(1,-1);
\r
804 } catch (ArgumentOutOfRangeException) {
\r
805 errorThrown = true;
\r
807 Assert("negative index error not thrown",
\r
811 bool errorThrown = false;
\r
813 ArrayList a = new ArrayList();
\r
814 IEnumerator en = a.GetEnumerator(1,1);
\r
815 } catch (ArgumentException) {
\r
816 errorThrown = true;
\r
818 Assert("out-of-range index error not thrown",
\r
822 String[] s1 = {"this", "is", "a", "test"};
\r
823 ArrayList al1 = new ArrayList(s1);
\r
824 IEnumerator en = al1.GetEnumerator();
\r
825 AssertNotNull("No enumerator", en);
\r
827 for (int i = 0; i < s1.Length; i++) {
\r
829 AssertEquals("Not enumerating",
\r
830 al1[i], en.Current);
\r
834 String[] s1 = {"this", "is", "a", "test"};
\r
835 ArrayList al1 = new ArrayList(s1);
\r
836 IEnumerator en = al1.GetEnumerator(1,2);
\r
837 AssertNotNull("No enumerator", en);
\r
839 for (int i = 0; i < 2; i++) {
\r
841 AssertEquals("Not enumerating",
\r
842 al1[i+1], en.Current);
\r
848 [ExpectedException (typeof (ArgumentException))]
\r
849 public void GetEnumerator_IndexOverflow ()
\r
851 ArrayList al = new ArrayList ();
\r
853 al.GetEnumerator (Int32.MaxValue, 0);
\r
857 [ExpectedException (typeof (ArgumentException))]
\r
858 public void GetEnumerator_CountOverflow ()
\r
860 ArrayList al = new ArrayList ();
\r
862 al.GetEnumerator (0, Int32.MaxValue);
\r
865 public void TestGetRange() {
\r
867 bool errorThrown = false;
\r
869 ArrayList a = new ArrayList();
\r
870 ArrayList b = a.GetRange(-1,1);
\r
871 } catch (ArgumentOutOfRangeException) {
\r
872 errorThrown = true;
\r
874 Assert("negative index error not thrown",
\r
878 bool errorThrown = false;
\r
880 ArrayList a = new ArrayList();
\r
881 ArrayList b = a.GetRange(1,-1);
\r
882 } catch (ArgumentOutOfRangeException) {
\r
883 errorThrown = true;
\r
885 Assert("negative index error not thrown",
\r
889 bool errorThrown = false;
\r
891 ArrayList a = new ArrayList();
\r
892 ArrayList b = a.GetRange(1,1);
\r
893 } catch (ArgumentException) {
\r
894 errorThrown = true;
\r
896 Assert("out-of-range index error not thrown",
\r
900 char[] chars = {'a', 'b', 'c', 'd', 'e', 'f'};
\r
901 ArrayList a = new ArrayList(chars);
\r
902 ArrayList b = a.GetRange(1, 3);
\r
903 AssertEquals("GetRange returned wrong size ArrayList", 3, b.Count);
\r
904 for (int i = 0; i < b.Count; i++) {
\r
905 AssertEquals("range didn't work",
\r
909 a[2] = '?'; // should screw up ArrayList b.
\r
910 bool errorThrown = false;
\r
913 } catch (InvalidOperationException) {
\r
914 errorThrown = true;
\r
916 AssertEquals("Munging 'a' should mess up 'b'",
\r
917 true, errorThrown);
\r
922 [ExpectedException (typeof (ArgumentException))]
\r
923 public void GetRange_IndexOverflow ()
\r
925 ArrayList al = new ArrayList ();
\r
927 al.GetRange (Int32.MaxValue, 0);
\r
931 [ExpectedException (typeof (ArgumentException))]
\r
932 public void GetRange_CountOverflow ()
\r
934 ArrayList al = new ArrayList ();
\r
936 al.GetRange (0, Int32.MaxValue);
\r
939 public void TestIndexOf() {
\r
941 bool errorThrown = false;
\r
943 ArrayList a = new ArrayList(1);
\r
944 int i = a.IndexOf('a', -1);
\r
945 } catch (ArgumentOutOfRangeException) {
\r
946 errorThrown = true;
\r
948 Assert("negative indexof error not thrown",
\r
952 bool errorThrown = false;
\r
954 ArrayList a = new ArrayList(1);
\r
955 int i = a.IndexOf('a', 2);
\r
956 } catch (ArgumentOutOfRangeException) {
\r
957 errorThrown = true;
\r
959 Assert("past-end indexof error not thrown",
\r
963 bool errorThrown = false;
\r
965 ArrayList a = new ArrayList(1);
\r
966 int i = a.IndexOf('a', 0, -1);
\r
967 } catch (ArgumentOutOfRangeException) {
\r
968 errorThrown = true;
\r
970 Assert("negative indexof error not thrown",
\r
974 bool errorThrown = false;
\r
976 ArrayList a = new ArrayList(1);
\r
977 int i = a.IndexOf('a', 0, 2);
\r
978 } catch (ArgumentOutOfRangeException) {
\r
979 errorThrown = true;
\r
981 Assert("past-end indexof error not thrown",
\r
985 bool errorThrown = false;
\r
987 ArrayList a = new ArrayList(2);
\r
988 int i = a.IndexOf('a', 1, 2);
\r
989 } catch (ArgumentOutOfRangeException) {
\r
990 errorThrown = true;
\r
992 Assert("past-end indexof error not thrown",
\r
996 char[] c = {'a', 'b', 'c', 'd', 'e'};
\r
997 ArrayList a = new ArrayList(c);
\r
998 AssertEquals("never find null",
\r
999 -1, a.IndexOf(null));
\r
1000 AssertEquals("never find null",
\r
1001 -1, a.IndexOf(null, 0));
\r
1002 AssertEquals("never find null",
\r
1003 -1, a.IndexOf(null, 0, 5));
\r
1004 AssertEquals("can't find elem",
\r
1005 2, a.IndexOf('c'));
\r
1006 AssertEquals("can't find elem",
\r
1007 2, a.IndexOf('c', 2));
\r
1008 AssertEquals("can't find elem",
\r
1009 2, a.IndexOf('c', 2, 2));
\r
1010 AssertEquals("shouldn't find elem",
\r
1011 -1, a.IndexOf('c', 3, 2));
\r
1012 AssertEquals("shouldn't find", -1, a.IndexOf('?'));
\r
1013 AssertEquals("shouldn't find", -1, a.IndexOf(3));
\r
1018 [ExpectedException (typeof (ArgumentOutOfRangeException))]
\r
1019 public void IndexOf_StartIndexOverflow ()
\r
1021 ArrayList al = new ArrayList ();
\r
1023 al.IndexOf ('a', Int32.MaxValue, 1);
\r
1027 [ExpectedException (typeof (ArgumentOutOfRangeException))]
\r
1028 public void IndexOf_CountOverflow ()
\r
1030 ArrayList al = new ArrayList ();
\r
1032 al.IndexOf ('a', 1, Int32.MaxValue);
\r
1035 public void TestInsert() {
\r
1037 bool errorThrown = false;
\r
1040 ArrayList.FixedSize(new ArrayList());
\r
1041 al1.Insert(0, "Hi!");
\r
1042 } catch (NotSupportedException) {
\r
1043 errorThrown = true;
\r
1045 Assert("insert to fixed size error not thrown",
\r
1049 bool errorThrown = false;
\r
1052 ArrayList.ReadOnly(new ArrayList());
\r
1053 al1.Insert(0, "Hi!");
\r
1054 } catch (NotSupportedException) {
\r
1055 errorThrown = true;
\r
1057 Assert("insert to read only error not thrown",
\r
1061 bool errorThrown = false;
\r
1063 ArrayList al1 = new ArrayList(3);
\r
1064 al1.Insert(-1, "Hi!");
\r
1065 } catch (ArgumentOutOfRangeException) {
\r
1066 errorThrown = true;
\r
1068 Assert("insert to read only error not thrown",
\r
1072 bool errorThrown = false;
\r
1074 ArrayList al1 = new ArrayList(3);
\r
1075 al1.Insert(4, "Hi!");
\r
1076 } catch (ArgumentOutOfRangeException) {
\r
1077 errorThrown = true;
\r
1079 Assert("insert to read only error not thrown",
\r
1083 ArrayList al1 = new ArrayList();
\r
1084 AssertEquals("arraylist starts empty", 0, al1.Count);
\r
1085 al1.Insert(0, 'a');
\r
1086 al1.Insert(1, 'b');
\r
1087 al1.Insert(0, 'c');
\r
1088 AssertEquals("arraylist needs stuff", 3, al1.Count);
\r
1089 AssertEquals("arraylist got stuff", 'c', al1[0]);
\r
1090 AssertEquals("arraylist got stuff", 'a', al1[1]);
\r
1091 AssertEquals("arraylist got stuff", 'b', al1[2]);
\r
1095 public void TestInsertRange() {
\r
1097 bool errorThrown = false;
\r
1100 ArrayList.FixedSize(new ArrayList());
\r
1101 string[] s = {"Hi!"};
\r
1102 al1.InsertRange(0, s);
\r
1103 } catch (NotSupportedException) {
\r
1104 errorThrown = true;
\r
1106 Assert("insert to fixed size error not thrown",
\r
1110 bool errorThrown = false;
\r
1113 ArrayList.ReadOnly(new ArrayList());
\r
1114 string[] s = {"Hi!"};
\r
1115 al1.InsertRange(0, s);
\r
1116 } catch (NotSupportedException) {
\r
1117 errorThrown = true;
\r
1119 Assert("insert to read only error not thrown",
\r
1123 bool errorThrown = false;
\r
1125 ArrayList al1 = new ArrayList(3);
\r
1126 string[] s = {"Hi!"};
\r
1127 al1.InsertRange(-1, s);
\r
1128 } catch (ArgumentOutOfRangeException) {
\r
1129 errorThrown = true;
\r
1131 Assert("negative index insert error not thrown",
\r
1135 bool errorThrown = false;
\r
1137 ArrayList al1 = new ArrayList(3);
\r
1138 string[] s = {"Hi!"};
\r
1139 al1.InsertRange(4, s);
\r
1140 } catch (ArgumentOutOfRangeException) {
\r
1141 errorThrown = true;
\r
1143 Assert("out-of-range insert error not thrown",
\r
1147 bool errorThrown = false;
\r
1149 ArrayList al1 = new ArrayList(3);
\r
1150 al1.InsertRange(0, null);
\r
1151 } catch (ArgumentNullException) {
\r
1152 errorThrown = true;
\r
1154 Assert("null insert error not thrown",
\r
1158 char[] c = {'a', 'b', 'c'};
\r
1159 ArrayList a = new ArrayList(c);
\r
1160 a.InsertRange(1, c);
\r
1161 AssertEquals("bad insert 1", 'a', a[0]);
\r
1162 AssertEquals("bad insert 2", 'a', a[1]);
\r
1163 AssertEquals("bad insert 3", 'b', a[2]);
\r
1164 AssertEquals("bad insert 4", 'c', a[3]);
\r
1165 AssertEquals("bad insert 5", 'b', a[4]);
\r
1166 AssertEquals("bad insert 6", 'c', a[5]);
\r
1170 public void TestLastIndexOf() {
\r
1172 //bool errorThrown = false;
\r
1174 //ArrayList a = new ArrayList(1);
\r
1175 //int i = a.LastIndexOf('a', -1);
\r
1176 //} catch (ArgumentOutOfRangeException) {
\r
1177 //errorThrown = true;
\r
1179 //Assert("first negative lastindexof error not thrown",
\r
1183 bool errorThrown = false;
\r
1185 ArrayList a = new ArrayList(1);
\r
1186 int i = a.LastIndexOf('a', 2);
\r
1187 } catch (ArgumentOutOfRangeException) {
\r
1188 errorThrown = true;
\r
1190 Assert("past-end lastindexof error not thrown",
\r
1194 //bool errorThrown = false;
\r
1196 //ArrayList a = new ArrayList(1);
\r
1197 //int i = a.LastIndexOf('a', 0, -1);
\r
1198 //} catch (ArgumentOutOfRangeException) {
\r
1199 //errorThrown = true;
\r
1201 //Assert("second negative lastindexof error not thrown",
\r
1205 //bool errorThrown = false;
\r
1207 //ArrayList a = new ArrayList(1);
\r
1208 //int i = a.LastIndexOf('a', 0, 2);
\r
1209 //} catch (ArgumentOutOfRangeException) {
\r
1210 //errorThrown = true;
\r
1212 //Assert("past-end lastindexof error not thrown",
\r
1216 //bool errorThrown = false;
\r
1218 //ArrayList a = new ArrayList(2);
\r
1219 //int i = a.LastIndexOf('a', 0, 2);
\r
1220 //} catch (ArgumentOutOfRangeException) {
\r
1221 //errorThrown = true;
\r
1223 //Assert("past-end lastindexof error not thrown",
\r
1228 char[] c = {'a', 'b', 'c', 'd', 'e'};
\r
1229 ArrayList a = new ArrayList(c);
\r
1230 AssertEquals("never find null",
\r
1231 -1, a.LastIndexOf(null));
\r
1233 AssertEquals("never find null",
\r
1234 -1, a.LastIndexOf(null, 4));
\r
1236 AssertEquals("never find null",
\r
1237 -1, a.LastIndexOf(null, 4, 5));
\r
1239 AssertEquals("can't find elem",
\r
1240 2, a.LastIndexOf('c'));
\r
1242 AssertEquals("can't find elem",
\r
1243 2, a.LastIndexOf('c', 4));
\r
1245 AssertEquals("can't find elem",
\r
1246 2, a.LastIndexOf('c', 3, 2));
\r
1248 AssertEquals("shouldn't find elem",
\r
1249 -1, a.LastIndexOf('c', 4, 2));
\r
1251 AssertEquals("shouldn't find", -1, a.LastIndexOf('?'));
\r
1253 AssertEquals("shouldn't find", -1, a.LastIndexOf(1));
\r
1254 } catch (Exception e) {
\r
1255 Fail ("Unexpected exception caught when iTest=" + iTest + ". e=" + e);
\r
1260 [ExpectedException (typeof (ArgumentOutOfRangeException))]
\r
1261 public void LastIndexOf_StartIndexOverflow ()
\r
1263 ArrayList al = new ArrayList ();
\r
1265 al.LastIndexOf ('a', Int32.MaxValue, 1);
\r
1269 [ExpectedException (typeof (ArgumentOutOfRangeException))]
\r
1270 public void LastIndexOf_CountOverflow ()
\r
1272 ArrayList al = new ArrayList ();
\r
1274 al.LastIndexOf ('a', 1, Int32.MaxValue);
\r
1277 public void TestReadOnly() {
\r
1279 bool errorThrown = false;
\r
1281 ArrayList al1 = ArrayList.ReadOnly(null);
\r
1282 } catch (ArgumentNullException) {
\r
1283 errorThrown = true;
\r
1285 Assert("null arg error not thrown", errorThrown);
\r
1288 ArrayList al1 = new ArrayList();
\r
1289 AssertEquals("arrays start writeable.",
\r
1290 false, al1.IsReadOnly);
\r
1291 ArrayList al2 = ArrayList.ReadOnly(al1);
\r
1292 AssertEquals("should be readonly.",
\r
1293 true, al2.IsReadOnly);
\r
1297 public void TestRemove() {
\r
1299 bool errorThrown = false;
\r
1302 ArrayList.FixedSize(new ArrayList(3));
\r
1304 } catch (NotSupportedException) {
\r
1305 errorThrown = true;
\r
1307 Assert("remove fixed size error not thrown",
\r
1311 bool errorThrown = false;
\r
1314 ArrayList.ReadOnly(new ArrayList(3));
\r
1316 } catch (NotSupportedException) {
\r
1317 errorThrown = true;
\r
1319 Assert("remove read only error not thrown",
\r
1323 char[] c = {'a','b','c'};
\r
1324 ArrayList a = new ArrayList(c);
\r
1327 AssertEquals("should be unchanged", c.Length, a.Count);
\r
1329 AssertEquals("should be changed", 2, a.Count);
\r
1330 AssertEquals("should have shifted", 'b', a[0]);
\r
1331 AssertEquals("should have shifted", 'c', a[1]);
\r
1335 public void TestRemoveAt() {
\r
1337 bool errorThrown = false;
\r
1340 ArrayList.FixedSize(new ArrayList(3));
\r
1342 } catch (NotSupportedException) {
\r
1343 errorThrown = true;
\r
1345 Assert("remove from fixed size error not thrown",
\r
1349 bool errorThrown = false;
\r
1352 ArrayList.ReadOnly(new ArrayList(3));
\r
1354 } catch (NotSupportedException) {
\r
1355 errorThrown = true;
\r
1357 Assert("remove from read only error not thrown",
\r
1361 bool errorThrown = false;
\r
1363 ArrayList al1 = new ArrayList(3);
\r
1365 } catch (ArgumentOutOfRangeException) {
\r
1366 errorThrown = true;
\r
1368 Assert("remove at negative index error not thrown",
\r
1372 bool errorThrown = false;
\r
1374 ArrayList al1 = new ArrayList(3);
\r
1376 } catch (ArgumentOutOfRangeException) {
\r
1377 errorThrown = true;
\r
1379 Assert("remove at out-of-range index error not thrown",
\r
1383 char[] c = {'a','b','c'};
\r
1384 ArrayList a = new ArrayList(c);
\r
1386 AssertEquals("should be changed", 2, a.Count);
\r
1387 AssertEquals("should have shifted", 'b', a[0]);
\r
1388 AssertEquals("should have shifted", 'c', a[1]);
\r
1392 public void TestRemoveRange() {
\r
1394 bool errorThrown = false;
\r
1397 ArrayList.FixedSize(new ArrayList(3));
\r
1398 al1.RemoveRange(0, 1);
\r
1399 } catch (NotSupportedException) {
\r
1400 errorThrown = true;
\r
1402 Assert("removerange from fixed size error not thrown",
\r
1406 bool errorThrown = false;
\r
1409 ArrayList.ReadOnly(new ArrayList(3));
\r
1410 al1.RemoveRange(0, 1);
\r
1411 } catch (NotSupportedException) {
\r
1412 errorThrown = true;
\r
1414 Assert("removerange from read only error not thrown",
\r
1418 bool errorThrown = false;
\r
1420 ArrayList al1 = new ArrayList(3);
\r
1421 al1.RemoveRange(-1, 1);
\r
1422 } catch (ArgumentOutOfRangeException) {
\r
1423 errorThrown = true;
\r
1425 Assert("removerange at negative index error not thrown",
\r
1429 bool errorThrown = false;
\r
1431 ArrayList al1 = new ArrayList(3);
\r
1432 al1.RemoveRange(0, -1);
\r
1433 } catch (ArgumentOutOfRangeException) {
\r
1434 errorThrown = true;
\r
1436 Assert("removerange at negative index error not thrown",
\r
1440 bool errorThrown = false;
\r
1442 ArrayList al1 = new ArrayList(3);
\r
1443 al1.RemoveRange(2, 3);
\r
1444 } catch (ArgumentException) {
\r
1445 errorThrown = true;
\r
1447 Assert("removerange at bad range error not thrown",
\r
1451 char[] c = {'a','b','c'};
\r
1452 ArrayList a = new ArrayList(c);
\r
1453 a.RemoveRange(1,2);
\r
1454 AssertEquals("should be changed", 1, a.Count);
\r
1455 AssertEquals("should have shifted", 'a', a[0]);
\r
1460 [ExpectedException (typeof (ArgumentException))]
\r
1461 public void RemoveRange_IndexOverflow ()
\r
1463 ArrayList al = new ArrayList ();
\r
1465 al.RemoveRange (Int32.MaxValue, 1);
\r
1469 [ExpectedException (typeof (ArgumentException))]
\r
1470 public void RemoveRange_CountOverflow ()
\r
1472 ArrayList al = new ArrayList ();
\r
1474 al.RemoveRange (1, Int32.MaxValue);
\r
1477 public void TestRepeat() {
\r
1479 bool errorThrown = false;
\r
1481 ArrayList al1 = ArrayList.Repeat('c', -1);
\r
1482 } catch (ArgumentOutOfRangeException) {
\r
1483 errorThrown = true;
\r
1485 Assert("repeat negative copies error not thrown",
\r
1489 ArrayList al1 = ArrayList.Repeat("huh?", 0);
\r
1490 AssertEquals("should be nothing in array",
\r
1494 ArrayList al1 = ArrayList.Repeat("huh?", 3);
\r
1495 AssertEquals("should be something in array",
\r
1497 AssertEquals("array elem doesn't check",
\r
1499 AssertEquals("array elem doesn't check",
\r
1501 AssertEquals("array elem doesn't check",
\r
1506 public void TestReverse() {
\r
1508 bool errorThrown = false;
\r
1511 ArrayList.ReadOnly(new ArrayList());
\r
1513 } catch (NotSupportedException) {
\r
1514 errorThrown = true;
\r
1516 Assert("reverse on read only error not thrown",
\r
1520 bool errorThrown = false;
\r
1522 char[] c = new Char[2];
\r
1523 ArrayList al1 = new ArrayList(c);
\r
1524 al1.Reverse(0, 3);
\r
1525 } catch (ArgumentException) {
\r
1526 errorThrown = true;
\r
1528 Assert("error not thrown", errorThrown);
\r
1531 bool errorThrown = false;
\r
1533 char[] c = new Char[2];
\r
1534 ArrayList al1 = new ArrayList(c);
\r
1535 al1.Reverse(3, 0);
\r
1536 } catch (ArgumentException) {
\r
1537 errorThrown = true;
\r
1539 Assert("error not thrown", errorThrown);
\r
1542 char[] c = {'a', 'b', 'c', 'd', 'e'};
\r
1543 ArrayList al1 = new ArrayList(c);
\r
1545 for (int i = 0; i < al1.Count; i++) {
\r
1546 AssertEquals("Should be no change yet",
\r
1550 for (int i = 0; i < al1.Count; i++) {
\r
1551 AssertEquals("Should be reversed",
\r
1555 for (int i = 0; i < al1.Count; i++) {
\r
1556 AssertEquals("Should be back to normal",
\r
1560 AssertEquals("Should be back to normal", c[0], al1[0]);
\r
1561 AssertEquals("Should be back to normal", c[3], al1[1]);
\r
1562 AssertEquals("Should be back to normal", c[2], al1[2]);
\r
1563 AssertEquals("Should be back to normal", c[1], al1[3]);
\r
1564 AssertEquals("Should be back to normal", c[4], al1[4]);
\r
1569 [ExpectedException (typeof (ArgumentException))]
\r
1570 public void Reverse_IndexOverflow ()
\r
1572 ArrayList al = new ArrayList ();
\r
1574 al.Reverse (Int32.MaxValue, 1);
\r
1578 [ExpectedException (typeof (ArgumentException))]
\r
1579 public void Reverse_CountOverflow ()
\r
1581 ArrayList al = new ArrayList ();
\r
1583 al.Reverse (1, Int32.MaxValue);
\r
1586 public void TestSetRange() {
\r
1588 bool errorThrown = false;
\r
1590 char[] c = {'a', 'b', 'c'};
\r
1592 ArrayList.ReadOnly(new ArrayList(3));
\r
1593 al1.SetRange(0, c);
\r
1594 } catch (NotSupportedException) {
\r
1595 errorThrown = true;
\r
1596 } catch (Exception e) {
\r
1597 Fail ("Incorrect exception thrown at 1: " + e.ToString());
\r
1599 Assert("setrange on read only error not thrown",
\r
1603 bool errorThrown = false;
\r
1605 ArrayList al1 = new ArrayList(3);
\r
1606 al1.SetRange(0, null);
\r
1607 } catch (ArgumentNullException) {
\r
1608 errorThrown = true;
\r
1609 } catch (ArgumentOutOfRangeException) {
\r
1610 errorThrown = true;
\r
1611 } catch (Exception e) {
\r
1612 Fail ("Incorrect exception thrown at 2: " + e.ToString());
\r
1614 Assert("setrange with null error not thrown",
\r
1618 bool errorThrown = false;
\r
1620 char[] c = {'a', 'b', 'c'};
\r
1621 ArrayList al1 = new ArrayList(3);
\r
1622 al1.SetRange(-1, c);
\r
1623 } catch (ArgumentOutOfRangeException) {
\r
1624 errorThrown = true;
\r
1625 } catch (Exception e) {
\r
1626 Fail ("Incorrect exception thrown at 3: " + e.ToString());
\r
1628 Assert("setrange with negative index error not thrown",
\r
1632 bool errorThrown = false;
\r
1634 char[] c = {'a', 'b', 'c'};
\r
1635 ArrayList al1 = new ArrayList(3);
\r
1636 al1.SetRange(2, c);
\r
1637 } catch (ArgumentOutOfRangeException) {
\r
1638 errorThrown = true;
\r
1639 } catch (Exception e) {
\r
1640 Fail ("Incorrect exception thrown at 4: " + e.ToString());
\r
1642 Assert("setrange with too much error not thrown",
\r
1647 char[] c = {'a', 'b', 'c'};
\r
1648 ArrayList al1 = ArrayList.Repeat('?', 3);
\r
1649 Assert("no match yet", c[0] != (char)al1[0]);
\r
1650 Assert("no match yet", c[1] != (char)al1[1]);
\r
1651 Assert("no match yet", c[2] != (char)al1[2]);
\r
1652 al1.SetRange(0, c);
\r
1653 AssertEquals("should match", c[0], al1[0]);
\r
1654 AssertEquals("should match", c[1], al1[1]);
\r
1655 AssertEquals("should match", c[2], al1[2]);
\r
1660 [ExpectedException (typeof (ArgumentOutOfRangeException))]
\r
1661 public void SetRange_Overflow ()
\r
1663 ArrayList al = new ArrayList ();
\r
1665 al.SetRange (Int32.MaxValue, new ArrayList ());
\r
1668 public void TestInsertRange_this() {
\r
1669 String[] s1 = {"this", "is", "a", "test"};
\r
1670 ArrayList al = new ArrayList(s1);
\r
1671 al.InsertRange(2, al);
\r
1672 String[] s2 = {"this", "is", "this", "is", "a", "test", "a", "test"};
\r
1673 for (int i=0; i < al.Count; i++) {
\r
1674 AssertEquals("at i=" + i, s2[i], al[i]);
\r
1678 public void TestSort() {
\r
1680 bool errorThrown = false;
\r
1683 ArrayList.ReadOnly(new ArrayList());
\r
1685 } catch (NotSupportedException) {
\r
1686 errorThrown = true;
\r
1688 Assert("sort on read only error not thrown",
\r
1692 char[] starter = {'d', 'b', 'f', 'e', 'a', 'c'};
\r
1693 ArrayList al1 = new ArrayList(starter);
\r
1695 AssertEquals("Should be sorted", 'a', al1[0]);
\r
1696 AssertEquals("Should be sorted", 'b', al1[1]);
\r
1697 AssertEquals("Should be sorted", 'c', al1[2]);
\r
1698 AssertEquals("Should be sorted", 'd', al1[3]);
\r
1699 AssertEquals("Should be sorted", 'e', al1[4]);
\r
1700 AssertEquals("Should be sorted", 'f', al1[5]);
\r
1703 ArrayList al1 = new ArrayList ();
\r
1712 AssertEquals ("Should be null", null, al1 [0]);
\r
1713 AssertEquals ("Should be 2. null", null, al1 [1]);
\r
1714 AssertEquals ("Should be 3. null", null, al1 [2]);
\r
1715 AssertEquals ("Should be 4. null", null, al1 [3]);
\r
1716 AssertEquals ("Should be 32", 32, al1 [4]);
\r
1717 AssertEquals ("Should be 33", 33, al1 [5]);
\r
1722 [ExpectedException (typeof (ArgumentException))]
\r
1723 public void Sort_IndexOverflow ()
\r
1725 ArrayList al = new ArrayList ();
\r
1727 al.Sort (Int32.MaxValue, 1, null);
\r
1731 [ExpectedException (typeof (ArgumentException))]
\r
1732 public void Sort_CountOverflow ()
\r
1734 ArrayList al = new ArrayList ();
\r
1736 al.Sort (1, Int32.MaxValue, null);
\r
1739 // TODO - Sort with IComparers
\r
1741 // TODO - Synchronize
\r
1743 public void TestToArray() {
\r
1745 bool errorThrown = false;
\r
1747 ArrayList al1 = new ArrayList(3);
\r
1748 al1.ToArray(null);
\r
1749 } catch (ArgumentNullException) {
\r
1750 errorThrown = true;
\r
1752 Assert("toarray with null error not thrown",
\r
1756 bool errorThrown = false;
\r
1758 char[] c = {'a', 'b', 'c'};
\r
1759 string s = "huh?";
\r
1760 ArrayList al1 = new ArrayList(c);
\r
1761 al1.ToArray(s.GetType());
\r
1762 } catch (InvalidCastException) {
\r
1763 errorThrown = true;
\r
1765 Assert("toarray with bad type error not thrown",
\r
1769 char[] c1 = {'a', 'b', 'c', 'd', 'e'};
\r
1770 ArrayList al1 = new ArrayList(c1);
\r
1771 object[] o2 = al1.ToArray();
\r
1772 for (int i = 0; i < c1.Length; i++) {
\r
1773 AssertEquals("should be copy", c1[i], o2[i]);
\r
1775 Array c2 = al1.ToArray(c1[0].GetType());
\r
1776 for (int i = 0; i < c1.Length; i++) {
\r
1777 AssertEquals("should be copy",
\r
1778 c1[i], c2.GetValue(i));
\r
1783 public void TestTrimToSize() {
\r
1785 bool errorThrown = false;
\r
1788 ArrayList.ReadOnly(new ArrayList());
\r
1790 } catch (NotSupportedException) {
\r
1791 errorThrown = true;
\r
1793 Assert("trim read only error not thrown",
\r
1797 ArrayList al1 = new ArrayList();
\r
1798 int capacity = al1.Capacity;
\r
1799 int size = capacity / 2;
\r
1800 for (int i = 1; i <=size; i++) {
\r
1805 AssertEquals("no capacity match",
\r
1806 size - 1, al1.Capacity);
\r
1810 AssertEquals("no default capacity",
\r
1811 capacity, al1.Capacity);
\r