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
46 private object[] c_TestData = new Object[] {0,1,2,3,4,5,6,7,8,9};
48 private void VerifyContains(IList list, IList values, string message)
50 if (values.Count != list.Count)
52 Assert.Fail (message);
55 for (int i = 0; i < list.Count; i++)
57 if (list[i] == null && values[i] == null)
62 if ((list[i] == null || values[i] == null) || !list[i].Equals(values[i]))
64 Assert.Fail (message);
69 private void PrivateTestSort(ArrayList arrayList)
71 Random random = new Random(1027);
73 // Sort arrays of lengths up to 200
75 for (int i = 1; i < 200; i++)
77 for (int j = 0; j < i; j++)
79 arrayList.Add(random.Next(0, 1000));
84 for (int j = 1; j < i; j++)
86 if ((int)arrayList[j] < (int)arrayList[j - 1])
88 Assert.Fail("ArrayList.Sort()");
99 public void TestSortStandard()
101 PrivateTestSort(new ArrayList());
105 public void TestSortSynchronized()
107 PrivateTestSort(ArrayList.Synchronized(new ArrayList()));
111 public void TestSortAdapter()
113 PrivateTestSort(ArrayList.Adapter(new ArrayList()));
117 public void TestSortGetRange()
119 PrivateTestSort(new ArrayList().GetRange(0, 0));
122 private void PrivateTestIndexOf(ArrayList arrayList)
126 arrayList.AddRange(c_TestData);
128 for (int i = 0; i < 10; i++)
130 x = arrayList.IndexOf(i);
131 Assert.IsTrue(x == i, "ArrayList.IndexOf(" + i + ")");
136 arrayList.IndexOf(0, 10, 1);
137 Assert.Fail("ArrayList.IndexOf(0, 10, 1)");
139 catch (ArgumentOutOfRangeException)
145 arrayList.IndexOf(0, 0, -1);
146 Assert.Fail("ArrayList.IndexOf(0, 10, 1)");
148 catch (ArgumentOutOfRangeException)
154 arrayList.IndexOf(0, -1, -1);
155 Assert.Fail("ArrayList.IndexOf(0, 10, 1)");
157 catch (ArgumentOutOfRangeException)
163 arrayList.IndexOf(0, 9, 10);
164 Assert.Fail("ArrayList.IndexOf(0, 10, 1)");
166 catch (ArgumentOutOfRangeException)
172 arrayList.IndexOf(0, 0, 10);
174 catch (ArgumentOutOfRangeException)
176 Assert.Fail("ArrayList.IndexOf(0, 10, 1)");
181 arrayList.IndexOf(0, 0, 11);
182 Assert.Fail("ArrayList.IndexOf(0, 10, 1)");
184 catch (ArgumentOutOfRangeException)
190 for (int i = 0; i < 10; i++)
192 x = arrayList.LastIndexOf(i);
194 Assert.IsTrue(x == i, "ArrayList.LastIndexOf(" + i + ")");
199 arrayList.IndexOf(0, 10, 1);
201 Assert.Fail("ArrayList.LastIndexOf(0, 10, 1)");
203 catch (ArgumentOutOfRangeException)
209 arrayList.IndexOf(0, 0, -1);
211 Assert.Fail("ArrayList.LastIndexOf(0, 10, 1)");
213 catch (ArgumentOutOfRangeException)
219 arrayList.LastIndexOf(0, -1, -1);
221 Assert.Fail("ArrayList.LastIndexOf(0, 10, 1)");
223 catch (ArgumentOutOfRangeException)
229 arrayList.LastIndexOf(0, 9, 10);
231 catch (ArgumentOutOfRangeException)
233 Assert.Fail("ArrayList.LastIndexOf(0, 10, 1)");
238 arrayList.LastIndexOf(0, 0, 10);
239 Assert.Fail("ArrayList.LastIndexOf(0, 10, 1)");
241 catch (ArgumentOutOfRangeException)
247 arrayList.LastIndexOf(0, 0, 11);
248 Assert.Fail("ArrayList.LastIndexOf(0, 10, 1)");
250 catch (ArgumentOutOfRangeException)
255 private void PrivateTestAddRange(ArrayList arrayList)
257 arrayList.AddRange(c_TestData);
258 arrayList.AddRange(c_TestData);
260 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");
264 public void TestAddRangeStandard()
266 PrivateTestAddRange(new ArrayList());
270 public void TestAddRangeSynchronized()
272 PrivateTestAddRange(ArrayList.Synchronized(new ArrayList()));
276 public void TestAddRangeAdapter()
278 PrivateTestAddRange(ArrayList.Adapter(new ArrayList()));
282 public void TestAddRangeGetRange()
284 PrivateTestAddRange(new ArrayList().GetRange(0, 0));
288 public void TestIndexOfStandard()
290 PrivateTestIndexOf(new ArrayList());
294 public void TestIndexOfSynchronized()
296 PrivateTestIndexOf(ArrayList.Synchronized(new ArrayList()));
300 public void TestIndexOfAdapter()
302 PrivateTestIndexOf(ArrayList.Adapter(new ArrayList()));
306 public void TestIndexOfGetRange()
308 PrivateTestIndexOf(new ArrayList().GetRange(0, 0));
312 public void TestReadOnly()
314 ArrayList arrayList, readOnlyList;
316 arrayList = new ArrayList();
317 readOnlyList = ArrayList.ReadOnly(arrayList);
319 arrayList.AddRange(c_TestData);
321 // Make sure the readOnlyList is a wrapper and not a clone.
324 Assert.IsTrue(readOnlyList.Count == 11, "readOnlyList.Count == 11");
329 Assert.Fail("readOnlyList.Add(0)");
331 catch (NotSupportedException)
337 readOnlyList.AddRange(c_TestData);
339 Assert.Fail("readOnlyList.AddRange(c_TestData)");
341 catch (NotSupportedException)
347 readOnlyList.BinarySearch(1);
349 catch (NotSupportedException)
351 Assert.Fail("readOnlyList.BinarySearch(1)");
356 int x = readOnlyList.Capacity;
358 catch (NotSupportedException)
360 Assert.Fail("readOnlyList.Capacity");
365 readOnlyList.Clear();
366 Assert.Fail("readOnlyList.Clear()");
368 catch (NotSupportedException)
374 readOnlyList.Clone();
376 catch (NotSupportedException)
378 Assert.Fail("readOnlyList.Clone()");
383 readOnlyList.Contains(1);
385 catch (NotSupportedException)
387 Assert.Fail("readOnlyList.Contains");
392 readOnlyList.CopyTo(new object[readOnlyList.Count]);
394 catch (NotSupportedException)
396 Assert.Fail("readOnlyList.CopyTo(new Array(readOnlyList.Count))");
401 foreach (object o in readOnlyList)
406 catch (NotSupportedException)
408 Assert.Fail("readOnlyList.GetEnumerator()");
413 readOnlyList.GetRange(0, 1);
415 catch (NotSupportedException)
417 Assert.Fail("readOnlyList.GetRange(0, 1)");
422 readOnlyList.IndexOf(1);
424 catch (NotSupportedException)
426 Assert.Fail("readOnlyList.readOnlyList.IndexOf(1)");
432 Assert.Fail("readOnlyList[0] = 0");
434 catch (NotSupportedException)
440 readOnlyList.IndexOf(0);
442 catch (NotSupportedException)
444 Assert.Fail("readOnlyList.IndexOf(0)");
449 readOnlyList.InsertRange(0, new object[] {1,2});
451 Assert.Fail("readOnlyList.InsertRange(0, new object[] {1,2})");
453 catch (NotSupportedException)
459 readOnlyList.LastIndexOf(1111);
461 catch (NotSupportedException)
463 Assert.Fail("readOnlyList.LastIndexOf(1)");
468 readOnlyList.Remove(1);
470 Assert.Fail("readOnlyList.Remove(1)");
472 catch (NotSupportedException)
478 readOnlyList.RemoveAt(1);
480 Assert.Fail("readOnlyList.RemoveAt(1)");
482 catch (NotSupportedException)
488 readOnlyList.RemoveRange(0, 1);
490 Assert.Fail("readOnlyList.RemoveRange(0, 1)");
492 catch (NotSupportedException)
498 readOnlyList.Reverse();
500 Assert.Fail("readOnlyList.Reverse()");
502 catch (NotSupportedException)
508 readOnlyList.SetRange(0, new Object[] {0, 1});
510 Assert.Fail("readOnlyList.SetRange(0, new Object[] {0, 1})");
512 catch (NotSupportedException)
520 Assert.Fail("readOnlyList.Sort()");
522 catch (NotSupportedException)
528 readOnlyList.ToArray();
530 catch (NotSupportedException)
532 Assert.Fail("readOnlyList.ToArray()");
537 readOnlyList.TrimToSize();
539 Assert.Fail("readOnlyList.TrimToSize()");
541 catch (NotSupportedException)
547 public void TestFixedSize()
549 ArrayList arrayList, fixedSizeList;
551 arrayList = new ArrayList();
552 fixedSizeList = ArrayList.FixedSize(arrayList);
554 arrayList.AddRange(c_TestData);
556 // Make sure the fixedSizeList is a wrapper and not a clone.
559 Assert.IsTrue(fixedSizeList.Count == 11, "fixedSizeList.Count == 11");
563 fixedSizeList.Add(0);
564 Assert.Fail("fixedSizeList.Add(0)");
566 catch (NotSupportedException)
572 fixedSizeList.Remove(0);
573 Assert.Fail("fixedSizeList.Remove(0)");
575 catch (NotSupportedException)
581 fixedSizeList.RemoveAt(0);
582 Assert.Fail("fixedSizeList.RemoveAt(0)");
584 catch (NotSupportedException)
590 fixedSizeList.Clear();
591 Assert.Fail("fixedSizeList.Clear()");
593 catch (NotSupportedException)
599 fixedSizeList[0] = 0;
601 catch (NotSupportedException)
603 Assert.Fail("fixedSizeList[0] = 0");
608 fixedSizeList.Clear();
609 Assert.Fail("fixedSizeList.Clear()");
611 catch (NotSupportedException)
617 fixedSizeList.Contains(1);
619 catch (NotSupportedException)
621 Assert.Fail("fixedSizeList.Contains");
626 int x = fixedSizeList.Count;
628 catch (NotSupportedException)
630 Assert.Fail("fixedSizeList.Count");
635 fixedSizeList.GetRange(0, 1);
637 catch (NotSupportedException)
639 Assert.Fail("fixedSizeList.GetRange(0, 1)");
644 fixedSizeList.IndexOf(0);
646 catch (NotSupportedException)
648 Assert.Fail("fixedSizeList.IndexOf(0)");
653 fixedSizeList.InsertRange(0, new object[] {1,2});
655 Assert.Fail("fixedSizeList.InsertRange(0, new object[] {1,2})");
657 catch (NotSupportedException)
663 fixedSizeList.Reverse();
665 catch (NotSupportedException)
667 Assert.Fail("fixedSizeList.Reverse()");
672 fixedSizeList.SetRange(0, new Object[] {0, 1});
674 catch (NotSupportedException)
676 Assert.Fail("fixedSizeList.SetRange(0, new Object[] {0, 1})");
681 fixedSizeList.Sort();
683 catch (NotSupportedException)
685 Assert.Fail("fixedSizeList.Sort()");
690 fixedSizeList.ToArray();
692 catch (NotSupportedException)
694 Assert.Fail("fixedSizeList.ToArray()");
699 fixedSizeList.TrimToSize();
701 Assert.Fail("fixedSizeList.TrimToSize()");
703 catch (NotSupportedException)
709 fixedSizeList.Clone();
711 catch (NotSupportedException)
713 Assert.Fail("fixedSizeList.Clone()");
718 fixedSizeList.AddRange(c_TestData);
720 Assert.Fail("fixedSizeList.AddRange(c_TestData)");
722 catch (NotSupportedException)
727 private void PrivateTestClone(ArrayList arrayList)
729 ArrayList arrayList2;
731 arrayList.AddRange(c_TestData);
733 arrayList2 = (ArrayList)arrayList.Clone();
735 VerifyContains(arrayList2, c_TestData, "arrayList.Clone()");
739 public void TestCloneStandard()
741 PrivateTestClone(new ArrayList());
745 public void TestCloneSynchronized()
747 PrivateTestClone(ArrayList.Synchronized(new ArrayList()));
751 public void TestCloneAdapter()
753 PrivateTestClone(ArrayList.Adapter(new ArrayList()));
757 public void TestCloneGetRange()
759 PrivateTestClone(new ArrayList().GetRange(0, 0));
762 private void PrivateTestCopyTo(ArrayList arrayList)
766 arrayList.AddRange(c_TestData);
768 array = new Object[arrayList.Count];
770 arrayList.CopyTo(array);
772 VerifyContains(array, new object[] {0,1,2,3,4,5,6,7,8,9}, "ArrayList.CopyTo(array)");
774 array = new Object[3];
776 arrayList.CopyTo(0, array, 0, 3);
778 VerifyContains(array, new object[] {0,1,2}, "ArrayList.CopyTo(0, array, 0, 3)");
780 array = new Object[4];
782 arrayList.CopyTo(0, array, 1, 3);
784 VerifyContains(array, new object[] {null,0, 1, 2}, "ArrayList.CopyTo(0, array, 1, 3)");
786 array = new object[10];
788 arrayList.CopyTo(3, array, 3, 5);
790 VerifyContains(array, new object[] {null, null, null, 3, 4, 5, 6, 7, null, null}, "VerifyContains(array, ...)");
794 public void TestCopyToStandard()
796 PrivateTestCopyTo(new ArrayList());
800 public void TestCopyToSynchronized()
802 PrivateTestCopyTo(ArrayList.Synchronized(new ArrayList()));
806 public void TestCopyToAdapter()
808 PrivateTestCopyTo(ArrayList.Adapter(new ArrayList()));
812 public void TestCopyToGetRange()
814 PrivateTestCopyTo(new ArrayList().GetRange(0, 0));
817 private void PrivateTestSetCapacity(ArrayList arrayList)
821 arrayList.AddRange(c_TestData);
823 x = arrayList.Capacity;
825 arrayList.Capacity = x * 2;
827 Assert.IsTrue(arrayList.Capacity == x * 2, "arrayList.Capacity == x * 2");
829 VerifyContains(arrayList, c_TestData, "VerifyContains(arrayList, c_TestData)");
833 public void TestSetCapacity()
835 PrivateTestSetCapacity(new ArrayList());
839 public void TestSetCapacitySynchronized()
841 PrivateTestSetCapacity(ArrayList.Synchronized(new ArrayList()));
845 public void TestCapacityExpands()
847 ArrayList arrayList = new ArrayList(10);
849 arrayList.AddRange(c_TestData);
851 Assert.IsTrue(arrayList.Capacity == 10, "arrayList.Capacity == 10");
855 Assert.IsTrue(arrayList.Capacity == 20, "arrayList.Capacity == 20");
857 VerifyContains(arrayList, new object[] {0,1,2,3,4,5,6,7,8,9,10}, "VerifyContains");
860 private void PrivateTestBinarySearch(ArrayList arrayList)
862 // Try searching with different size lists...
864 for (int x = 0; x < 10; x++)
866 for (int i = 0; i < x; i++)
871 for (int i = 0; i < x; i++)
875 y = arrayList.BinarySearch(i);
877 Assertion.Equals(y, i);
882 arrayList.Add(new object());
886 arrayList.BinarySearch(new object());
888 Assert.Fail("1: Binary search on object that doesn't support IComparable.");
890 catch (ArgumentException)
893 catch (InvalidOperationException)
895 // LAMESPEC: ArrayList.BinarySearch() on MS.NET throws InvalidOperationException
900 arrayList.BinarySearch(1);
902 Assert.Fail("2: Binary search on incompatible object.");
904 catch (ArgumentException)
907 catch (InvalidOperationException)
909 // LAMESPEC: ArrayList.BinarySearch() on MS.NET throws InvalidOperationException
914 for (int i = 0; i < 100; i++)
919 Assert.IsTrue(arrayList.BinarySearch(1) == 49, "BinarySearch should start in middle.");
920 Assert.IsTrue(arrayList.BinarySearch(0, 0, 0, Comparer.Default) == -1, "arrayList.BinarySearch(0, 0, 0, Comparer.Default)");
924 public void TestBinarySearchStandard()
926 PrivateTestBinarySearch(new ArrayList());
930 public void TestBinarySearchSynchronized()
932 PrivateTestBinarySearch(ArrayList.Synchronized(new ArrayList()));
936 public void TestBinarySearchAdapter()
938 PrivateTestBinarySearch(ArrayList.Adapter(new ArrayList()));
942 public void TestBinarySearchGetRange()
944 PrivateTestBinarySearch(new ArrayList().GetRange(0, 0));
947 private void PrivateTestRemoveAt(ArrayList arrayList)
957 VerifyContains(arrayList, new object[] {1, 3, 4, 5},
958 "Remove element failed.");
960 arrayList.RemoveAt(0);
962 VerifyContains(arrayList, new object[] {3, 4, 5},
963 "RemoveAt at start failed.");
965 arrayList.RemoveAt(2);
967 VerifyContains(arrayList, new object[] {3, 4},
968 "RemoveAt at end failed.");
972 public void TestRemoveAtStandard()
974 PrivateTestRemoveAt(new ArrayList());
978 public void TestRemoveAtSynchronized()
980 PrivateTestRemoveAt(ArrayList.Synchronized(new ArrayList()));
984 public void TestRemoveAtAdapter()
986 PrivateTestRemoveAt(ArrayList.Adapter(new ArrayList()));
990 public void TestRemoveAtGetRange()
992 PrivateTestRemoveAt(new ArrayList().GetRange(0, 0));
995 private void PrivateTestRemoveRange(ArrayList arrayList)
997 arrayList.AddRange(c_TestData);
999 arrayList.RemoveRange(0, 3);
1001 VerifyContains(arrayList, new object[] { 3, 4, 5, 6, 7, 8, 9 },
1002 "RemoveRange at start failed.");
1004 arrayList.RemoveRange(4, 3);
1006 VerifyContains(arrayList, new object[] { 3, 4, 5, 6 },
1007 "RemoveRange at start failed.");
1009 arrayList.RemoveRange(2, 1);
1011 VerifyContains(arrayList, new object[] { 3, 4, 6 },
1012 "RemoveRange in middle failed.");
1016 public void TestRemoveRangeStandard()
1018 PrivateTestRemoveRange(new ArrayList());
1022 public void TestRemoveRangeSynchronized()
1024 PrivateTestRemoveRange(ArrayList.Synchronized(new ArrayList()));
1028 public void TestRemoveRangeAdapter()
1030 PrivateTestRemoveRange(ArrayList.Adapter(new ArrayList()));
1034 public void TestRemoveRangeGetRange()
1036 PrivateTestRemoveRange(new ArrayList().GetRange(0, 0));
1039 private void PrivateTestInsert(ArrayList arrayList)
1045 arrayList.Insert(0, 1);
1047 VerifyContains(arrayList, new object[] {1, 1, 2, 3, 4}, "Insert at beginning failed.");
1049 arrayList.Insert(5, 5);
1051 VerifyContains(arrayList, new object[] {1, 1, 2, 3, 4, 5}, "Insert at end failed.");
1053 arrayList.Insert(3, 7);
1055 VerifyContains(arrayList, new object[] {1, 1, 2, 7, 3, 4, 5}, "Insert in middle failed.");
1059 public void TestInsertStandard()
1061 PrivateTestInsert(new ArrayList());
1065 public void TestInsertAdapter()
1067 PrivateTestInsert(ArrayList.Adapter(new ArrayList()));
1071 public void TestInsertSynchronized()
1073 PrivateTestInsert(ArrayList.Synchronized(new ArrayList()));
1077 public void TestInsertGetRange()
1079 PrivateTestInsert(new ArrayList().GetRange(0, 0));
1082 private void PrivateTestGetRange(ArrayList arrayList)
1084 ArrayList rangeList;
1086 arrayList.AddRange(c_TestData);
1088 rangeList = arrayList.GetRange(3, 5);
1090 Assert.IsTrue(rangeList.Count == 5, "rangeList.Count == 5");
1092 this.VerifyContains(rangeList, new object[] {3,4,5,6,7}, "1: VerifyContains(rangeList)");
1094 //FIXME: If items are removed from the Range, one may not iterate over it on .NET
1096 rangeList.Remove(7);
1098 this.VerifyContains(a2, new object[] {3,4,5,6}, "2: VerifyContains(rangeList)");
1100 rangeList.RemoveAt(0);
1102 this.VerifyContains(a3, new object[] {4,5,6}, "3: VerifyContains(rangeList)");
1109 Assert.IsTrue(rangeList.LastIndexOf(6) == 4, "rangeList.LastIndexOf(6) == 4");
1113 this.VerifyContains(arrayList, new object[] {0, 1, 2, 3, 4, 5, 6, 6, 7, 11, 8, 9}, "4: VerifyContains(rangeList)");
1118 public void TestGetRangeStandard()
1120 PrivateTestGetRange(new ArrayList());
1124 public void TestGetRangeAdapter()
1126 PrivateTestGetRange(ArrayList.Adapter(new ArrayList()));
1130 public void TestGetRangeSynchronized()
1132 PrivateTestGetRange(ArrayList.Synchronized(new ArrayList()));
1136 public void TestGetRangeGetRange()
1138 PrivateTestGetRange(new ArrayList().GetRange(0, 0));
1141 private void PrivateTestEnumeratorWithRange(ArrayList arrayList)
1143 IEnumerator enumerator;
1145 arrayList.AddRange(c_TestData);
1149 // Test with the range 1 - 3
1151 enumerator = arrayList.GetEnumerator(1, 3);
1155 while (enumerator.MoveNext())
1157 Assert.IsTrue((int)enumerator.Current == x, "enumerator.Current == x");
1166 while (enumerator.MoveNext())
1168 Assert.IsTrue((int)enumerator.Current == x, "enumerator.Current == x");
1174 // Test with a range covering the whole list.
1176 enumerator = arrayList.GetEnumerator(0, arrayList.Count);
1180 while (enumerator.MoveNext())
1182 Assert.IsTrue((int)enumerator.Current == x, "enumerator.Current == x");
1191 while (enumerator.MoveNext())
1193 Assert.IsTrue((int)enumerator.Current == x, "enumerator.Current == x");
1198 // Test with a range covering nothing.
1200 enumerator = arrayList.GetEnumerator(arrayList.Count, 0);
1202 Assert.IsTrue(!enumerator.MoveNext(), "!enumerator.MoveNext()");
1206 Assert.IsTrue(!enumerator.MoveNext(), "!enumerator.MoveNext()");
1210 public void TestEnumeratorWithRangeStandard()
1212 PrivateTestEnumeratorWithRange(new ArrayList());
1216 public void TestEnumeratorWithRangeSynchronized()
1218 PrivateTestEnumeratorWithRange(ArrayList.Synchronized(new ArrayList()));
1222 public void TestEnumeratorWithRangeAdapter()
1224 PrivateTestEnumeratorWithRange(ArrayList.Adapter(new ArrayList()));
1228 public void TestEnumeratorWithRangeGetRange()
1230 PrivateTestEnumeratorWithRange(new ArrayList().GetRange(0, 0));
1233 private void PrivateTestEnumerator(ArrayList arrayList)
1237 arrayList.AddRange(c_TestData);
1241 foreach (object o in arrayList)
1245 Assert.Fail("Arraylist.GetEnumerator()");
1253 IEnumerator enumerator;
1255 enumerator = arrayList.GetEnumerator();
1257 enumerator.MoveNext();
1259 Assert.IsTrue((int)enumerator.Current == 0, "enumerator.Current == 0");
1261 // Invalidate the enumerator.
1267 // According to the spec this should still work even though the enumerator is invalid.
1269 Assert.IsTrue((int)enumerator.Current == 0, "enumerator.Current == 0");
1271 catch (InvalidOperationException)
1273 Assert.IsTrue(false, "enumerator.Current should not fail.");
1278 // This should throw an InvalidOperationException.
1280 enumerator.MoveNext();
1282 Assert.IsTrue(false, "enumerator.Current should fail.");
1284 catch (InvalidOperationException)
1290 public void TestEnumeratorStandard()
1292 PrivateTestEnumerator(new ArrayList());
1296 public void TestEnumeratorSynchronized()
1298 PrivateTestEnumerator(ArrayList.Synchronized(new ArrayList()));
1302 public void TestEnumeratorAdapter()
1304 PrivateTestEnumerator(ArrayList.Adapter(new ArrayList()));
1308 public void TestEnumeratorGetRange()
1310 PrivateTestEnumerator(new ArrayList().GetRange(0, 0));
1313 private void PrivateTestReverse(ArrayList arrayList)
1315 ArrayList arrayList2;
1317 for (int x = 1; x < 100; x ++)
1319 arrayList2 = (ArrayList)arrayList.Clone();
1321 for (int i = 0; i < x; i++)
1326 arrayList2.Reverse();
1330 // Check that reverse did reverse the adapter.
1332 for (int i = 0; i < x; i++)
1334 if ((int)arrayList2[i] != x - i - 1)
1344 String.Format("Reverse on arrayList failed on list with {0} items.", x),
1351 public void TestReverseStandard()
1353 PrivateTestReverse(new ArrayList());
1357 public void TestReverseAdapter()
1359 ArrayList arrayList = new ArrayList();
1360 ArrayList adapter = ArrayList.Adapter(arrayList);
1362 PrivateTestReverse(adapter);
1364 VerifyContains(adapter, arrayList, "Changing adapter didn't change ArrayList.");
1368 public void TestReverseSynchronized()
1370 PrivateTestReverse(ArrayList.Synchronized(new ArrayList()));
1374 public void TestReverseGetRange()
1376 PrivateTestReverse(new ArrayList().GetRange(0,0));
1380 public void TestIterator ()
1382 ArrayList a = new ArrayList ();
1388 foreach (int b in a)
1390 Assert.IsTrue (total == 6, "Count should be 6");
1394 public void TestIteratorObjects ()
1396 ArrayList a = new ArrayList ();
1403 bool found_null = false;
1404 foreach (object b in a){
1408 Assert.IsTrue (false, "Should only find one null");
1415 Assert.IsTrue (found_null, "Should fine one null");
1416 Assert.IsTrue (total == 4, "Total should be 4");
1417 Assert.IsTrue (count == 3, "Count should be 3");