1 // SortedListTest.cs - NUnit Test Cases for the System.Collections.SortedList class
\r
5 // Duncan Mak (duncan@ximian.com)
\r
7 // Thanks go to David Brandt (bucky@keystreams.com),
\r
8 // because this file is based on his ArrayListTest.cs
\r
10 // (C) Ximian, Inc. http://www.ximian.com
\r
12 // main TODO: additional tests for functions affected by
\r
13 // fixedsize and read-only properties
\r
17 using System.Collections;
\r
19 using NUnit.Framework;
\r
22 namespace MonoTests.System.Collections {
\r
25 /// <summary>SortedList test.</summary>
\r
27 public class SortedListTest : Assertion {
\r
28 protected SortedList sl1;
\r
29 protected SortedList sl2;
\r
30 protected SortedList emptysl;
\r
31 protected const int icap=16;
\r
34 public void SetUp()
\r
39 public void TearDown()
\r
43 public void TestConstructor1() {
\r
44 SortedList temp1 = new SortedList();
\r
45 AssertNotNull("sl.constructor-1: returns null", temp1);
\r
46 AssertEquals("sl.constructor-1: incorrect initial capacity", icap, temp1.Capacity);
\r
50 public void TestConstructor2() {
\r
51 Comparer c = Comparer.Default;
\r
52 SortedList temp1 = new SortedList(c);
\r
53 AssertNotNull("sl.constructor-2: returns null", temp1);
\r
54 AssertEquals("sl.constructor-2: incorrect initial capacity", icap, temp1.Capacity);
\r
58 public void TestConstructor3() {
\r
59 Hashtable d = new Hashtable();
\r
60 d.Add("one", "Mircosoft");
\r
61 d.Add("two", "will");
\r
62 d.Add("three", "rule");
\r
63 d.Add("four", "the world");
\r
65 SortedList temp1 = new SortedList(d);
\r
66 AssertNotNull("sl.constructor-3: returns null", temp1);
\r
67 AssertEquals("sl.constructor-3: incorrect initial capacity", 4, temp1.Capacity);
\r
68 AssertEquals("sl.constructor-3: incorrect count", 4, temp1.Count);
\r
72 temp1 = new SortedList(d);
\r
73 Fail ("sl.constructor-3: does not throw ArgumentNullException");
\r
74 } catch (ArgumentNullException) {}
\r
76 d = new Hashtable();
\r
77 d.Add("one", "Mircosoft");
\r
78 d.Add("two", "will");
\r
79 d.Add("three", "rule");
\r
80 d.Add("four", "the world");
\r
82 temp1 = new SortedList(d);
\r
83 Fail ("sl.constructor-3: does not throw InvalidCastException");
\r
84 } catch (InvalidOperationException) {
\r
85 } catch (Exception e) {
\r
86 Fail ("Unexpected Exception throw: e=" + e);
\r
91 public void TestConstructor4() {
\r
92 SortedList temp1 = new SortedList(17);
\r
93 AssertNotNull("sl.constructor-4: returns null", temp1);
\r
94 AssertEquals("sl.constructor-4: incorrect initial capacity", temp1.Capacity, 17);
\r
96 temp1 = new SortedList(-6);
\r
97 Fail ("sl.constructor-4: does not throw ArgumentOutOfRangeException, with negative values");
\r
98 } catch (ArgumentOutOfRangeException) {}
\r
100 temp1 = new SortedList(0);
\r
101 } catch (ArgumentOutOfRangeException) {
\r
102 Fail ("sl.constructor-4: throws ArgumentOutOfRangeException with 0");
\r
107 public void TestConstructor5() {
\r
108 Comparer c = Comparer.Default;
\r
109 SortedList temp1 = new SortedList(c,27);
\r
110 AssertNotNull("sl.constructor-5: returns null", temp1);
\r
111 AssertEquals("sl.constructor-5: incorrect initial capacity", temp1.Capacity, 27);
\r
113 temp1 = new SortedList(-12);
\r
114 Fail ("sl.constructor-5: does not throw ArgumentOutOfRangeException, with negative values");
\r
115 } catch (ArgumentOutOfRangeException) {}
\r
119 public void TestIsSynchronized() {
\r
120 SortedList sl1 = new SortedList();
\r
121 Assert("sl: should not be synchronized by default",
\r
122 !sl1.IsSynchronized);
\r
123 SortedList sl2 = SortedList.Synchronized(sl1);
\r
124 Assert("sl: synchronized wrapper not working", sl2.IsSynchronized);
\r
128 public void TestCapacity() {
\r
129 for (int i = 0; i < 100; i++) {
\r
130 SortedList sl1 = new SortedList(i);
\r
131 AssertEquals("Bad capacity of " + i,
\r
137 public void TestCapacity2 ()
\r
139 SortedList list = new SortedList ();
\r
142 AssertEquals (5, list.Capacity);
\r
146 public void TestCapacity3 ()
\r
148 int new_capacity = 5;
\r
149 SortedList list = new SortedList (1000);
\r
150 list.Capacity = new_capacity;
\r
153 AssertEquals (new_capacity, list.Capacity);
\r
155 AssertEquals (16, list.Capacity);
\r
160 [ExpectedException (typeof (OutOfMemoryException))]
\r
161 [Ignore ("This is not implemented in the runtime yet")]
\r
162 public void TestCapacity4 ()
\r
164 SortedList list = new SortedList ();
\r
165 list.Capacity = Int32.MaxValue;
\r
169 public void TestCount() {
\r
171 SortedList sl1 = new SortedList();
\r
172 AssertEquals("Bad initial count",
\r
174 for (int i = 1; i <= 100; i++) {
\r
175 sl1.Add(""+i,""+i);
\r
176 AssertEquals("Bad count " + i,
\r
183 public void TestIsFixed() {
\r
184 SortedList sl1 = new SortedList();
\r
185 Assert("should not be fixed by default", !sl1.IsFixedSize);
\r
190 public void TestIsReadOnly() {
\r
191 SortedList sl1 = new SortedList();
\r
192 Assert("should not be ReadOnly by default", !sl1.IsReadOnly);
\r
197 public void TestItem() {
\r
198 SortedList sl1 = new SortedList();
\r
202 object o = sl1[-1];
\r
203 } catch (ArgumentNullException) {
\r
204 Fail ("sl.Item: throws ArgumentNullException with negative values");
\r
207 object o = sl1[key];
\r
208 Fail ("sl.Item: does not throw ArgumentNullException with null key");
\r
209 } catch (ArgumentNullException) {}
\r
212 for (int i = 0; i <= 100; i++) {
\r
213 sl1.Add("kala "+i,i);
\r
215 for (int i = 0; i <= 100; i++) {
\r
216 AssertEquals("sl.Item: item not fetched for " + i,
\r
217 i, sl1["kala "+i]);
\r
222 public void TestSyncRoot()
\r
224 SortedList sl1 = new SortedList();
\r
225 AssertEquals("sl.SyncRoot: does not function",false, sl1.SyncRoot == null);
\r
227 lock( sl1.SyncRoot ) {
\r
228 foreach ( Object item in sl1 ) {
\r
230 Assert ("sl.SyncRoot: item not read-only",item.IsReadOnly);
\r
237 public void TestValues()
\r
239 SortedList sl1 = new SortedList();
\r
240 ICollection ic1 = sl1.Values;
\r
241 for (int i = 0; i <= 100; i++) {
\r
242 sl1.Add("kala "+i,i);
\r
243 AssertEquals("sl.Values: .Values has different count",ic1.Count,sl1.Count);
\r
248 // TODO: Add with IComparer
\r
250 public void TestAdd() {
\r
251 // seems SortedList cannot be set fixedsize or readonly
\r
252 SortedList sl1 = new SortedList();
\r
256 sl1.Add(key,"kala");
\r
257 Fail ("sl.Add: does not throw ArgumentNullException with null key");
\r
258 } catch (ArgumentNullException) {}
\r
262 for (int i = 1; i <= 100; i++) {
\r
263 sl1.Add("kala "+i,i);
\r
264 AssertEquals("sl.Add: incorrect count",i,sl1.Count);
\r
265 AssertEquals("sl.Add: incorrect value",i,sl1["kala "+i]);
\r
270 sl1.Add("kala",10);
\r
271 sl1.Add("kala",11);
\r
272 Fail ("sl.Add: does not throw ArgumentException when adding existing key");
\r
273 } catch (ArgumentException) {}
\r
278 public void TestClear() {
\r
279 SortedList sl1 = new SortedList(10);
\r
280 sl1.Add("kala", 'c');
\r
281 sl1.Add("kala2", 'd');
\r
282 AssertEquals("sl.Clear: capacity is incorrect", 10, sl1.Capacity);
\r
283 AssertEquals("sl.Clear: should have one element", 2, sl1.Count);
\r
285 AssertEquals("sl.Clear: is not cleared", 0, sl1.Count);
\r
286 AssertEquals("sl.Clear: capacity is altered", 16, sl1.Capacity);
\r
290 public void TestClone() {
\r
292 SortedList sl1 = new SortedList(10);
\r
293 for (int i = 0; i <= 50; i++) {sl1.Add("kala "+i,i);}
\r
294 SortedList sl2 = (SortedList)sl1.Clone();
\r
295 for (int i = 0; i <= 50; i++) {
\r
296 AssertEquals("sl.Clone: copying failed @"+i, sl1["kala "+i], sl2["kala "+i]);
\r
300 char[] d10 = {'a', 'b'};
\r
301 char[] d11 = {'a', 'c'};
\r
302 char[] d12 = {'b', 'c'};
\r
303 //char[][] d1 = {d10, d11, d12};
\r
304 SortedList sl1 = new SortedList();
\r
308 SortedList sl2 = (SortedList)sl1.Clone();
\r
309 AssertEquals("sl.Clone: Array not matching", sl1["d1"], sl2["d1"]);
\r
310 AssertEquals("sl.Clone: Array not matching", sl1["d2"], sl2["d2"]);
\r
311 AssertEquals("sl.Clone: Array not matching", sl1["d3"], sl2["d3"]);
\r
313 ((char[])sl1["d1"])[0] = 'z';
\r
314 AssertEquals("s1.Clone: shallow copy", sl1["d1"], sl2["d1"]);
\r
319 public void TestContains() {
\r
320 SortedList sl1 = new SortedList(55);
\r
321 for (int i = 0; i <= 50; i++) {sl1.Add("kala "+i,i);}
\r
324 if (sl1.Contains(null)){}
\r
325 Fail ("sl.Contains: does not throw ArgumentNullException with null key");
\r
326 } catch (ArgumentNullException) {}
\r
328 Assert("sl.Contains: can't find existing key", sl1.Contains("kala 17"));
\r
329 Assert("sl.Contains: finds non-existing key", !sl1.Contains("ohoo"));
\r
333 public void TestContainsKey() {
\r
334 SortedList sl1 = new SortedList(55);
\r
335 for (int i = 0; i <= 50; i++) {sl1.Add("kala "+i,i);}
\r
338 if (sl1.ContainsKey(null)){}
\r
339 Fail ("sl.ContainsKey: does not throw ArgumentNullException with null key");
\r
340 } catch (ArgumentNullException) {}
\r
342 Assert("sl.ContainsKey: can't find existing key", sl1.ContainsKey("kala 17"));
\r
343 Assert("sl.ContainsKey: finds non-existing key", !sl1.ContainsKey("ohoo"));
\r
347 public void TestContainsValue() {
\r
348 SortedList sl1 = new SortedList(55);
\r
349 sl1.Add(0, "zero");
\r
352 sl1.Add(3, "three");
\r
353 sl1.Add(4, "four");
\r
355 Assert("sl.ContainsValue: can't find existing value", sl1.ContainsValue("zero"));
\r
356 Assert("sl.ContainsValue: finds non-existing value", !sl1.ContainsValue("ohoo"));
\r
357 Assert("sl.ContainsValue: finds non-existing value", !sl1.ContainsValue(null));
\r
361 public void TestCopyTo() {
\r
362 SortedList sl1 = new SortedList();
\r
363 for (int i = 0; i <= 10; i++) {sl1.Add("kala "+i,i);}
\r
366 sl1.CopyTo(null, 2);
\r
367 Fail("sl.CopyTo: does not throw ArgumentNullException when target null");
\r
368 } catch (ArgumentNullException) {}
\r
372 Char[,] c2 = new Char[2,2];
\r
374 Fail("sl.CopyTo: does not throw ArgumentException when target is multiarray");
\r
375 } catch (ArgumentException) {}
\r
379 Char[] c1 = new Char[2];
\r
380 sl1.CopyTo(c1, -2);
\r
381 Fail("sl.CopyTo: does not throw ArgumentOutOfRangeException when index is negative");
\r
382 } catch (ArgumentOutOfRangeException) {}
\r
386 Char[] c1 = new Char[2];
\r
388 Fail("sl.CopyTo: does not throw ArgumentException when index is too large");
\r
389 } catch (ArgumentException) {}
\r
393 Char[] c1 = new Char[2];
\r
395 Fail("sl.CopyTo: does not throw ArgumentException when SortedList too big for the array");
\r
396 } catch (ArgumentException) {}
\r
400 Char[] c2 = new Char[15];
\r
402 Fail("sl.CopyTo: does not throw InvalidCastException when incompatible data types");
\r
403 } catch (InvalidCastException) {}
\r
406 // CopyTo function does not work well with SortedList
\r
407 // even example at MSDN gave InvalidCastException
\r
408 // thus, it is NOT tested here
\r
411 for (int i = 0; i <= 5; i++) {sl1.Add(i,""+i);}
\r
412 Char[] copy = new Char[15];
\r
413 Array.Clear(copy,0,copy.Length);
\r
414 copy.SetValue( "The", 0 );
\r
415 copy.SetValue( "quick", 1 );
\r
416 copy.SetValue( "brown", 2 );
\r
417 copy.SetValue( "fox", 3 );
\r
418 copy.SetValue( "jumped", 4 );
\r
419 copy.SetValue( "over", 5 );
\r
420 copy.SetValue( "the", 6 );
\r
421 copy.SetValue( "lazy", 7 );
\r
422 copy.SetValue( "dog", 8 );
\r
423 sl1.CopyTo(copy,1);
\r
424 AssertEquals("sl.CopyTo: incorrect copy(1).","The", copy.GetValue(0));
\r
425 AssertEquals("sl.CopyTo: incorrect copy(1).","quick", copy.GetValue(1));
\r
426 for (int i=2; i<8; i++) AssertEquals("sl.CopyTo: incorrect copy(2).",sl1["kala "+(i-2)], copy.GetValue(i));
\r
427 AssertEquals("sl.CopyTo: incorrect copy(3).","dog", copy.GetValue(8));
\r
431 public SortedList DefaultSL() {
\r
432 SortedList sl1 = new SortedList();
\r
433 sl1.Add( 1.0, "The" );
\r
434 sl1.Add( 1.1, "quick" );
\r
435 sl1.Add( 34.0, "brown" );
\r
436 sl1.Add( -100.75, "fox" );
\r
437 sl1.Add( 1.4, "jumped" );
\r
438 sl1.Add( 1.5, "over" );
\r
439 sl1.Add( 1.6, "the" );
\r
440 sl1.Add( 1.7, "lazy" );
\r
441 sl1.Add( 1.8, "dog" );
\r
445 public IList DefaultValues() {
\r
446 IList il = new ArrayList();
\r
450 il.Add( "jumped" );
\r
460 public void TestGetByIndex() {
\r
461 SortedList sl1 = DefaultSL();
\r
462 AssertEquals("cl.GetByIndex: failed(1)",sl1.GetByIndex(4),"over");
\r
463 AssertEquals("cl.GetByIndex: failed(2)",sl1.GetByIndex(8),"brown");
\r
465 sl1.GetByIndex(-1);
\r
466 Fail("sl.GetByIndex: does not throw ArgumentOutOfRangeException with negative index");
\r
467 } catch (ArgumentOutOfRangeException) {}
\r
469 sl1.GetByIndex(100);
\r
470 Fail("sl.GetByIndex: does not throw ArgumentOutOfRangeException with too large index");
\r
471 } catch (ArgumentOutOfRangeException) {}
\r
475 public void TestGetEnumerator() {
\r
476 SortedList sl1 = DefaultSL();
\r
477 IDictionaryEnumerator e = sl1.GetEnumerator();
\r
478 AssertNotNull("sl.GetEnumerator: does not return enumerator", e);
\r
479 AssertEquals("sl.GetEnumerator: enumerator not working(1)",e.MoveNext(),true);
\r
480 AssertNotNull("sl.GetEnumerator: enumerator not working(2)",e.Current);
\r
484 public void TestGetKey() {
\r
485 SortedList sl1 = DefaultSL();
\r
486 AssertEquals("sl.GetKey: failed(1)",sl1.GetKey(4),1.5);
\r
487 AssertEquals("sl.GetKey: failed(2)",sl1.GetKey(8),34.0);
\r
490 Fail("sl.GetKey: does not throw ArgumentOutOfRangeException with negative index");
\r
491 } catch (ArgumentOutOfRangeException) {}
\r
494 Fail("sl.GetKey: does not throw ArgumentOutOfRangeException with too large index");
\r
495 } catch (ArgumentOutOfRangeException) {}
\r
499 public void TestGetKeyList() {
\r
500 SortedList sl1 = DefaultSL();
\r
501 IList keys = sl1.GetKeyList();
\r
502 AssertNotNull("sl.GetKeyList: does not return keylist", keys);
\r
503 Assert("sl.GetKeyList: keylist is not readonly", keys.IsReadOnly);
\r
504 AssertEquals("sl.GetKeyList: incorrect keylist size",keys.Count,9);
\r
505 AssertEquals("sl.GetKeyList: incorrect key(1)",keys[3],1.4);
\r
506 sl1.Add(33.9,"ehhe");
\r
507 AssertEquals("sl.GetKeyList: incorrect keylist size",keys.Count,10);
\r
508 AssertEquals("sl.GetKeyList: incorrect key(2)",keys[8],33.9);
\r
512 public void TestGetValueList() {
\r
513 SortedList sl1 = DefaultSL();
\r
514 IList originalvals = DefaultValues();
\r
515 IList vals = sl1.GetValueList();
\r
516 AssertNotNull("sl.GetValueList: does not return valuelist", vals);
\r
517 Assert("sl.GetValueList: valuelist is not readonly", vals.IsReadOnly);
\r
518 AssertEquals("sl.GetValueList: incorrect valuelist size",vals.Count,sl1.Count);
\r
519 for (int i=0; i<sl1.Count; i++) {
\r
520 AssertEquals("sl.GetValueList: incorrect key(1)",vals[i],originalvals[i]);
\r
523 sl1.Add(0.01,"ehhe");
\r
524 AssertEquals("sl.GetValueList: incorrect valuelist size",vals.Count,10);
\r
525 AssertEquals("sl.GetValueList: incorrect value(2)",vals[8],"dog");
\r
528 // TODO: IEnumerable.GetEnumerator [Explicit Interface Implementation]
\r
530 public void TestIEnumerable_GetEnumerator() {
\r
531 SortedList sl1 = DefaultSL();
\r
532 IEnumerator e = sl1.IEnumerable.GetEnumerator();
\r
533 AssertNotNull("sl.GetEnumerator: does not return enumerator", e);
\r
534 AssertEquals("sl.GetEnumerator: enumerator not working(1)",e.MoveNext(),true);
\r
535 AssertNotNull("sl.GetEnumerator: enumerator not working(2)",e.Current);
\r
540 public void TestIndexOfKey() {
\r
541 SortedList sl1 = new SortedList(24);
\r
544 for (int i = 0; i <= 50; i++) {
\r
545 s=string.Format("{0:D2}", i);
\r
546 sl1.Add("kala "+s,i);
\r
548 AssertEquals("sl.IndexOfKey: does not return -1 for non-existing key", -1, sl1.IndexOfKey("kala "));
\r
551 t=sl1.IndexOfKey(s);
\r
552 Fail("sl.IndexOfKey: ArgumentNullException not caught, when key is null");
\r
554 catch (ArgumentNullException) {}
\r
556 t=sl1.IndexOfKey(10);
\r
557 Fail("sl.IndexOfKey: InvalidOperationException not caught, when key invalid");
\r
559 catch (InvalidOperationException) {}
\r
560 for (int i=0; i<=50; i++) {
\r
561 s=string.Format("{0:D2}", i);
\r
562 AssertEquals("sl.IndexOfKey: incorrect index key", i, sl1.IndexOfKey("kala "+s));
\r
567 public void TestIndexOfValue() {
\r
568 SortedList sl1 = new SortedList(24);
\r
570 for (int i = 0; i < 50; i++) {
\r
571 s=string.Format("{0:D2}", i);
\r
572 sl1.Add("kala "+s,100+i*i);
\r
574 for (int i = 0; i < 50; i++) {
\r
575 s=string.Format("{0:D2}", i+50);
\r
576 sl1.Add("kala "+s,100+i*i);
\r
578 AssertEquals("sl.IndexOfValue: does not return -1 for non-existing value(1)", -1, sl1.IndexOfValue(102));
\r
579 AssertEquals("sl.IndexOfValue: does not return -1 for non-existing value(2)", -1, sl1.IndexOfValue(null));
\r
580 for (int i=0; i<50; i++) {
\r
581 AssertEquals("sl.IndexOfValue: incorrect index key", i, sl1.IndexOfValue(100+i*i));
\r
586 public void TestIndexOfValue2 ()
\r
588 SortedList list = new SortedList ();
\r
589 list.Add ("key0", "la la");
\r
590 list.Add ("key1", "value");
\r
591 list.Add ("key2", "value");
\r
593 int i = list.IndexOfValue ("value");
\r
595 AssertEquals (1, i);
\r
599 public void TestIndexOfValue3 ()
\r
601 SortedList list = new SortedList ();
\r
602 int i = list.IndexOfValue ((string) null);
\r
604 AssertEquals (1, -i);
\r
608 public void TestIndexer ()
\r
610 SortedList list = new SortedList ();
\r
612 list.Add (1, new Queue ());
\r
613 list.Add (2, new Hashtable ());
\r
614 list.Add (3, new Stack ());
\r
616 AssertEquals (typeof (Queue), list [1].GetType ());
\r
617 AssertEquals (typeof (Hashtable), list [2].GetType ());
\r
618 AssertEquals (typeof (Stack), list [3].GetType ());
\r
622 public void TestEnumerator ()
\r
624 SortedList list = new SortedList ();
\r
626 list.Add (1, new Queue ());
\r
627 list.Add (2, new Hashtable ());
\r
628 list.Add (3, new Stack ());
\r
630 foreach (DictionaryEntry d in list) {
\r
632 int key = (int) d.Key;
\r
633 Type value = d.Value.GetType ();
\r
637 AssertEquals (typeof (Queue), value);
\r
641 AssertEquals (typeof (Hashtable), value);
\r
645 AssertEquals (typeof (Stack), value);
\r
649 Fail ("This is incorrect: " + value.FullName);
\r
656 public void TestRemove() {
\r
657 SortedList sl1 = new SortedList(24);
\r
660 for (int i = 0; i < 50; i++) sl1.Add("kala "+i,i);
\r
664 Fail("sl.Remove: ArgumentNullException not caught, when key is null");
\r
665 } catch (ArgumentNullException) {}
\r
667 sl1.Remove("kala ");
\r
668 AssertEquals("sl.Remove: removes an item, when non-existing key given",sl1.Count,k);
\r
671 Fail("sl.Remove: IComparer exception is not thrown");
\r
672 } catch (Exception) {}
\r
674 for (int i=15; i<20; i++) sl1.Remove("kala "+i);
\r
675 for (int i=45; i<55; i++) sl1.Remove("kala "+i);
\r
677 AssertEquals("sl.Remove: removing failed",sl1.Count,40);
\r
678 for (int i=45; i<55; i++)
\r
679 AssertEquals("sl.Remove: removing failed(2)",sl1["kala "+i],null);
\r
683 public void TestRemoveAt() {
\r
684 SortedList sl1 = new SortedList(24);
\r
687 for (int i = 0; i < 50; i++) {
\r
688 s=string.Format("{0:D2}", i);
\r
689 sl1.Add("kala "+s,i);
\r
694 Fail("sl.RemoveAt: ArgumentOutOfRangeException not caught, when key is out of range");
\r
695 } catch (ArgumentOutOfRangeException) {}
\r
698 Fail("sl.RemoveAt: ArgumentOutOfRangeException not caught, when key is out of range");
\r
699 } catch (ArgumentOutOfRangeException) {}
\r
702 for (int i=0; i<20; i++) sl1.RemoveAt(9);
\r
704 AssertEquals("sl.RemoveAt: removing failed",sl1.Count,30);
\r
705 for (int i=0; i<9; i++)
\r
706 AssertEquals("sl.RemoveAt: removing failed(2)",sl1["kala "+string.Format("{0:D2}", i)],i);
\r
707 for (int i=9; i<29; i++)
\r
708 AssertEquals("sl.RemoveAt: removing failed(3)",sl1["kala "+string.Format("{0:D2}", i)],null);
\r
709 for (int i=29; i<50; i++)
\r
710 AssertEquals("sl.RemoveAt: removing failed(4)",sl1["kala "+string.Format("{0:D2}", i)],i);
\r
714 public void TestSetByIndex() {
\r
715 SortedList sl1 = new SortedList(24);
\r
716 for (int i = 49; i>=0; i--) sl1.Add(100+i,i);
\r
719 sl1.SetByIndex(-1,77);
\r
720 Fail("sl.SetByIndex: ArgumentOutOfRangeException not caught, when key is out of range");
\r
721 } catch (ArgumentOutOfRangeException) {}
\r
723 sl1.SetByIndex(100,88);
\r
724 Fail("sl.SetByIndex: ArgumentOutOfRangeException not caught, when key is out of range");
\r
725 } catch (ArgumentOutOfRangeException) {}
\r
727 for(int i=5; i<25; i++) sl1.SetByIndex(i,-1);
\r
728 for(int i=0; i<5; i++)
\r
729 AssertEquals("sl.SetByIndex: set failed(1)",sl1[100+i],i);
\r
730 for(int i=5; i<25; i++)
\r
731 AssertEquals("sl.SetByIndex: set failed(2)",sl1[100+i],-1);
\r
732 for(int i=25; i<50; i++)
\r
733 AssertEquals("sl.SetByIndex: set failed(3)",sl1[100+i],i);
\r
738 public void TestTrimToSize() {
\r
739 SortedList sl1 = new SortedList(24);
\r
742 AssertEquals("sl.TrimToSize: incorrect capacity after trimming empty list",icap,sl1.Capacity);
\r
744 for (int i = 72; i>=0; i--) sl1.Add(100+i,i);
\r
746 AssertEquals("sl.TrimToSize: incorrect capacity after trimming a list",73,sl1.Capacity);
\r