touching up TODO
[mono.git] / mcs / class / corlib / Test / System.Collections / ArrayListTest.cs
1 // ArrayListTest.cs - NUnit Test Cases for the System.Collections.ArrayList class\r
2 //\r
3 // David Brandt (bucky@keystreams.com)\r
4 //\r
5 // (C) Ximian, Inc.  http://www.ximian.com\r
6 // \r
7 \r
8 using System;\r
9 using System.Collections;\r
10 \r
11 using NUnit.Framework;\r
12 \r
13 \r
14 \r
15 namespace MonoTests.System.Collections {\r
16 \r
17 \r
18 /// <summary>ArrayList test.</summary>\r
19 public class ArrayListTest : TestCase {\r
20         public ArrayListTest() : base ("MonoTests.System.ArrayListTest testsuite") {}\r
21         public ArrayListTest(string name) : base(name) {}\r
22 \r
23         protected override void SetUp() \r
24         {\r
25         }\r
26 \r
27         protected override void TearDown() \r
28         {\r
29         }\r
30 \r
31         public static ITest Suite {\r
32                 get { \r
33                         return new TestSuite(typeof(ArrayListTest)); \r
34                 }\r
35         }\r
36 \r
37         public void TestCtor() {\r
38                 {\r
39                         ArrayList al1 = new ArrayList();\r
40                         AssertNotNull("no basic ArrayList", al1);\r
41                 }\r
42                 {\r
43                         bool errorThrown = false;\r
44                         try {\r
45                                 ArrayList a = new ArrayList(null);\r
46                         } catch (ArgumentNullException) {\r
47                                 errorThrown = true;\r
48                         }\r
49                         Assert("null icollection error not thrown", \r
50                                errorThrown);\r
51                 }\r
52                 {\r
53                         // what can I say?  I like chars.  [--DB]\r
54                         char[] coll = {'a', 'b', 'c', 'd'};\r
55                         ArrayList al1 = new ArrayList(coll);\r
56                         AssertNotNull("no icollection ArrayList", al1);\r
57                         for (int i = 0; i < coll.Length; i++) {\r
58                                 AssertEquals(i + " not ctor'ed properly.",\r
59                                              coll[i], al1[i]);\r
60                         }\r
61                 }\r
62                 // TODO - multi-dim ICollection ctor?\r
63                 {\r
64                         bool errorThrown = false;\r
65                         try {\r
66                                 ArrayList a = new ArrayList(-1);\r
67                         } catch (ArgumentOutOfRangeException) {\r
68                                 errorThrown = true;\r
69                         }\r
70                         Assert("negative capacity error not thrown", \r
71                                errorThrown);\r
72                 }\r
73         }\r
74 \r
75         public void TestCapacity() {\r
76                 for (int i = 0; i < 100; i++) {\r
77                         ArrayList al1 = new ArrayList(i);\r
78                         AssertEquals("Bad capacity of " + i,\r
79                                      i, al1.Capacity);\r
80                 }\r
81                 {\r
82                         ArrayList al1 = new ArrayList();\r
83                         AssertEquals("Bad default capacity",\r
84                                      16, al1.Capacity);\r
85                 }\r
86         }\r
87         \r
88         public void TestCount() {\r
89                 {\r
90                         ArrayList al1 = new ArrayList();\r
91                         AssertEquals("Bad initial count",\r
92                                      0, al1.Count);\r
93                         for (int i = 1; i <= 100; i++) {\r
94                                 al1.Add(i);\r
95                                 AssertEquals("Bad count " + i,\r
96                                              i, al1.Count);\r
97                         }\r
98                 }\r
99                 for (int i = 0; i < 100; i++) {\r
100                         char[] coll = new Char[i];\r
101                         ArrayList al1 = new ArrayList(coll);\r
102                         AssertEquals("Bad count for " + i,\r
103                                      i, al1.Count);\r
104                 }\r
105         }\r
106 \r
107         public void TestIsFixed() {\r
108                 ArrayList al1 = new ArrayList();\r
109                 Assert("should not be fixed by default", !al1.IsFixedSize);\r
110                 ArrayList al2 = ArrayList.FixedSize(al1);\r
111                 Assert("fixed-size wrapper not working", al2.IsFixedSize);\r
112         }\r
113 \r
114         public void TestIsReadOnly() {\r
115                 ArrayList al1 = new ArrayList();\r
116                 Assert("should not be ReadOnly by default", !al1.IsReadOnly);\r
117                 ArrayList al2 = ArrayList.ReadOnly(al1);\r
118                 Assert("read-only wrapper not working", al2.IsReadOnly);\r
119         }\r
120 \r
121         public void TestIsSynchronized() {\r
122                 ArrayList al1 = new ArrayList();\r
123                 Assert("should not be synchronized by default", \r
124                        !al1.IsSynchronized);\r
125                 ArrayList al2 = ArrayList.Synchronized(al1);\r
126                 Assert("synchronized wrapper not working", al2.IsSynchronized);\r
127         }\r
128 \r
129         public void TestItem() {\r
130                 ArrayList al1 = new ArrayList();\r
131                 {\r
132                         bool errorThrown = false;\r
133                         try {\r
134                                 object o = al1[-1];\r
135                         } catch (ArgumentOutOfRangeException) {\r
136                                 errorThrown = true;\r
137                         }\r
138                         Assert("negative item error not thrown", \r
139                                errorThrown);\r
140                 }\r
141                 {\r
142                         bool errorThrown = false;\r
143                         try {\r
144                                 object o = al1[1];\r
145                         } catch (ArgumentOutOfRangeException) {\r
146                                 errorThrown = true;\r
147                         }\r
148                         Assert("past-end item error not thrown", \r
149                                errorThrown);\r
150                 }\r
151                 for (int i = 0; i <= 100; i++) {\r
152                         al1.Add(i);\r
153                 }\r
154                 for (int i = 0; i <= 100; i++) {\r
155                         AssertEquals("item not fetched for " + i,\r
156                                      i, al1[i]);\r
157                 }\r
158         }\r
159 \r
160         public void TestAdapter() {\r
161                 {\r
162                         bool errorThrown = false;\r
163                         try {\r
164                                 ArrayList al1 = ArrayList.Adapter(null);\r
165                         } catch (ArgumentNullException) {\r
166                                 errorThrown = true;\r
167                         }\r
168                         Assert("null adapter error not thrown", \r
169                                errorThrown);\r
170                 }\r
171                 {               \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
177                         }\r
178                         list[0] = 'z';\r
179                         for (int i = 0; i < list.Length; i++) {\r
180                                 AssertEquals("adapter not adapting", list[i], al1[i]);\r
181                         }\r
182                 }\r
183                 // TODO - test other adapter types?\r
184         }\r
185 \r
186         public void TestAdd() {\r
187                 {\r
188                         bool errorThrown = false;\r
189                         try {\r
190                                 ArrayList al1 = \r
191                                         ArrayList.FixedSize(new ArrayList());\r
192                                 al1.Add("Hi!");\r
193                         } catch (NotSupportedException) {\r
194                                 errorThrown = true;\r
195                         }\r
196                         Assert("add to fixed size error not thrown", \r
197                                errorThrown);\r
198                 }\r
199                 {\r
200                         bool errorThrown = false;\r
201                         try {\r
202                                 ArrayList al1 = \r
203                                         ArrayList.ReadOnly(new ArrayList());\r
204                                 al1.Add("Hi!");\r
205                         } catch (NotSupportedException) {\r
206                                 errorThrown = true;\r
207                         }\r
208                         Assert("add to read only error not thrown", \r
209                                errorThrown);\r
210                 }\r
211                 {\r
212                         ArrayList al1 = new ArrayList();\r
213                         for (int i = 1; i <= 100; i++) {\r
214                                 al1.Add(i);\r
215                                 AssertEquals("add failed " + i,\r
216                                              i, al1.Count);\r
217                                 AssertEquals("add failed " + i,\r
218                                              i, al1[i-1]);\r
219                                 \r
220                         }\r
221                 }\r
222         }\r
223         \r
224         public void TestAddRange() {\r
225                 {\r
226                         bool errorThrown = false;\r
227                         try {\r
228                                 ArrayList al1 = \r
229                                         ArrayList.FixedSize(new ArrayList());\r
230                                 String[] s1 = {"Hi!"};\r
231                                 al1.AddRange(s1);\r
232                         } catch (NotSupportedException) {\r
233                                 errorThrown = true;\r
234                         }\r
235                         Assert("add to fixed size error not thrown", \r
236                                errorThrown);\r
237                 }\r
238                 {\r
239                         bool errorThrown = false;\r
240                         try {\r
241                                 ArrayList al1 = \r
242                                         ArrayList.ReadOnly(new ArrayList());\r
243                                 String[] s1 = {"Hi!"};\r
244                                 al1.AddRange(s1);\r
245                         } catch (NotSupportedException) {\r
246                                 errorThrown = true;\r
247                         }\r
248                         Assert("add to read only error not thrown", \r
249                                errorThrown);\r
250                 }\r
251                 {\r
252                         bool errorThrown = false;\r
253                         try {\r
254                                 ArrayList al1 = new ArrayList();\r
255                                 al1.AddRange(null);\r
256                         } catch (ArgumentNullException) {\r
257                                 errorThrown = true;\r
258                         }\r
259                         Assert("add to read only error not thrown", \r
260                                errorThrown);\r
261                 }\r
262 \r
263                 {\r
264                         ArrayList a1 = new ArrayList();\r
265                         AssertEquals("ArrayList should start empty",\r
266                                      0, a1.Count);\r
267                         char[] coll = {'a', 'b', 'c'};\r
268                         a1.AddRange(coll);\r
269                         AssertEquals("ArrayList has wrong elements",\r
270                                      3, a1.Count);\r
271                         a1.AddRange(coll);\r
272                         AssertEquals("ArrayList has wrong elements",\r
273                                      6, a1.Count);\r
274                 }\r
275         }\r
276 \r
277         public void TestBinarySearch() {\r
278                 //{\r
279                 //bool errorThrown = false;\r
280                 //try {\r
281                 //      ArrayList al1 = new ArrayList();\r
282                 //      String[] s1 = {"This", "is", "a", "test"};\r
283                 //      al1.AddRange(s1);\r
284                 //      al1.BinarySearch(42);\r
285                 //} catch (ArgumentException) {\r
286                 //      errorThrown = true;\r
287                 //}\r
288                 //Assert("search-for-wrong-type error not thrown", \r
289                 //       errorThrown);\r
290                 //}\r
291                 \r
292                 {\r
293                         char[] bad = {'d', 'a', 'd', 'a', 'c', 'a'};\r
294                         ArrayList al1 = new ArrayList(bad);\r
295                         AssertEquals("shouldn't find elem in badly-sorted array", -1, al1.BinarySearch('c'));\r
296                 }\r
297                 {\r
298                         char[] bad = {'a', 'd', 'a', 'd', 'a', 'c', 'a'};\r
299                         ArrayList al1 = new ArrayList(bad);\r
300                         AssertEquals("shouldn't find elem in badly-sorted array", -2, al1.BinarySearch('c'));\r
301                 }\r
302                 {\r
303                         char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};\r
304                         ArrayList al1 = new ArrayList(arr);\r
305                         Assert("couldn't find elem", \r
306                                al1.BinarySearch('c') >= 3);\r
307                         Assert("couldn't find elem", \r
308                                al1.BinarySearch('c') < 6);\r
309                 }\r
310                 {\r
311                         char[] arr = {'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};\r
312                         ArrayList al1 = new ArrayList(arr);\r
313                         AssertEquals("couldn't find next-higher elem", \r
314                                      -4, al1.BinarySearch('c'));\r
315                 }\r
316                 {\r
317                         char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};\r
318                         ArrayList al1 = new ArrayList(arr);\r
319                         AssertEquals("couldn't find end", \r
320                                      -9, al1.BinarySearch('e'));\r
321                 }\r
322                 \r
323         }\r
324 \r
325         // TODO - BinarySearch with IComparer\r
326 \r
327         public void TestClear() {\r
328                 {\r
329                         bool errorThrown = false;\r
330                         try {\r
331                                 ArrayList al1 = \r
332                                         ArrayList.FixedSize(new ArrayList());\r
333                                 al1.Clear();\r
334                         } catch (NotSupportedException) {\r
335                                 errorThrown = true;\r
336                         }\r
337                         Assert("add to fixed size error not thrown", \r
338                                errorThrown);\r
339                 }\r
340                 {\r
341                         bool errorThrown = false;\r
342                         try {\r
343                                 ArrayList al1 = \r
344                                         ArrayList.ReadOnly(new ArrayList());\r
345                                 al1.Clear();\r
346                         } catch (NotSupportedException) {\r
347                                 errorThrown = true;\r
348                         }\r
349                         Assert("add to read only error not thrown", \r
350                                errorThrown);\r
351                 }\r
352                 {\r
353                         ArrayList al1 = new ArrayList();\r
354                         al1.Add('c');\r
355                         AssertEquals("should have one element",\r
356                                      1, al1.Count);\r
357                         al1.Clear();\r
358                         AssertEquals("should be empty",\r
359                                      0, al1.Count);\r
360                 }\r
361                 {\r
362                         int[] i1 = {1,2,3,4};\r
363                         ArrayList al1 = new ArrayList(i1);\r
364                         AssertEquals("should have elements",\r
365                                      i1.Length, al1.Count);\r
366                         al1.Clear();\r
367                         AssertEquals("should be empty again",\r
368                                      0, al1.Count);\r
369                 }\r
370         }\r
371 \r
372         public void TestClone() {\r
373                 {\r
374                         char[] c1 = {'a', 'b', 'c'};\r
375                         ArrayList al1 = new ArrayList(c1);\r
376                         ArrayList al2 = (ArrayList)al1.Clone();\r
377                         AssertEquals("ArrayList match", al1[0], al2[0]);\r
378                         AssertEquals("ArrayList match", al1[1], al2[1]);\r
379                         AssertEquals("ArrayList match", al1[2], al2[2]);\r
380                 }\r
381                 {\r
382                         char[] d10 = {'a', 'b'};\r
383                         char[] d11 = {'a', 'c'};\r
384                         char[] d12 = {'b', 'c'};\r
385                         char[][] d1 = {d10, d11, d12};\r
386                         ArrayList al1 = new ArrayList(d1);\r
387                         ArrayList al2 = (ArrayList)al1.Clone();\r
388                         AssertEquals("Array match", al1[0], al2[0]);\r
389                         AssertEquals("Array match", al1[1], al2[1]);\r
390                         AssertEquals("Array match", al1[2], al2[2]);\r
391                         \r
392                         ((char[])al1[0])[0] = 'z';\r
393                         AssertEquals("shallow copy", al1[0], al2[0]);\r
394                 }\r
395         }\r
396 \r
397         public void TestContains() {\r
398                 char[] c1 = {'a', 'b', 'c'};\r
399                 ArrayList al1 = new ArrayList(c1);\r
400                 Assert("never find a null", !al1.Contains(null));\r
401                 Assert("can't find value", al1.Contains('b'));\r
402                 Assert("shouldn't find value", !al1.Contains('?'));\r
403         }\r
404         \r
405         public void TestCopyTo() {\r
406                 {\r
407                         bool errorThrown = false;\r
408                         try {\r
409                                 Char[] c1 = new Char[2];\r
410                                 ArrayList al1 = new ArrayList(c1);\r
411                                 al1.CopyTo(null, 2);\r
412                         } catch (ArgumentNullException) {\r
413                                 errorThrown = true;\r
414                         }\r
415                         Assert("error not thrown", errorThrown);\r
416                 }\r
417                 {\r
418                         bool errorThrown = false;\r
419                         try {\r
420                                 Char[] c1 = new Char[2];\r
421                                 ArrayList al1 = new ArrayList(c1);\r
422                                 Char[,] c2 = new Char[2,2];\r
423                                 al1.CopyTo(c2, 2);\r
424                         } catch (ArgumentException) {\r
425                                 errorThrown = true;\r
426                         }\r
427                         Assert("error not thrown", errorThrown);\r
428                 }\r
429                 {\r
430                         bool errorThrown = false;\r
431                         try {\r
432                                 Char[,] c1 = new Char[2,2];\r
433                                 ArrayList al1 = new ArrayList(c1);\r
434                                 Char[] c2 = new Char[2];\r
435                                 al1.CopyTo(c2, 2);\r
436                         } catch (RankException) {\r
437                                 errorThrown = true;\r
438                         }\r
439                         Assert("error not thrown", errorThrown);\r
440                 }\r
441                 {\r
442                         bool errorThrown = false;\r
443                         try {\r
444                                 Char[] c1 = new Char[2];\r
445                                 ArrayList al1 = new ArrayList(c1);\r
446                                 Char[] c2 = new Char[2];\r
447                                 al1.CopyTo(c2, -1);\r
448                         } catch (ArgumentOutOfRangeException) {\r
449                                 errorThrown = true;\r
450                         }\r
451                         Assert("error not thrown", errorThrown);\r
452                 }\r
453                 {\r
454                         bool errorThrown = false;\r
455                         try {\r
456                                 Char[] c1 = new Char[2];\r
457                                 ArrayList al1 = new ArrayList(c1);\r
458                                 Char[] c2 = new Char[2];\r
459                                 al1.CopyTo(c2, 3);\r
460                         } catch (ArgumentException) {\r
461                                 errorThrown = true;\r
462                         }\r
463                         Assert("error not thrown", errorThrown);\r
464                 }\r
465                 {\r
466                         bool errorThrown = false;\r
467                         try {\r
468                                 Char[] c1 = new Char[2];\r
469                                 ArrayList al1 = new ArrayList(c1);\r
470                                 Char[] c2 = new Char[2];\r
471                                 al1.CopyTo(c2, 1);\r
472                         } catch (ArgumentException) {\r
473                                 errorThrown = true;\r
474                         }\r
475                         Assert("error not thrown", errorThrown);\r
476                 }\r
477                 {\r
478                         bool errorThrown = false;\r
479                         try {\r
480                                 String[] c1 = new String[2];\r
481                                 ArrayList al1 = new ArrayList(c1);\r
482                                 Char[] c2 = new Char[2];\r
483                                 al1.CopyTo(c2, 0);\r
484                         } catch (InvalidCastException) {\r
485                                 errorThrown = true;\r
486                         }\r
487                         Assert("error not thrown", errorThrown);\r
488                 }\r
489 \r
490                 Char[] orig = {'a', 'b', 'c', 'd'};\r
491                 ArrayList al = new ArrayList(orig);\r
492                 Char[] copy = new Char[10];\r
493                 Array.Clear(copy, 0, copy.Length);\r
494                 al.CopyTo(copy, 3);\r
495                 AssertEquals("Wrong CopyTo 0", (char)0, copy[0]);\r
496                 AssertEquals("Wrong CopyTo 1", (char)0, copy[1]);\r
497                 AssertEquals("Wrong CopyTo 2", (char)0, copy[2]);\r
498                 AssertEquals("Wrong CopyTo 3", orig[0], copy[3]);\r
499                 AssertEquals("Wrong CopyTo 4", orig[1], copy[4]);\r
500                 AssertEquals("Wrong CopyTo 5", orig[2], copy[5]);\r
501                 AssertEquals("Wrong CopyTo 6", orig[3], copy[6]);\r
502                 AssertEquals("Wrong CopyTo 7", (char)0, copy[7]);\r
503                 AssertEquals("Wrong CopyTo 8", (char)0, copy[8]);\r
504                 AssertEquals("Wrong CopyTo 9", (char)0, copy[9]);\r
505         }\r
506 \r
507         public void TestFixedSize() {\r
508                 {\r
509                         bool errorThrown = false;\r
510                         try {\r
511                                 ArrayList al1 = ArrayList.FixedSize(null);\r
512                         } catch (ArgumentNullException) {\r
513                                 errorThrown = true;\r
514                         }\r
515                         Assert("null arg error not thrown", errorThrown);\r
516                 }\r
517                 {\r
518                         ArrayList al1 = new ArrayList();\r
519                         AssertEquals("arrays start un-fixed.",\r
520                                      false, al1.IsFixedSize);\r
521                         ArrayList al2 = ArrayList.FixedSize(al1);\r
522                         AssertEquals("should be fixed.",\r
523                                      true, al2.IsFixedSize);\r
524                 }\r
525         }\r
526 \r
527         public void TestGetEnumerator() {\r
528                 {\r
529                         bool errorThrown = false;\r
530                         try {\r
531                                 ArrayList a = new ArrayList();\r
532                                 IEnumerator en = a.GetEnumerator(-1,1);\r
533                         } catch (ArgumentOutOfRangeException) {\r
534                                 errorThrown = true;\r
535                         }\r
536                         Assert("negative index error not thrown", \r
537                                errorThrown);\r
538                 }\r
539                 {\r
540                         bool errorThrown = false;\r
541                         try {\r
542                                 ArrayList a = new ArrayList();\r
543                                 IEnumerator en = a.GetEnumerator(1,-1);\r
544                         } catch (ArgumentOutOfRangeException) {\r
545                                 errorThrown = true;\r
546                         }\r
547                         Assert("negative index error not thrown", \r
548                                errorThrown);\r
549                 }\r
550                 {\r
551                         bool errorThrown = false;\r
552                         try {\r
553                                 ArrayList a = new ArrayList();\r
554                                 IEnumerator en = a.GetEnumerator(1,1);\r
555                         } catch (ArgumentException) {\r
556                                 errorThrown = true;\r
557                         }\r
558                         Assert("out-of-range index error not thrown", \r
559                                errorThrown);\r
560                 }\r
561                 {\r
562                         String[] s1 = {"this", "is", "a", "test"};\r
563                         ArrayList al1 = new ArrayList(s1);\r
564                         IEnumerator en = al1.GetEnumerator();\r
565                         AssertNotNull("No enumerator", en);\r
566                         \r
567                         for (int i = 0; i < s1.Length; i++) {\r
568                                 en.MoveNext();\r
569                                 AssertEquals("Not enumerating", \r
570                                              al1[i], en.Current);\r
571                         }\r
572                 }\r
573                 {\r
574                         String[] s1 = {"this", "is", "a", "test"};\r
575                         ArrayList al1 = new ArrayList(s1);\r
576                         IEnumerator en = al1.GetEnumerator(1,2);\r
577                         AssertNotNull("No enumerator", en);\r
578                         \r
579                         for (int i = 0; i < 2; i++) {\r
580                                 en.MoveNext();\r
581                                 AssertEquals("Not enumerating", \r
582                                              al1[i+1], en.Current);\r
583                         }\r
584                 }\r
585         }\r
586 \r
587         public void TestGetRange() {\r
588                 {\r
589                         bool errorThrown = false;\r
590                         try {\r
591                                 ArrayList a = new ArrayList();\r
592                                 ArrayList b = a.GetRange(-1,1);\r
593                         } catch (ArgumentOutOfRangeException) {\r
594                                 errorThrown = true;\r
595                         }\r
596                         Assert("negative index error not thrown", \r
597                                errorThrown);\r
598                 }\r
599                 {\r
600                         bool errorThrown = false;\r
601                         try {\r
602                                 ArrayList a = new ArrayList();\r
603                                 ArrayList b = a.GetRange(1,-1);\r
604                         } catch (ArgumentOutOfRangeException) {\r
605                                 errorThrown = true;\r
606                         }\r
607                         Assert("negative index error not thrown", \r
608                                errorThrown);\r
609                 }\r
610                 {\r
611                         bool errorThrown = false;\r
612                         try {\r
613                                 ArrayList a = new ArrayList();\r
614                                 ArrayList b = a.GetRange(1,1);\r
615                         } catch (ArgumentException) {\r
616                                 errorThrown = true;\r
617                         }\r
618                         Assert("out-of-range index error not thrown", \r
619                                errorThrown);\r
620                 }\r
621                 {\r
622                         char[] chars = {'a', 'b', 'c', 'd', 'e', 'f'};\r
623                         ArrayList a = new ArrayList(chars);\r
624                         ArrayList b = a.GetRange(1, 3);\r
625                         for (int i = 0; i < b.Count; i++) {\r
626                                 AssertEquals("range didn't work",\r
627                                              chars[i+1], b[i]);\r
628                         }\r
629 \r
630                         a[2] = '?'; // should screw up ArrayList b.\r
631                         bool errorThrown = false;\r
632                         try {\r
633                                 int i = b.Count;\r
634                         } catch (InvalidOperationException) {\r
635                                 errorThrown = true;\r
636                         }\r
637                         AssertEquals("Munging 'a' should mess up 'b'",\r
638                                      true, errorThrown);\r
639                 }\r
640         }\r
641 \r
642         public void TestIndexOf() {\r
643                 {\r
644                         bool errorThrown = false;\r
645                         try {\r
646                                 ArrayList a = new ArrayList(1);\r
647                                 int i = a.IndexOf('a', -1);\r
648                         } catch (ArgumentOutOfRangeException) {\r
649                                 errorThrown = true;\r
650                         }\r
651                         Assert("negative indexof error not thrown", \r
652                                errorThrown);\r
653                 }\r
654                 {\r
655                         bool errorThrown = false;\r
656                         try {\r
657                                 ArrayList a = new ArrayList(1);\r
658                                 int i = a.IndexOf('a', 2);\r
659                         } catch (ArgumentOutOfRangeException) {\r
660                                 errorThrown = true;\r
661                         }\r
662                         Assert("past-end indexof error not thrown", \r
663                                errorThrown);\r
664                 }\r
665                 {\r
666                         bool errorThrown = false;\r
667                         try {\r
668                                 ArrayList a = new ArrayList(1);\r
669                                 int i = a.IndexOf('a', 0, -1);\r
670                         } catch (ArgumentOutOfRangeException) {\r
671                                 errorThrown = true;\r
672                         }\r
673                         Assert("negative indexof error not thrown", \r
674                                errorThrown);\r
675                 }\r
676                 {\r
677                         bool errorThrown = false;\r
678                         try {\r
679                                 ArrayList a = new ArrayList(1);\r
680                                 int i = a.IndexOf('a', 0, 2);\r
681                         } catch (ArgumentOutOfRangeException) {\r
682                                 errorThrown = true;\r
683                         }\r
684                         Assert("past-end indexof error not thrown", \r
685                                errorThrown);\r
686                 }\r
687                 {\r
688                         bool errorThrown = false;\r
689                         try {\r
690                                 ArrayList a = new ArrayList(2);\r
691                                 int i = a.IndexOf('a', 1, 2);\r
692                         } catch (ArgumentOutOfRangeException) {\r
693                                 errorThrown = true;\r
694                         }\r
695                         Assert("past-end indexof error not thrown", \r
696                                errorThrown);\r
697                 }\r
698                 {\r
699                         char[] c = {'a', 'b', 'c', 'd', 'e'};\r
700                         ArrayList a = new ArrayList(c);\r
701                         AssertEquals("never find null", \r
702                                      -1, a.IndexOf(null));\r
703                         AssertEquals("never find null", \r
704                                      -1, a.IndexOf(null, 0));\r
705                         AssertEquals("never find null", \r
706                                      -1, a.IndexOf(null, 0, 5));\r
707                         AssertEquals("can't find elem", \r
708                                      2, a.IndexOf('c'));\r
709                         AssertEquals("can't find elem", \r
710                                      2, a.IndexOf('c', 2));\r
711                         AssertEquals("can't find elem", \r
712                                      2, a.IndexOf('c', 2, 2));\r
713                         AssertEquals("shouldn't find elem", \r
714                                      -1, a.IndexOf('c', 3, 2));\r
715                         AssertEquals("shouldn't find", -1, a.IndexOf('?'));\r
716                         AssertEquals("shouldn't find", -1, a.IndexOf(3));\r
717                 }\r
718         }\r
719 \r
720         public void TestInsert() {\r
721                 {\r
722                         bool errorThrown = false;\r
723                         try {\r
724                                 ArrayList al1 = \r
725                                         ArrayList.FixedSize(new ArrayList());\r
726                                 al1.Insert(0, "Hi!");\r
727                         } catch (NotSupportedException) {\r
728                                 errorThrown = true;\r
729                         }\r
730                         Assert("insert to fixed size error not thrown", \r
731                                errorThrown);\r
732                 }\r
733                 {\r
734                         bool errorThrown = false;\r
735                         try {\r
736                                 ArrayList al1 = \r
737                                         ArrayList.ReadOnly(new ArrayList());\r
738                                 al1.Insert(0, "Hi!");\r
739                         } catch (NotSupportedException) {\r
740                                 errorThrown = true;\r
741                         }\r
742                         Assert("insert to read only error not thrown", \r
743                                errorThrown);\r
744                 }\r
745                 {\r
746                         bool errorThrown = false;\r
747                         try {\r
748                                 ArrayList al1 = new ArrayList(3);\r
749                                 al1.Insert(-1, "Hi!");\r
750                         } catch (ArgumentOutOfRangeException) {\r
751                                 errorThrown = true;\r
752                         }\r
753                         Assert("insert to read only error not thrown", \r
754                                errorThrown);\r
755                 }\r
756                 {\r
757                         bool errorThrown = false;\r
758                         try {\r
759                                 ArrayList al1 = new ArrayList(3);\r
760                                 al1.Insert(4, "Hi!");\r
761                         } catch (ArgumentOutOfRangeException) {\r
762                                 errorThrown = true;\r
763                         }\r
764                         Assert("insert to read only error not thrown", \r
765                                errorThrown);\r
766                 }\r
767                 {\r
768                         ArrayList al1 = new ArrayList();\r
769                         AssertEquals("arraylist starts empty", 0, al1.Count);\r
770                         al1.Insert(0, 'a');\r
771                         al1.Insert(1, 'b');\r
772                         al1.Insert(0, 'c');\r
773                         AssertEquals("arraylist needs stuff", 3, al1.Count);\r
774                         AssertEquals("arraylist got stuff", 'c', al1[0]);\r
775                         AssertEquals("arraylist got stuff", 'a', al1[1]);\r
776                         AssertEquals("arraylist got stuff", 'b', al1[2]);\r
777                 }\r
778         }\r
779 \r
780         public void TestInsertRange() {\r
781                 {\r
782                         bool errorThrown = false;\r
783                         try {\r
784                                 ArrayList al1 = \r
785                                         ArrayList.FixedSize(new ArrayList());\r
786                                 string[] s = {"Hi!"};\r
787                                 al1.InsertRange(0, s);\r
788                         } catch (NotSupportedException) {\r
789                                 errorThrown = true;\r
790                         }\r
791                         Assert("insert to fixed size error not thrown", \r
792                                errorThrown);\r
793                 }\r
794                 {\r
795                         bool errorThrown = false;\r
796                         try {\r
797                                 ArrayList al1 = \r
798                                         ArrayList.ReadOnly(new ArrayList());\r
799                                 string[] s = {"Hi!"};\r
800                                 al1.InsertRange(0, s);\r
801                         } catch (NotSupportedException) {\r
802                                 errorThrown = true;\r
803                         }\r
804                         Assert("insert to read only error not thrown", \r
805                                errorThrown);\r
806                 }\r
807                 {\r
808                         bool errorThrown = false;\r
809                         try {\r
810                                 ArrayList al1 = new ArrayList(3);\r
811                                 string[] s = {"Hi!"};\r
812                                 al1.InsertRange(-1, s);\r
813                         } catch (ArgumentOutOfRangeException) {\r
814                                 errorThrown = true;\r
815                         }\r
816                         Assert("negative index insert error not thrown", \r
817                                errorThrown);\r
818                 }\r
819                 {\r
820                         bool errorThrown = false;\r
821                         try {\r
822                                 ArrayList al1 = new ArrayList(3);\r
823                                 string[] s = {"Hi!"};\r
824                                 al1.InsertRange(4, s);\r
825                         } catch (ArgumentOutOfRangeException) {\r
826                                 errorThrown = true;\r
827                         }\r
828                         Assert("out-of-range insert error not thrown", \r
829                                errorThrown);\r
830                 }\r
831                 {\r
832                         bool errorThrown = false;\r
833                         try {\r
834                                 ArrayList al1 = new ArrayList(3);\r
835                                 al1.InsertRange(0, null);\r
836                         } catch (ArgumentNullException) {\r
837                                 errorThrown = true;\r
838                         }\r
839                         Assert("null insert error not thrown", \r
840                                errorThrown);\r
841                 }\r
842                 {\r
843                         char[] c = {'a', 'b', 'c'};\r
844                         ArrayList a = new ArrayList(c);\r
845                         a.InsertRange(1, c);\r
846                         AssertEquals("bad insert", 'a', a[0]);\r
847                         AssertEquals("bad insert", 'a', a[1]);\r
848                         AssertEquals("bad insert", 'b', a[2]);\r
849                         AssertEquals("bad insert", 'c', a[3]);\r
850                         AssertEquals("bad insert", 'b', a[4]);\r
851                         AssertEquals("bad insert", 'c', a[5]);\r
852                 }\r
853         }\r
854 \r
855         public void TestLastIndexOf() {\r
856                 //{\r
857                 //bool errorThrown = false;\r
858                 //try {\r
859                 //ArrayList a = new ArrayList(1);\r
860                 //int i = a.LastIndexOf('a', -1);\r
861                 //} catch (ArgumentOutOfRangeException) {\r
862                 //errorThrown = true;\r
863                 //}\r
864                 //Assert("first negative lastindexof error not thrown", \r
865                 //errorThrown);\r
866                 //}\r
867                 {\r
868                         bool errorThrown = false;\r
869                         try {\r
870                                 ArrayList a = new ArrayList(1);\r
871                                 int i = a.LastIndexOf('a', 2);\r
872                         } catch (ArgumentOutOfRangeException) {\r
873                                 errorThrown = true;\r
874                         }\r
875                         Assert("past-end lastindexof error not thrown", \r
876                                errorThrown);\r
877                 }\r
878                 //{\r
879                 //bool errorThrown = false;\r
880                 //try {\r
881                 //ArrayList a = new ArrayList(1);\r
882                 //int i = a.LastIndexOf('a', 0, -1);\r
883                 //} catch (ArgumentOutOfRangeException) {\r
884                 //errorThrown = true;\r
885                 //}\r
886                 //Assert("second negative lastindexof error not thrown", \r
887                 //errorThrown);\r
888                 //}\r
889                 //{\r
890                 //bool errorThrown = false;\r
891                 //try {\r
892                 //ArrayList a = new ArrayList(1);\r
893                 //int i = a.LastIndexOf('a', 0, 2);\r
894                 //} catch (ArgumentOutOfRangeException) {\r
895                 //errorThrown = true;\r
896                 //}\r
897                 //Assert("past-end lastindexof error not thrown", \r
898                 //errorThrown);\r
899                 //}\r
900                 //{\r
901                 //bool errorThrown = false;\r
902                 //try {\r
903                 //ArrayList a = new ArrayList(2);\r
904                 //int i = a.LastIndexOf('a', 0, 2);\r
905                 //} catch (ArgumentOutOfRangeException) {\r
906                 //errorThrown = true;\r
907                 //}\r
908                 //Assert("past-end lastindexof error not thrown", \r
909                 //errorThrown);\r
910                 //}\r
911                 {\r
912                         char[] c = {'a', 'b', 'c', 'd', 'e'};\r
913                         ArrayList a = new ArrayList(c);\r
914                         AssertEquals("never find null", \r
915                                      -1, a.LastIndexOf(null));\r
916                         AssertEquals("never find null", \r
917                                      -1, a.LastIndexOf(null, 4));\r
918                         AssertEquals("never find null", \r
919                                      -1, a.LastIndexOf(null, 4, 5));\r
920                         AssertEquals("can't find elem", \r
921                                      2, a.LastIndexOf('c'));\r
922                         AssertEquals("can't find elem", \r
923                                      2, a.LastIndexOf('c', 4));\r
924                         AssertEquals("can't find elem", \r
925                                      2, a.LastIndexOf('c', 3, 2));\r
926                         AssertEquals("shouldn't find elem", \r
927                                      -1, a.LastIndexOf('c', 4, 2));\r
928                         AssertEquals("shouldn't find", -1, a.LastIndexOf('?'));\r
929                         AssertEquals("shouldn't find", -1, a.LastIndexOf(1));\r
930                 }\r
931         }\r
932 \r
933         public void TestReadOnly() {\r
934                 {\r
935                         bool errorThrown = false;\r
936                         try {\r
937                                 ArrayList al1 = ArrayList.ReadOnly(null);\r
938                         } catch (ArgumentNullException) {\r
939                                 errorThrown = true;\r
940                         }\r
941                         Assert("null arg error not thrown", errorThrown);\r
942                 }\r
943                 {\r
944                         ArrayList al1 = new ArrayList();\r
945                         AssertEquals("arrays start writeable.",\r
946                                      false, al1.IsReadOnly);\r
947                         ArrayList al2 = ArrayList.ReadOnly(al1);\r
948                         AssertEquals("should be readonly.",\r
949                                      true, al2.IsReadOnly);\r
950                 }\r
951         }\r
952 \r
953         public void TestRemove() {\r
954                 {\r
955                         bool errorThrown = false;\r
956                         try {\r
957                                 ArrayList al1 = \r
958                                         ArrayList.FixedSize(new ArrayList(3));\r
959                                 al1.Remove(1);\r
960                         } catch (NotSupportedException) {\r
961                                 errorThrown = true;\r
962                         }\r
963                         Assert("remove fixed size error not thrown", \r
964                                errorThrown);\r
965                 }\r
966                 {\r
967                         bool errorThrown = false;\r
968                         try {\r
969                                 ArrayList al1 = \r
970                                         ArrayList.ReadOnly(new ArrayList(3));\r
971                                 al1.Remove(1);\r
972                         } catch (NotSupportedException) {\r
973                                 errorThrown = true;\r
974                         }\r
975                         Assert("remove read only error not thrown", \r
976                                errorThrown);\r
977                 }\r
978                 {\r
979                         char[] c = {'a','b','c'};\r
980                         ArrayList a = new ArrayList(c);\r
981                         a.Remove(1);\r
982                         a.Remove('?');\r
983                         AssertEquals("should be unchanged", c.Length, a.Count);\r
984                         a.Remove('a');\r
985                         AssertEquals("should be changed", 2, a.Count);\r
986                         AssertEquals("should have shifted", 'b', a[0]);\r
987                         AssertEquals("should have shifted", 'c', a[1]);\r
988                 }\r
989         }\r
990 \r
991         public void TestRemoveAt() {\r
992                 {\r
993                         bool errorThrown = false;\r
994                         try {\r
995                                 ArrayList al1 = \r
996                                         ArrayList.FixedSize(new ArrayList(3));\r
997                                 al1.RemoveAt(1);\r
998                         } catch (NotSupportedException) {\r
999                                 errorThrown = true;\r
1000                         }\r
1001                         Assert("remove from fixed size error not thrown", \r
1002                                errorThrown);\r
1003                 }\r
1004                 {\r
1005                         bool errorThrown = false;\r
1006                         try {\r
1007                                 ArrayList al1 = \r
1008                                         ArrayList.ReadOnly(new ArrayList(3));\r
1009                                 al1.RemoveAt(1);\r
1010                         } catch (NotSupportedException) {\r
1011                                 errorThrown = true;\r
1012                         }\r
1013                         Assert("remove from read only error not thrown", \r
1014                                errorThrown);\r
1015                 }\r
1016                 {\r
1017                         bool errorThrown = false;\r
1018                         try {\r
1019                                 ArrayList al1 = new ArrayList(3);\r
1020                                 al1.RemoveAt(-1);\r
1021                         } catch (ArgumentOutOfRangeException) {\r
1022                                 errorThrown = true;\r
1023                         }\r
1024                         Assert("remove at negative index error not thrown", \r
1025                                errorThrown);\r
1026                 }\r
1027                 {\r
1028                         bool errorThrown = false;\r
1029                         try {\r
1030                                 ArrayList al1 = new ArrayList(3);\r
1031                                 al1.RemoveAt(4);\r
1032                         } catch (ArgumentOutOfRangeException) {\r
1033                                 errorThrown = true;\r
1034                         }\r
1035                         Assert("remove at out-of-range index error not thrown", \r
1036                                errorThrown);\r
1037                 }\r
1038                 {\r
1039                         char[] c = {'a','b','c'};\r
1040                         ArrayList a = new ArrayList(c);\r
1041                         a.RemoveAt(0);\r
1042                         AssertEquals("should be changed", 2, a.Count);\r
1043                         AssertEquals("should have shifted", 'b', a[0]);\r
1044                         AssertEquals("should have shifted", 'c', a[1]);\r
1045                 }\r
1046         }\r
1047 \r
1048         public void TestRemoveRange() {\r
1049                 {\r
1050                         bool errorThrown = false;\r
1051                         try {\r
1052                                 ArrayList al1 = \r
1053                                         ArrayList.FixedSize(new ArrayList(3));\r
1054                                 al1.RemoveRange(0, 1);\r
1055                         } catch (NotSupportedException) {\r
1056                                 errorThrown = true;\r
1057                         }\r
1058                         Assert("removerange from fixed size error not thrown", \r
1059                                errorThrown);\r
1060                 }\r
1061                 {\r
1062                         bool errorThrown = false;\r
1063                         try {\r
1064                                 ArrayList al1 = \r
1065                                         ArrayList.ReadOnly(new ArrayList(3));\r
1066                                 al1.RemoveRange(0, 1);\r
1067                         } catch (NotSupportedException) {\r
1068                                 errorThrown = true;\r
1069                         }\r
1070                         Assert("removerange from read only error not thrown", \r
1071                                errorThrown);\r
1072                 }\r
1073                 {\r
1074                         bool errorThrown = false;\r
1075                         try {\r
1076                                 ArrayList al1 = new ArrayList(3);\r
1077                                 al1.RemoveRange(-1, 1);\r
1078                         } catch (ArgumentOutOfRangeException) {\r
1079                                 errorThrown = true;\r
1080                         }\r
1081                         Assert("removerange at negative index error not thrown", \r
1082                                errorThrown);\r
1083                 }\r
1084                 {\r
1085                         bool errorThrown = false;\r
1086                         try {\r
1087                                 ArrayList al1 = new ArrayList(3);\r
1088                                 al1.RemoveRange(0, -1);\r
1089                         } catch (ArgumentOutOfRangeException) {\r
1090                                 errorThrown = true;\r
1091                         }\r
1092                         Assert("removerange at negative index error not thrown", \r
1093                                errorThrown);\r
1094                 }\r
1095                 {\r
1096                         bool errorThrown = false;\r
1097                         try {\r
1098                                 ArrayList al1 = new ArrayList(3);\r
1099                                 al1.RemoveRange(2, 3);\r
1100                         } catch (ArgumentException) {\r
1101                                 errorThrown = true;\r
1102                         }\r
1103                         Assert("removerange at bad range error not thrown", \r
1104                                errorThrown);\r
1105                 }\r
1106                 {\r
1107                         char[] c = {'a','b','c'};\r
1108                         ArrayList a = new ArrayList(c);\r
1109                         a.RemoveRange(1,2);\r
1110                         AssertEquals("should be changed", 1, a.Count);\r
1111                         AssertEquals("should have shifted", 'a', a[0]);\r
1112                 }\r
1113         }\r
1114 \r
1115         public void TestRepeat() {\r
1116                 {\r
1117                         bool errorThrown = false;\r
1118                         try {\r
1119                                 ArrayList al1 = ArrayList.Repeat('c', -1);\r
1120                         } catch (ArgumentOutOfRangeException) {\r
1121                                 errorThrown = true;\r
1122                         }\r
1123                         Assert("repeat negative copies error not thrown", \r
1124                                errorThrown);\r
1125                 }\r
1126                 {\r
1127                         ArrayList al1 = ArrayList.Repeat("huh?", 0);\r
1128                         AssertEquals("should be nothing in array", \r
1129                                      0, al1.Count);\r
1130                 }               \r
1131                 {\r
1132                         ArrayList al1 = ArrayList.Repeat("huh?", 3);\r
1133                         AssertEquals("should be something in array", \r
1134                                      3, al1.Count);\r
1135                         AssertEquals("array elem doesn't check",\r
1136                                      "huh?", al1[0]);\r
1137                         AssertEquals("array elem doesn't check",\r
1138                                      "huh?", al1[1]);\r
1139                         AssertEquals("array elem doesn't check",\r
1140                                      "huh?", al1[2]);\r
1141                 }\r
1142         }\r
1143 \r
1144         public void TestReverse() {\r
1145                 {\r
1146                         bool errorThrown = false;\r
1147                         try {\r
1148                                 ArrayList al1 = \r
1149                                         ArrayList.ReadOnly(new ArrayList());\r
1150                                 al1.Reverse();\r
1151                         } catch (NotSupportedException) {\r
1152                                 errorThrown = true;\r
1153                         }\r
1154                         Assert("reverse on read only error not thrown", \r
1155                                errorThrown);\r
1156                 }\r
1157                 {\r
1158                         bool errorThrown = false;\r
1159                         try {\r
1160                                 char[] c = new Char[2];\r
1161                                 ArrayList al1 = new ArrayList(c);\r
1162                                 al1.Reverse(0, 3);\r
1163                         } catch (ArgumentException) {\r
1164                                 errorThrown = true;\r
1165                         }\r
1166                         Assert("error not thrown", errorThrown);\r
1167                 }\r
1168                 {\r
1169                         bool errorThrown = false;\r
1170                         try {\r
1171                                 char[] c = new Char[2];\r
1172                                 ArrayList al1 = new ArrayList(c);\r
1173                                 al1.Reverse(3, 0);\r
1174                         } catch (ArgumentException) {\r
1175                                 errorThrown = true;\r
1176                         }\r
1177                         Assert("error not thrown", errorThrown);\r
1178                 }\r
1179                 {\r
1180                         char[] c = {'a', 'b', 'c', 'd', 'e'};\r
1181                         ArrayList al1 = new ArrayList(c);\r
1182                         al1.Reverse(2,1);\r
1183                         for (int i = 0; i < al1.Count; i++) {\r
1184                                 AssertEquals("Should be no change yet",\r
1185                                              c[i], al1[i]);\r
1186                         }\r
1187                         al1.Reverse();\r
1188                         for (int i = 0; i < al1.Count; i++) {\r
1189                                 AssertEquals("Should be reversed",\r
1190                                              c[i], al1[4-i]);\r
1191                         }\r
1192                         al1.Reverse();\r
1193                         for (int i = 0; i < al1.Count; i++) {\r
1194                                 AssertEquals("Should be back to normal",\r
1195                                              c[i], al1[i]);\r
1196                         }\r
1197                         al1.Reverse(1,3);\r
1198                         AssertEquals("Should be back to normal", c[0], al1[0]);\r
1199                         AssertEquals("Should be back to normal", c[3], al1[1]);\r
1200                         AssertEquals("Should be back to normal", c[2], al1[2]);\r
1201                         AssertEquals("Should be back to normal", c[1], al1[3]);\r
1202                         AssertEquals("Should be back to normal", c[4], al1[4]);\r
1203                 }\r
1204         }\r
1205 \r
1206         public void TestSetRange() {\r
1207                 {\r
1208                         bool errorThrown = false;\r
1209                         try {\r
1210                                 char[] c = {'a', 'b', 'c'};\r
1211                                 ArrayList al1 = \r
1212                                         ArrayList.ReadOnly(new ArrayList(3));\r
1213                                 al1.SetRange(0, c);\r
1214                         } catch (NotSupportedException) {\r
1215                                 errorThrown = true;\r
1216                         }\r
1217                         Assert("setrange on read only error not thrown", \r
1218                                errorThrown);\r
1219                 }\r
1220                 {\r
1221                         bool errorThrown = false;\r
1222                         try {\r
1223                                 ArrayList al1 = new ArrayList(3);\r
1224                                 al1.SetRange(0, null);\r
1225                         } catch (ArgumentNullException) {\r
1226                                 errorThrown = true;\r
1227                         } catch (ArgumentOutOfRangeException) {\r
1228                                 errorThrown = true;\r
1229                         }\r
1230                         Assert("setrange with null error not thrown", \r
1231                                errorThrown);\r
1232                 }\r
1233                 {\r
1234                         bool errorThrown = false;\r
1235                         try {\r
1236                                 char[] c = {'a', 'b', 'c'};\r
1237                                 ArrayList al1 = new ArrayList(3);\r
1238                                 al1.SetRange(-1, c);\r
1239                         } catch (ArgumentOutOfRangeException) {\r
1240                                 errorThrown = true;\r
1241                         }\r
1242                         Assert("setrange with negative index error not thrown",\r
1243                                errorThrown);\r
1244                 }\r
1245                 {\r
1246                         bool errorThrown = false;\r
1247                         try {\r
1248                                 char[] c = {'a', 'b', 'c'};\r
1249                                 ArrayList al1 = new ArrayList(3);\r
1250                                 al1.SetRange(2, c);\r
1251                         } catch (ArgumentOutOfRangeException) {\r
1252                                 errorThrown = true;\r
1253                         }\r
1254                         Assert("setrange with too much error not thrown",\r
1255                                errorThrown);\r
1256                 }\r
1257                 {\r
1258                         char[] c = {'a', 'b', 'c'};\r
1259                         ArrayList al1 = ArrayList.Repeat('?', 3);\r
1260                         Assert("no match yet", c[0] != (char)al1[0]);\r
1261                         Assert("no match yet", c[1] != (char)al1[1]);\r
1262                         Assert("no match yet", c[2] != (char)al1[2]);\r
1263                         al1.SetRange(0, c);\r
1264                         AssertEquals("should match", c[0], al1[0]);\r
1265                         AssertEquals("should match", c[1], al1[1]);\r
1266                         AssertEquals("should match", c[2], al1[2]);\r
1267                 }               \r
1268         }\r
1269 \r
1270         public void TestSort() {\r
1271                 {\r
1272                         bool errorThrown = false;\r
1273                         try {\r
1274                                 ArrayList al1 = \r
1275                                         ArrayList.ReadOnly(new ArrayList());\r
1276                                 al1.Sort();\r
1277                         } catch (NotSupportedException) {\r
1278                                 errorThrown = true;\r
1279                         }\r
1280                         Assert("sort on read only error not thrown", \r
1281                                errorThrown);\r
1282                 }\r
1283                 {\r
1284                         char[] starter = {'d', 'b', 'f', 'e', 'a', 'c'};\r
1285                         ArrayList al1 = new ArrayList(starter);\r
1286                         al1.Sort();\r
1287                         AssertEquals("Should be sorted", 'a', al1[0]);\r
1288                         AssertEquals("Should be sorted", 'b', al1[1]);\r
1289                         AssertEquals("Should be sorted", 'c', al1[2]);\r
1290                         AssertEquals("Should be sorted", 'd', al1[3]);\r
1291                         AssertEquals("Should be sorted", 'e', al1[4]);\r
1292                         AssertEquals("Should be sorted", 'f', al1[5]);\r
1293                 }\r
1294         }\r
1295 \r
1296         // TODO - Sort with IComparers\r
1297 \r
1298         // TODO - Synchronize\r
1299 \r
1300         public void TestToArray() {\r
1301                 {\r
1302                         bool errorThrown = false;\r
1303                         try {\r
1304                                 ArrayList al1 = new ArrayList(3);\r
1305                                 al1.ToArray(null);\r
1306                         } catch (ArgumentNullException) {\r
1307                                 errorThrown = true;\r
1308                         }\r
1309                         Assert("toarray with null error not thrown", \r
1310                                errorThrown);\r
1311                 }\r
1312                 {\r
1313                         bool errorThrown = false;\r
1314                         try {\r
1315                                 char[] c = {'a', 'b', 'c'};\r
1316                                 string s = "huh?";\r
1317                                 ArrayList al1 = new ArrayList(c);\r
1318                                 al1.ToArray(s.GetType());\r
1319                         } catch (InvalidCastException) {\r
1320                                 errorThrown = true;\r
1321                         }\r
1322                         Assert("toarray with bad type error not thrown", \r
1323                                errorThrown);\r
1324                 }\r
1325                 {\r
1326                         char[] c1 = {'a', 'b', 'c', 'd', 'e'};\r
1327                         ArrayList al1 = new ArrayList(c1);\r
1328                         object[] o2 = al1.ToArray();\r
1329                         for (int i = 0; i < c1.Length; i++) {\r
1330                                 AssertEquals("should be copy", c1[i], o2[i]);\r
1331                         }\r
1332                         Array c2 = al1.ToArray(c1[0].GetType());\r
1333                         for (int i = 0; i < c1.Length; i++) {\r
1334                                 AssertEquals("should be copy", \r
1335                                              c1[i], c2.GetValue(i));\r
1336                         }\r
1337                 }\r
1338         }\r
1339 \r
1340         public void TestTrimToSize() {\r
1341                 {\r
1342                         bool errorThrown = false;\r
1343                         try {\r
1344                                 ArrayList al1 = \r
1345                                         ArrayList.ReadOnly(new ArrayList());\r
1346                                 al1.TrimToSize();\r
1347                         } catch (NotSupportedException) {\r
1348                                 errorThrown = true;\r
1349                         }\r
1350                         Assert("trim read only error not thrown", \r
1351                                errorThrown);\r
1352                 }\r
1353                 {\r
1354                         ArrayList al1 = new ArrayList();\r
1355                         int capacity = al1.Capacity;\r
1356                         while (al1.Capacity <= capacity) {\r
1357                                 al1.Add('?');\r
1358                         }\r
1359                         al1.RemoveAt(0);\r
1360                         AssertEquals("size not good", capacity, al1.Count);\r
1361                         Assert("capacity not good", al1.Capacity > capacity);\r
1362                         al1.TrimToSize();\r
1363                         AssertEquals("no capacity match", \r
1364                                      capacity, al1.Capacity);\r
1365 \r
1366                         al1.Clear();\r
1367                         al1.TrimToSize();\r
1368                         AssertEquals("no default capacity", \r
1369                                      capacity, al1.Capacity);\r
1370                 }\r
1371         }\r
1372 \r
1373 }\r
1374  \r
1375 }\r