3 // Unit tests for System.Collections.ArrayList
5 // Copyright (c) 2003 Thong (Tum) Nguyen [tum@veridicus.com]
7 // Released under the MIT License:
9 // http://www.opensource.org/licenses/mit-license.html
11 // Permission is hereby granted, free of charge, to any person obtaining a copy of this
12 // software and associated documentation files (the "Software"), to deal in the
13 // Software without restriction, including without limitation the rights to use, copy,
14 // modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
15 // and to permit persons to whom the Software is furnished to do so, subject to the
16 // following conditions:
18 // The above copyright notice and this permission notice shall be included in all copies
19 // or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
25 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 // Author's comment: Source code formatting has been changed by request to match
31 // Mono's formatting style. I personally use BSD-style formatting.
35 using System.Collections;
36 using NUnit.Framework;
38 namespace MonoTests.System.Collections
41 /// Some test cases for the new ArrayList implementation.
44 public class NewArrayListTest
47 private object[] c_TestData = new Object[] {0,1,2,3,4,5,6,7,8,9};
49 private void VerifyContains(IList list, IList values, string message)
51 if (values.Count != list.Count)
53 Assertion.Assert(message, false);
56 for (int i = 0; i < list.Count; i++)
58 if (list[i] == null && values[i] == null)
63 if ((list[i] == null || values[i] == null) || !list[i].Equals(values[i]))
65 Assertion.Assert(message, false);
70 private void PrivateTestSort(ArrayList arrayList)
72 Random random = new Random(1027);
74 // Sort arrays of lengths up to 200
76 for (int i = 1; i < 200; i++)
78 for (int j = 0; j < i; j++)
80 arrayList.Add(random.Next(0, 1000));
85 for (int j = 1; j < i; j++)
87 if ((int)arrayList[j] < (int)arrayList[j - 1])
89 Assertion.Fail("ArrayList.Sort()");
100 public void TestSortStandard()
102 PrivateTestSort(new ArrayList());
106 public void TestSortSynchronized()
108 PrivateTestSort(ArrayList.Synchronized(new ArrayList()));
112 public void TestSortAdapter()
114 PrivateTestSort(ArrayList.Adapter(new ArrayList()));
118 public void TestSortGetRange()
120 PrivateTestSort(new ArrayList().GetRange(0, 0));
123 private void PrivateTestIndexOf(ArrayList arrayList)
127 arrayList.AddRange(c_TestData);
129 for (int i = 0; i < 10; i++)
131 x = arrayList.IndexOf(i);
132 Assertion.Assert("ArrayList.IndexOf(" + i + ")", x == i);
137 arrayList.IndexOf(0, 10, 1);
138 Assertion.Fail("ArrayList.IndexOf(0, 10, 1)");
140 catch (ArgumentOutOfRangeException)
146 arrayList.IndexOf(0, 0, -1);
147 Assertion.Fail("ArrayList.IndexOf(0, 10, 1)");
149 catch (ArgumentOutOfRangeException)
155 arrayList.IndexOf(0, -1, -1);
156 Assertion.Fail("ArrayList.IndexOf(0, 10, 1)");
158 catch (ArgumentOutOfRangeException)
164 arrayList.IndexOf(0, 9, 10);
165 Assertion.Fail("ArrayList.IndexOf(0, 10, 1)");
167 catch (ArgumentOutOfRangeException)
173 arrayList.IndexOf(0, 0, 10);
175 catch (ArgumentOutOfRangeException)
177 Assertion.Fail("ArrayList.IndexOf(0, 10, 1)");
182 arrayList.IndexOf(0, 0, 11);
183 Assertion.Fail("ArrayList.IndexOf(0, 10, 1)");
185 catch (ArgumentOutOfRangeException)
191 for (int i = 0; i < 10; i++)
193 x = arrayList.LastIndexOf(i);
195 Assertion.Assert("ArrayList.LastIndexOf(" + i + ")", x == i);
200 arrayList.IndexOf(0, 10, 1);
202 Assertion.Fail("ArrayList.LastIndexOf(0, 10, 1)");
204 catch (ArgumentOutOfRangeException)
210 arrayList.IndexOf(0, 0, -1);
212 Assertion.Fail("ArrayList.LastIndexOf(0, 10, 1)");
214 catch (ArgumentOutOfRangeException)
220 arrayList.LastIndexOf(0, -1, -1);
222 Assertion.Fail("ArrayList.LastIndexOf(0, 10, 1)");
224 catch (ArgumentOutOfRangeException)
230 arrayList.LastIndexOf(0, 9, 10);
232 catch (ArgumentOutOfRangeException)
234 Assertion.Fail("ArrayList.LastIndexOf(0, 10, 1)");
239 arrayList.LastIndexOf(0, 0, 10);
240 Assertion.Fail("ArrayList.LastIndexOf(0, 10, 1)");
242 catch (ArgumentOutOfRangeException)
248 arrayList.LastIndexOf(0, 0, 11);
249 Assertion.Fail("ArrayList.LastIndexOf(0, 10, 1)");
251 catch (ArgumentOutOfRangeException)
256 private void PrivateTestAddRange(ArrayList arrayList)
258 arrayList.AddRange(c_TestData);
259 arrayList.AddRange(c_TestData);
261 VerifyContains(arrayList, new object[] {0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9}, "VerifyContains");
265 public void TestAddRangeStandard()
267 PrivateTestAddRange(new ArrayList());
271 public void TestAddRangeSynchronized()
273 PrivateTestAddRange(ArrayList.Synchronized(new ArrayList()));
277 public void TestAddRangeAdapter()
279 PrivateTestAddRange(ArrayList.Adapter(new ArrayList()));
283 public void TestAddRangeGetRange()
285 PrivateTestAddRange(new ArrayList().GetRange(0, 0));
289 public void TestIndexOfStandard()
291 PrivateTestIndexOf(new ArrayList());
295 public void TestIndexOfSynchronized()
297 PrivateTestIndexOf(ArrayList.Synchronized(new ArrayList()));
301 public void TestIndexOfAdapter()
303 PrivateTestIndexOf(ArrayList.Adapter(new ArrayList()));
307 public void TestIndexOfGetRange()
309 PrivateTestIndexOf(new ArrayList().GetRange(0, 0));
313 public void TestReadOnly()
315 ArrayList arrayList, readOnlyList;
317 arrayList = new ArrayList();
318 readOnlyList = ArrayList.ReadOnly(arrayList);
320 arrayList.AddRange(c_TestData);
322 // Make sure the readOnlyList is a wrapper and not a clone.
325 Assertion.Assert("readOnlyList.Count == 11", readOnlyList.Count == 11);
330 Assertion.Fail("readOnlyList.Add(0)");
332 catch (NotSupportedException)
338 readOnlyList.AddRange(c_TestData);
340 Assertion.Fail("readOnlyList.AddRange(c_TestData)");
342 catch (NotSupportedException)
348 readOnlyList.BinarySearch(1);
350 catch (NotSupportedException)
352 Assertion.Fail("readOnlyList.BinarySearch(1)");
357 int x = readOnlyList.Capacity;
359 catch (NotSupportedException)
361 Assertion.Fail("readOnlyList.Capacity");
366 readOnlyList.Clear();
367 Assertion.Fail("readOnlyList.Clear()");
369 catch (NotSupportedException)
375 readOnlyList.Clone();
377 catch (NotSupportedException)
379 Assertion.Fail("readOnlyList.Clone()");
384 readOnlyList.Contains(1);
386 catch (NotSupportedException)
388 Assertion.Fail("readOnlyList.Contains");
393 readOnlyList.CopyTo(new object[readOnlyList.Count]);
395 catch (NotSupportedException)
397 Assertion.Fail("readOnlyList.CopyTo(new Array(readOnlyList.Count))");
402 foreach (object o in readOnlyList)
407 catch (NotSupportedException)
409 Assertion.Fail("readOnlyList.GetEnumerator()");
414 readOnlyList.GetRange(0, 1);
416 catch (NotSupportedException)
418 Assertion.Fail("readOnlyList.GetRange(0, 1)");
423 readOnlyList.IndexOf(1);
425 catch (NotSupportedException)
427 Assertion.Fail("readOnlyList.readOnlyList.IndexOf(1)");
433 Assertion.Fail("readOnlyList[0] = 0");
435 catch (NotSupportedException)
441 readOnlyList.IndexOf(0);
443 catch (NotSupportedException)
445 Assertion.Fail("readOnlyList.IndexOf(0)");
450 readOnlyList.InsertRange(0, new object[] {1,2});
452 Assertion.Fail("readOnlyList.InsertRange(0, new object[] {1,2})");
454 catch (NotSupportedException)
460 readOnlyList.LastIndexOf(1111);
462 catch (NotSupportedException)
464 Assertion.Fail("readOnlyList.LastIndexOf(1)");
469 readOnlyList.Remove(1);
471 Assertion.Fail("readOnlyList.Remove(1)");
473 catch (NotSupportedException)
479 readOnlyList.RemoveAt(1);
481 Assertion.Fail("readOnlyList.RemoveAt(1)");
483 catch (NotSupportedException)
489 readOnlyList.RemoveRange(0, 1);
491 Assertion.Fail("readOnlyList.RemoveRange(0, 1)");
493 catch (NotSupportedException)
499 readOnlyList.Reverse();
501 Assertion.Fail("readOnlyList.Reverse()");
503 catch (NotSupportedException)
509 readOnlyList.SetRange(0, new Object[] {0, 1});
511 Assertion.Fail("readOnlyList.SetRange(0, new Object[] {0, 1})");
513 catch (NotSupportedException)
521 Assertion.Fail("readOnlyList.Sort()");
523 catch (NotSupportedException)
529 readOnlyList.ToArray();
531 catch (NotSupportedException)
533 Assertion.Fail("readOnlyList.ToArray()");
538 readOnlyList.TrimToSize();
540 Assertion.Fail("readOnlyList.TrimToSize()");
542 catch (NotSupportedException)
548 public void TestFixedSize()
550 ArrayList arrayList, fixedSizeList;
552 arrayList = new ArrayList();
553 fixedSizeList = ArrayList.FixedSize(arrayList);
555 arrayList.AddRange(c_TestData);
557 // Make sure the fixedSizeList is a wrapper and not a clone.
560 Assertion.Assert("fixedSizeList.Count == 11", fixedSizeList.Count == 11);
564 fixedSizeList.Add(0);
565 Assertion.Fail("fixedSizeList.Add(0)");
567 catch (NotSupportedException)
573 fixedSizeList.Remove(0);
574 Assertion.Fail("fixedSizeList.Remove(0)");
576 catch (NotSupportedException)
582 fixedSizeList.RemoveAt(0);
583 Assertion.Fail("fixedSizeList.RemoveAt(0)");
585 catch (NotSupportedException)
591 fixedSizeList.Clear();
592 Assertion.Fail("fixedSizeList.Clear()");
594 catch (NotSupportedException)
600 fixedSizeList[0] = 0;
602 catch (NotSupportedException)
604 Assertion.Fail("fixedSizeList[0] = 0");
609 fixedSizeList.Clear();
610 Assertion.Fail("fixedSizeList.Clear()");
612 catch (NotSupportedException)
618 fixedSizeList.Contains(1);
620 catch (NotSupportedException)
622 Assertion.Fail("fixedSizeList.Contains");
627 int x = fixedSizeList.Count;
629 catch (NotSupportedException)
631 Assertion.Fail("fixedSizeList.Count");
636 fixedSizeList.GetRange(0, 1);
638 catch (NotSupportedException)
640 Assertion.Fail("fixedSizeList.GetRange(0, 1)");
645 fixedSizeList.IndexOf(0);
647 catch (NotSupportedException)
649 Assertion.Fail("fixedSizeList.IndexOf(0)");
654 fixedSizeList.InsertRange(0, new object[] {1,2});
656 Assertion.Fail("fixedSizeList.InsertRange(0, new object[] {1,2})");
658 catch (NotSupportedException)
664 fixedSizeList.Reverse();
666 catch (NotSupportedException)
668 Assertion.Fail("fixedSizeList.Reverse()");
673 fixedSizeList.SetRange(0, new Object[] {0, 1});
675 catch (NotSupportedException)
677 Assertion.Fail("fixedSizeList.SetRange(0, new Object[] {0, 1})");
682 fixedSizeList.Sort();
684 catch (NotSupportedException)
686 Assertion.Fail("fixedSizeList.Sort()");
691 fixedSizeList.ToArray();
693 catch (NotSupportedException)
695 Assertion.Fail("fixedSizeList.ToArray()");
700 fixedSizeList.TrimToSize();
702 Assertion.Fail("fixedSizeList.TrimToSize()");
704 catch (NotSupportedException)
710 fixedSizeList.Clone();
712 catch (NotSupportedException)
714 Assertion.Fail("fixedSizeList.Clone()");
719 fixedSizeList.AddRange(c_TestData);
721 Assertion.Fail("fixedSizeList.AddRange(c_TestData)");
723 catch (NotSupportedException)
728 private void PrivateTestClone(ArrayList arrayList)
730 ArrayList arrayList2;
732 arrayList.AddRange(c_TestData);
734 arrayList2 = (ArrayList)arrayList.Clone();
736 VerifyContains(arrayList2, c_TestData, "arrayList.Clone()");
740 public void TestCloneStandard()
742 PrivateTestClone(new ArrayList());
746 public void TestCloneSynchronized()
748 PrivateTestClone(ArrayList.Synchronized(new ArrayList()));
752 public void TestCloneAdapter()
754 PrivateTestClone(ArrayList.Adapter(new ArrayList()));
758 public void TestCloneGetRange()
760 PrivateTestClone(new ArrayList().GetRange(0, 0));
763 private void PrivateTestCopyTo(ArrayList arrayList)
767 arrayList.AddRange(c_TestData);
769 array = new Object[arrayList.Count];
771 arrayList.CopyTo(array);
773 VerifyContains(array, new object[] {0,1,2,3,4,5,6,7,8,9}, "ArrayList.CopyTo(array)");
775 array = new Object[3];
777 arrayList.CopyTo(0, array, 0, 3);
779 VerifyContains(array, new object[] {0,1,2}, "ArrayList.CopyTo(0, array, 0, 3)");
781 array = new Object[4];
783 arrayList.CopyTo(0, array, 1, 3);
785 VerifyContains(array, new object[] {null,0, 1, 2}, "ArrayList.CopyTo(0, array, 1, 3)");
787 array = new object[10];
789 arrayList.CopyTo(3, array, 3, 5);
791 VerifyContains(array, new object[] {null, null, null, 3, 4, 5, 6, 7, null, null}, "VerifyContains(array, ...)");
795 public void TestCopyToStandard()
797 PrivateTestCopyTo(new ArrayList());
801 public void TestCopyToSynchronized()
803 PrivateTestCopyTo(ArrayList.Synchronized(new ArrayList()));
807 public void TestCopyToAdapter()
809 PrivateTestCopyTo(ArrayList.Adapter(new ArrayList()));
813 public void TestCopyToGetRange()
815 PrivateTestCopyTo(new ArrayList().GetRange(0, 0));
818 private void PrivateTestSetCapacity(ArrayList arrayList)
822 arrayList.AddRange(c_TestData);
824 x = arrayList.Capacity;
826 arrayList.Capacity = x * 2;
828 Assert("arrayList.Capacity == x * 2", arrayList.Capacity == x * 2);
830 VerifyContains(arrayList, c_TestData, "VerifyContains(arrayList, c_TestData)");
834 public void TestSetCapacity()
836 PrivateTestSetCapacity(new ArrayList());
840 public void TestSetCapacitySynchronized()
842 PrivateTestSetCapacity(ArrayList.Synchronized(new ArrayList()));
846 public void TestCapacityExpands()
848 ArrayList arrayList = new ArrayList(10);
850 arrayList.AddRange(c_TestData);
852 Assertion.Assert("arrayList.Capacity == 10", arrayList.Capacity == 10);
856 Assertion.Assert("arrayList.Capacity == 20", arrayList.Capacity == 20);
858 VerifyContains(arrayList, new object[] {0,1,2,3,4,5,6,7,8,9,10}, "VerifyContains");
861 private void PrivateTestBinarySearch(ArrayList arrayList)
863 // Try searching with different size lists...
865 for (int x = 0; x < 10; x++)
867 for (int i = 0; i < x; i++)
872 for (int i = 0; i < x; i++)
876 y = arrayList.BinarySearch(i);
878 Assertion.Equals(y, i);
883 arrayList.Add(new object());
887 arrayList.BinarySearch(new object());
889 Assertion.Fail("1: Binary search on object that doesn't support IComparable.");
891 catch (ArgumentException)
894 catch (InvalidOperationException)
896 // LAMESPEC: ArrayList.BinarySearch() on MS.NET throws InvalidOperationException
901 arrayList.BinarySearch(1);
903 Assertion.Fail("2: Binary search on incompatible object.");
905 catch (ArgumentException)
908 catch (InvalidOperationException)
910 // LAMESPEC: ArrayList.BinarySearch() on MS.NET throws InvalidOperationException
915 for (int i = 0; i < 100; i++)
920 Assertion.Assert("BinarySearch should start in middle.", arrayList.BinarySearch(1) == 49);
921 Assertion.Assert("arrayList.BinarySearch(0, 0, 0, Comparer.Default)", arrayList.BinarySearch(0, 0, 0, Comparer.Default) == -1);
925 public void TestBinarySearchStandard()
927 PrivateTestBinarySearch(new ArrayList());
931 public void TestBinarySearchSynchronized()
933 PrivateTestBinarySearch(ArrayList.Synchronized(new ArrayList()));
937 public void TestBinarySearchAdapter()
939 PrivateTestBinarySearch(ArrayList.Adapter(new ArrayList()));
943 public void TestBinarySearchGetRange()
945 PrivateTestBinarySearch(new ArrayList().GetRange(0, 0));
948 private void PrivateTestRemoveAt(ArrayList arrayList)
958 VerifyContains(arrayList, new object[] {1, 3, 4, 5},
959 "Remove element failed.");
961 arrayList.RemoveAt(0);
963 VerifyContains(arrayList, new object[] {3, 4, 5},
964 "RemoveAt at start failed.");
966 arrayList.RemoveAt(2);
968 VerifyContains(arrayList, new object[] {3, 4},
969 "RemoveAt at end failed.");
973 public void TestRemoveAtStandard()
975 PrivateTestRemoveAt(new ArrayList());
979 public void TestRemoveAtSynchronized()
981 PrivateTestRemoveAt(ArrayList.Synchronized(new ArrayList()));
985 public void TestRemoveAtAdapter()
987 PrivateTestRemoveAt(ArrayList.Adapter(new ArrayList()));
991 public void TestRemoveAtGetRange()
993 PrivateTestRemoveAt(new ArrayList().GetRange(0, 0));
996 private void PrivateTestRemoveRange(ArrayList arrayList)
998 arrayList.AddRange(c_TestData);
1000 arrayList.RemoveRange(0, 3);
1002 VerifyContains(arrayList, new object[] { 3, 4, 5, 6, 7, 8, 9 },
1003 "RemoveRange at start failed.");
1005 arrayList.RemoveRange(4, 3);
1007 VerifyContains(arrayList, new object[] { 3, 4, 5, 6 },
1008 "RemoveRange at start failed.");
1010 arrayList.RemoveRange(2, 1);
1012 VerifyContains(arrayList, new object[] { 3, 4, 6 },
1013 "RemoveRange in middle failed.");
1017 public void TestRemoveRangeStandard()
1019 PrivateTestRemoveRange(new ArrayList());
1023 public void TestRemoveRangeSynchronized()
1025 PrivateTestRemoveRange(ArrayList.Synchronized(new ArrayList()));
1029 public void TestRemoveRangeAdapter()
1031 PrivateTestRemoveRange(ArrayList.Adapter(new ArrayList()));
1035 public void TestRemoveRangeGetRange()
1037 PrivateTestRemoveRange(new ArrayList().GetRange(0, 0));
1040 private void PrivateTestInsert(ArrayList arrayList)
1046 arrayList.Insert(0, 1);
1048 VerifyContains(arrayList, new object[] {1, 1, 2, 3, 4}, "Insert at beginning failed.");
1050 arrayList.Insert(5, 5);
1052 VerifyContains(arrayList, new object[] {1, 1, 2, 3, 4, 5}, "Insert at end failed.");
1054 arrayList.Insert(3, 7);
1056 VerifyContains(arrayList, new object[] {1, 1, 2, 7, 3, 4, 5}, "Insert in middle failed.");
1060 public void TestInsertStandard()
1062 PrivateTestInsert(new ArrayList());
1066 public void TestInsertAdapter()
1068 PrivateTestInsert(ArrayList.Adapter(new ArrayList()));
1072 public void TestInsertSynchronized()
1074 PrivateTestInsert(ArrayList.Synchronized(new ArrayList()));
1078 public void TestInsertGetRange()
1080 PrivateTestInsert(new ArrayList().GetRange(0, 0));
1083 private void PrivateTestGetRange(ArrayList arrayList)
1085 ArrayList rangeList;
1087 arrayList.AddRange(c_TestData);
1089 rangeList = arrayList.GetRange(3, 5);
1091 Assertion.Assert("rangeList.Count == 5", rangeList.Count == 5);
1093 this.VerifyContains(rangeList, new object[] {3,4,5,6,7}, "1: VerifyContains(rangeList)");
1095 //FIXME: If items are removed from the Range, one may not iterate over it on .NET
1097 rangeList.Remove(7);
1099 this.VerifyContains(a2, new object[] {3,4,5,6}, "2: VerifyContains(rangeList)");
1101 rangeList.RemoveAt(0);
1103 this.VerifyContains(a3, new object[] {4,5,6}, "3: VerifyContains(rangeList)");
1110 Assertion.Assert("rangeList.LastIndexOf(6) == 4", rangeList.LastIndexOf(6) == 4);
1114 this.VerifyContains(arrayList, new object[] {0, 1, 2, 3, 4, 5, 6, 6, 7, 11, 8, 9}, "4: VerifyContains(rangeList)");
1119 public void TestGetRangeStandard()
1121 PrivateTestGetRange(new ArrayList());
1125 public void TestGetRangeAdapter()
1127 PrivateTestGetRange(ArrayList.Adapter(new ArrayList()));
1131 public void TestGetRangeSynchronized()
1133 PrivateTestGetRange(ArrayList.Synchronized(new ArrayList()));
1137 public void TestGetRangeGetRange()
1139 PrivateTestGetRange(new ArrayList().GetRange(0, 0));
1142 private void PrivateTestEnumeratorWithRange(ArrayList arrayList)
1144 IEnumerator enumerator;
1146 arrayList.AddRange(c_TestData);
1150 // Test with the range 1 - 3
1152 enumerator = arrayList.GetEnumerator(1, 3);
1156 while (enumerator.MoveNext())
1158 Assertion.Assert("enumerator.Current == x", (int)enumerator.Current == x);
1167 while (enumerator.MoveNext())
1169 Assertion.Assert("enumerator.Current == x", (int)enumerator.Current == x);
1175 // Test with a range covering the whole list.
1177 enumerator = arrayList.GetEnumerator(0, arrayList.Count);
1181 while (enumerator.MoveNext())
1183 Assertion.Assert("enumerator.Current == x", (int)enumerator.Current == x);
1192 while (enumerator.MoveNext())
1194 Assertion.Assert("enumerator.Current == x", (int)enumerator.Current == x);
1199 // Test with a range covering nothing.
1201 enumerator = arrayList.GetEnumerator(arrayList.Count, 0);
1203 Assertion.Assert("!enumerator.MoveNext()", !enumerator.MoveNext());
1207 Assertion.Assert("!enumerator.MoveNext()", !enumerator.MoveNext());
1211 public void TestEnumeratorWithRangeStandard()
1213 PrivateTestEnumeratorWithRange(new ArrayList());
1217 public void TestEnumeratorWithRangeSynchronized()
1219 PrivateTestEnumeratorWithRange(ArrayList.Synchronized(new ArrayList()));
1223 public void TestEnumeratorWithRangeAdapter()
1225 PrivateTestEnumeratorWithRange(ArrayList.Adapter(new ArrayList()));
1229 public void TestEnumeratorWithRangeGetRange()
1231 PrivateTestEnumeratorWithRange(new ArrayList().GetRange(0, 0));
1234 private void PrivateTestEnumerator(ArrayList arrayList)
1238 arrayList.AddRange(c_TestData);
1242 foreach (object o in arrayList)
1246 Assertion.Fail("Arraylist.GetEnumerator()");
1254 IEnumerator enumerator;
1256 enumerator = arrayList.GetEnumerator();
1258 enumerator.MoveNext();
1260 Assert("enumerator.Current == 0", (int)enumerator.Current == 0);
1262 // Invalidate the enumerator.
1268 // According to the spec this should still work even though the enumerator is invalid.
1270 Assert("enumerator.Current == 0", (int)enumerator.Current == 0);
1272 catch (InvalidOperationException)
1274 Assert("enumerator.Current should not fail.", false);
1279 // This should throw an InvalidOperationException.
1281 enumerator.MoveNext();
1283 Assert("enumerator.Current should fail.", false);
1285 catch (InvalidOperationException)
1291 public void TestEnumeratorStandard()
1293 PrivateTestEnumerator(new ArrayList());
1297 public void TestEnumeratorSynchronized()
1299 PrivateTestEnumerator(ArrayList.Synchronized(new ArrayList()));
1303 public void TestEnumeratorAdapter()
1305 PrivateTestEnumerator(ArrayList.Adapter(new ArrayList()));
1309 public void TestEnumeratorGetRange()
1311 PrivateTestEnumerator(new ArrayList().GetRange(0, 0));
1314 private void PrivateTestReverse(ArrayList arrayList)
1316 ArrayList arrayList2;
1318 for (int x = 1; x < 100; x ++)
1320 arrayList2 = (ArrayList)arrayList.Clone();
1322 for (int i = 0; i < x; i++)
1327 arrayList2.Reverse();
1331 // Check that reverse did reverse the adapter.
1333 for (int i = 0; i < x; i++)
1335 if ((int)arrayList2[i] != x - i - 1)
1345 String.Format("Reverse on arrayList failed on list with {0} items.", x),
1352 public void TestReverseStandard()
1354 PrivateTestReverse(new ArrayList());
1358 public void TestReverseAdapter()
1360 ArrayList arrayList = new ArrayList();
1361 ArrayList adapter = ArrayList.Adapter(arrayList);
1363 PrivateTestReverse(adapter);
1365 VerifyContains(adapter, arrayList, "Changing adapter didn't change ArrayList.");
1369 public void TestReverseSynchronized()
1371 PrivateTestReverse(ArrayList.Synchronized(new ArrayList()));
1375 public void TestReverseGetRange()
1377 PrivateTestReverse(new ArrayList().GetRange(0,0));
1381 public void TestIterator ()
1383 ArrayList a = new ArrayList ();
1389 foreach (int b in a)
1391 Assert ("Count should be 6", total == 6);
1395 public void TestIteratorObjects ()
1397 ArrayList a = new ArrayList ();
1404 bool found_null = false;
1405 foreach (object b in a){
1409 Assert ("Should only find one null", false);
1416 Assert ("Should fine one null", found_null);
1417 Assert ("Total should be 4", total == 4);
1418 Assert ("Count should be 3", count == 3);