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 public class SortedListTest : Assertion {
\r
26 protected SortedList sl1;
\r
27 protected SortedList sl2;
\r
28 protected SortedList emptysl;
\r
29 protected const int icap=16;
\r
31 public void TestConstructor1() {
\r
32 SortedList temp1 = new SortedList();
\r
33 AssertNotNull("sl.constructor-1: returns null", temp1);
\r
34 AssertEquals("sl.constructor-1: incorrect initial capacity", icap, temp1.Capacity);
\r
38 public void TestConstructor2() {
\r
39 Comparer c = Comparer.Default;
\r
40 SortedList temp1 = new SortedList(c);
\r
41 AssertNotNull("sl.constructor-2: returns null", temp1);
\r
42 AssertEquals("sl.constructor-2: incorrect initial capacity", icap, temp1.Capacity);
\r
46 public void TestConstructor3() {
\r
47 Hashtable d = new Hashtable();
\r
48 d.Add("one", "Mircosoft");
\r
49 d.Add("two", "will");
\r
50 d.Add("three", "rule");
\r
51 d.Add("four", "the world");
\r
53 SortedList temp1 = new SortedList(d);
\r
54 AssertNotNull("sl.constructor-3: returns null", temp1);
\r
55 AssertEquals("sl.constructor-3: incorrect initial capacity", 4, temp1.Capacity);
\r
56 AssertEquals("sl.constructor-3: incorrect count", 4, temp1.Count);
\r
60 temp1 = new SortedList(d);
\r
61 Fail ("sl.constructor-3: does not throw ArgumentNullException");
\r
62 } catch (ArgumentNullException) {}
\r
64 d = new Hashtable();
\r
65 d.Add("one", "Mircosoft");
\r
66 d.Add("two", "will");
\r
67 d.Add("three", "rule");
\r
68 d.Add("four", "the world");
\r
70 temp1 = new SortedList(d);
\r
71 Fail ("sl.constructor-3: does not throw InvalidCastException");
\r
72 } catch (InvalidOperationException) {
\r
73 } catch (Exception e) {
\r
74 Fail ("Unexpected Exception throw: e=" + e);
\r
79 public void TestConstructor4() {
\r
80 SortedList temp1 = new SortedList(17);
\r
81 AssertNotNull("sl.constructor-4: returns null", temp1);
\r
82 AssertEquals("sl.constructor-4: incorrect initial capacity", temp1.Capacity, 17);
\r
84 temp1 = new SortedList(-6);
\r
85 Fail ("sl.constructor-4: does not throw ArgumentOutOfRangeException, with negative values");
\r
86 } catch (ArgumentOutOfRangeException) {}
\r
88 temp1 = new SortedList(0);
\r
89 } catch (ArgumentOutOfRangeException) {
\r
90 Fail ("sl.constructor-4: throws ArgumentOutOfRangeException with 0");
\r
95 public void TestConstructor5() {
\r
96 Comparer c = Comparer.Default;
\r
97 SortedList temp1 = new SortedList(c,27);
\r
98 AssertNotNull("sl.constructor-5: returns null", temp1);
\r
99 AssertEquals("sl.constructor-5: incorrect initial capacity", temp1.Capacity, 27);
\r
101 temp1 = new SortedList(-12);
\r
102 Fail ("sl.constructor-5: does not throw ArgumentOutOfRangeException, with negative values");
\r
103 } catch (ArgumentOutOfRangeException) {}
\r
107 public void Constructor_Capacity ()
\r
109 SortedList sl = new SortedList (0);
\r
110 AssertEquals ("Capacity-Original", 0, sl.Capacity);
\r
112 // doesn't reset to class default (16)
\r
113 AssertEquals ("Capacity-Resetted", 0, sl.Capacity);
\r
115 for (int i=1; i <= 16; i++) {
\r
116 sl = new SortedList (i);
\r
117 AssertEquals ("Capacity-Original" + i.ToString (), i, sl.Capacity);
\r
119 // reset to class default (16)
\r
120 AssertEquals ("Capacity-Resetted" + i.ToString (), 16, sl.Capacity);
\r
125 public void TestIsSynchronized() {
\r
126 SortedList sl1 = new SortedList();
\r
127 Assert("sl: should not be synchronized by default",
\r
128 !sl1.IsSynchronized);
\r
129 SortedList sl2 = SortedList.Synchronized(sl1);
\r
130 Assert("sl: synchronized wrapper not working", sl2.IsSynchronized);
\r
134 public void TestCapacity() {
\r
135 for (int i = 0; i < 100; i++) {
\r
136 SortedList sl1 = new SortedList(i);
\r
137 AssertEquals("Bad capacity of " + i,
\r
143 public void TestCapacity2 ()
\r
145 SortedList list = new SortedList ();
\r
148 AssertEquals (5, list.Capacity);
\r
150 SortedList sync = SortedList.Synchronized (list);
\r
151 AssertEquals (5, sync.Capacity);
\r
153 list.Capacity = 20;
\r
154 AssertEquals (20, list.Capacity);
\r
155 AssertEquals (20, sync.Capacity);
\r
159 public void TestCapacity3 ()
\r
161 int new_capacity = 5;
\r
162 SortedList list = new SortedList (1000);
\r
163 list.Capacity = new_capacity;
\r
166 AssertEquals (new_capacity, list.Capacity);
\r
168 AssertEquals (16, list.Capacity);
\r
173 public void Capacity_BackTo0 ()
\r
175 SortedList list = new SortedList (42);
\r
176 AssertEquals ("42", 42, list.Capacity);
\r
178 AssertEquals ("0(16)", 16, list.Capacity);
\r
182 [ExpectedException (typeof (OutOfMemoryException))]
\r
183 public void TestCapacity4 ()
\r
185 SortedList list = new SortedList ();
\r
186 list.Capacity = Int32.MaxValue;
\r
190 public void TestCount() {
\r
192 SortedList sl1 = new SortedList();
\r
193 AssertEquals("Bad initial count",
\r
195 for (int i = 1; i <= 100; i++) {
\r
196 sl1.Add(""+i,""+i);
\r
197 AssertEquals("Bad count " + i,
\r
204 public void TestIsFixed() {
\r
205 SortedList sl1 = new SortedList();
\r
206 Assert("should not be fixed by default", !sl1.IsFixedSize);
\r
211 public void TestIsReadOnly() {
\r
212 SortedList sl1 = new SortedList();
\r
213 Assert("should not be ReadOnly by default", !sl1.IsReadOnly);
\r
218 public void TestItem() {
\r
219 SortedList sl1 = new SortedList();
\r
223 object o = sl1[-1];
\r
224 } catch (ArgumentNullException) {
\r
225 Fail ("sl.Item: throws ArgumentNullException with negative values");
\r
228 object o = sl1[key];
\r
229 Fail ("sl.Item: does not throw ArgumentNullException with null key");
\r
230 } catch (ArgumentNullException) {}
\r
233 for (int i = 0; i <= 100; i++) {
\r
234 sl1.Add("kala "+i,i);
\r
236 for (int i = 0; i <= 100; i++) {
\r
237 AssertEquals("sl.Item: item not fetched for " + i,
\r
238 i, sl1["kala "+i]);
\r
243 public void TestSyncRoot()
\r
245 SortedList sl1 = new SortedList();
\r
246 AssertEquals("sl.SyncRoot: does not function",false, sl1.SyncRoot == null);
\r
248 lock( sl1.SyncRoot ) {
\r
249 foreach ( Object item in sl1 ) {
\r
251 Assert ("sl.SyncRoot: item not read-only",item.IsReadOnly);
\r
258 public void TestValues()
\r
260 SortedList sl1 = new SortedList();
\r
261 ICollection ic1 = sl1.Values;
\r
262 for (int i = 0; i <= 100; i++) {
\r
263 sl1.Add("kala "+i,i);
\r
264 AssertEquals("sl.Values: .Values has different count",ic1.Count,sl1.Count);
\r
269 // TODO: Add with IComparer
\r
271 public void TestAdd() {
\r
272 // seems SortedList cannot be set fixedsize or readonly
\r
273 SortedList sl1 = new SortedList();
\r
277 sl1.Add(key,"kala");
\r
278 Fail ("sl.Add: does not throw ArgumentNullException with null key");
\r
279 } catch (ArgumentNullException) {}
\r
283 for (int i = 1; i <= 100; i++) {
\r
284 sl1.Add("kala "+i,i);
\r
285 AssertEquals("sl.Add: incorrect count",i,sl1.Count);
\r
286 AssertEquals("sl.Add: incorrect value",i,sl1["kala "+i]);
\r
291 sl1.Add("kala",10);
\r
292 sl1.Add("kala",11);
\r
293 Fail ("sl.Add: does not throw ArgumentException when adding existing key");
\r
294 } catch (ArgumentException) {}
\r
299 public void TestClear() {
\r
300 SortedList sl1 = new SortedList(10);
\r
301 sl1.Add("kala", 'c');
\r
302 sl1.Add("kala2", 'd');
\r
303 AssertEquals("sl.Clear: capacity is incorrect", 10, sl1.Capacity);
\r
304 AssertEquals("sl.Clear: should have one element", 2, sl1.Count);
\r
306 AssertEquals("sl.Clear: is not cleared", 0, sl1.Count);
\r
307 AssertEquals("sl.Clear: capacity is altered", 16, sl1.Capacity);
\r
311 public void Clear_Capacity ()
\r
313 // strangely Clear change the default capacity (while Capacity doesn't)
\r
314 for (int i=0; i <= 16; i++) {
\r
315 SortedList sl = new SortedList (i);
\r
316 AssertEquals ("Capacity-Original" + i.ToString (), i, sl.Capacity);
\r
318 // reset to class default (16)
\r
319 AssertEquals ("Capacity-Resetted" + i.ToString (), 16, sl.Capacity);
\r
324 public void Clear_Capacity_Reset ()
\r
326 SortedList sl = new SortedList (0);
\r
327 AssertEquals ("0", 0, sl.Capacity);
\r
329 // reset to class default (16)
\r
330 AssertEquals ("Clear", 16, sl.Capacity);
\r
332 AssertEquals ("Capacity", 16, sl.Capacity);
\r
333 // note: we didn't return to 0 - so Clear cahnge the default capacity
\r
337 public void TestClone() {
\r
339 SortedList sl1 = new SortedList(10);
\r
340 for (int i = 0; i <= 50; i++) {sl1.Add("kala "+i,i);}
\r
341 SortedList sl2 = (SortedList)sl1.Clone();
\r
342 for (int i = 0; i <= 50; i++) {
\r
343 AssertEquals("sl.Clone: copying failed @"+i, sl1["kala "+i], sl2["kala "+i]);
\r
347 char[] d10 = {'a', 'b'};
\r
348 char[] d11 = {'a', 'c'};
\r
349 char[] d12 = {'b', 'c'};
\r
350 //char[][] d1 = {d10, d11, d12};
\r
351 SortedList sl1 = new SortedList();
\r
355 SortedList sl2 = (SortedList)sl1.Clone();
\r
356 AssertEquals("sl.Clone: Array not matching", sl1["d1"], sl2["d1"]);
\r
357 AssertEquals("sl.Clone: Array not matching", sl1["d2"], sl2["d2"]);
\r
358 AssertEquals("sl.Clone: Array not matching", sl1["d3"], sl2["d3"]);
\r
360 ((char[])sl1["d1"])[0] = 'z';
\r
361 AssertEquals("s1.Clone: shallow copy", sl1["d1"], sl2["d1"]);
\r
366 public void TestContains() {
\r
367 SortedList sl1 = new SortedList(55);
\r
368 for (int i = 0; i <= 50; i++) {sl1.Add("kala "+i,i);}
\r
371 if (sl1.Contains(null)){}
\r
372 Fail ("sl.Contains: does not throw ArgumentNullException with null key");
\r
373 } catch (ArgumentNullException) {}
\r
375 Assert("sl.Contains: can't find existing key", sl1.Contains("kala 17"));
\r
376 Assert("sl.Contains: finds non-existing key", !sl1.Contains("ohoo"));
\r
380 public void TestContainsKey() {
\r
381 SortedList sl1 = new SortedList(55);
\r
382 for (int i = 0; i <= 50; i++) {sl1.Add("kala "+i,i);}
\r
385 if (sl1.ContainsKey(null)){}
\r
386 Fail ("sl.ContainsKey: does not throw ArgumentNullException with null key");
\r
387 } catch (ArgumentNullException) {}
\r
389 Assert("sl.ContainsKey: can't find existing key", sl1.ContainsKey("kala 17"));
\r
390 Assert("sl.ContainsKey: finds non-existing key", !sl1.ContainsKey("ohoo"));
\r
394 public void TestContainsValue() {
\r
395 SortedList sl1 = new SortedList(55);
\r
396 sl1.Add(0, "zero");
\r
399 sl1.Add(3, "three");
\r
400 sl1.Add(4, "four");
\r
402 Assert("sl.ContainsValue: can't find existing value", sl1.ContainsValue("zero"));
\r
403 Assert("sl.ContainsValue: finds non-existing value", !sl1.ContainsValue("ohoo"));
\r
404 Assert("sl.ContainsValue: finds non-existing value", !sl1.ContainsValue(null));
\r
408 public void TestCopyTo() {
\r
409 SortedList sl1 = new SortedList();
\r
410 for (int i = 0; i <= 10; i++) {sl1.Add("kala "+i,i);}
\r
413 sl1.CopyTo(null, 2);
\r
414 Fail("sl.CopyTo: does not throw ArgumentNullException when target null");
\r
415 } catch (ArgumentNullException) {}
\r
419 Char[,] c2 = new Char[2,2];
\r
421 Fail("sl.CopyTo: does not throw ArgumentException when target is multiarray");
\r
422 } catch (ArgumentException) {}
\r
426 Char[] c1 = new Char[2];
\r
427 sl1.CopyTo(c1, -2);
\r
428 Fail("sl.CopyTo: does not throw ArgumentOutOfRangeException when index is negative");
\r
429 } catch (ArgumentOutOfRangeException) {}
\r
433 Char[] c1 = new Char[2];
\r
435 Fail("sl.CopyTo: does not throw ArgumentException when index is too large");
\r
436 } catch (ArgumentException) {}
\r
440 Char[] c1 = new Char[2];
\r
442 Fail("sl.CopyTo: does not throw ArgumentException when SortedList too big for the array");
\r
443 } catch (ArgumentException) {}
\r
447 Char[] c2 = new Char[15];
\r
449 Fail("sl.CopyTo: does not throw InvalidCastException when incompatible data types");
\r
450 } catch (InvalidCastException) {}
\r
453 // CopyTo function does not work well with SortedList
\r
454 // even example at MSDN gave InvalidCastException
\r
455 // thus, it is NOT tested here
\r
458 for (int i = 0; i <= 5; i++) {sl1.Add(i,""+i);}
\r
459 Char[] copy = new Char[15];
\r
460 Array.Clear(copy,0,copy.Length);
\r
461 copy.SetValue( "The", 0 );
\r
462 copy.SetValue( "quick", 1 );
\r
463 copy.SetValue( "brown", 2 );
\r
464 copy.SetValue( "fox", 3 );
\r
465 copy.SetValue( "jumped", 4 );
\r
466 copy.SetValue( "over", 5 );
\r
467 copy.SetValue( "the", 6 );
\r
468 copy.SetValue( "lazy", 7 );
\r
469 copy.SetValue( "dog", 8 );
\r
470 sl1.CopyTo(copy,1);
\r
471 AssertEquals("sl.CopyTo: incorrect copy(1).","The", copy.GetValue(0));
\r
472 AssertEquals("sl.CopyTo: incorrect copy(1).","quick", copy.GetValue(1));
\r
473 for (int i=2; i<8; i++) AssertEquals("sl.CopyTo: incorrect copy(2).",sl1["kala "+(i-2)], copy.GetValue(i));
\r
474 AssertEquals("sl.CopyTo: incorrect copy(3).","dog", copy.GetValue(8));
\r
478 public SortedList DefaultSL() {
\r
479 SortedList sl1 = new SortedList();
\r
480 sl1.Add( 1.0, "The" );
\r
481 sl1.Add( 1.1, "quick" );
\r
482 sl1.Add( 34.0, "brown" );
\r
483 sl1.Add( -100.75, "fox" );
\r
484 sl1.Add( 1.4, "jumped" );
\r
485 sl1.Add( 1.5, "over" );
\r
486 sl1.Add( 1.6, "the" );
\r
487 sl1.Add( 1.7, "lazy" );
\r
488 sl1.Add( 1.8, "dog" );
\r
492 public IList DefaultValues() {
\r
493 IList il = new ArrayList();
\r
497 il.Add( "jumped" );
\r
507 public void TestGetByIndex() {
\r
508 SortedList sl1 = DefaultSL();
\r
509 AssertEquals("cl.GetByIndex: failed(1)",sl1.GetByIndex(4),"over");
\r
510 AssertEquals("cl.GetByIndex: failed(2)",sl1.GetByIndex(8),"brown");
\r
512 sl1.GetByIndex(-1);
\r
513 Fail("sl.GetByIndex: does not throw ArgumentOutOfRangeException with negative index");
\r
514 } catch (ArgumentOutOfRangeException) {}
\r
516 sl1.GetByIndex(100);
\r
517 Fail("sl.GetByIndex: does not throw ArgumentOutOfRangeException with too large index");
\r
518 } catch (ArgumentOutOfRangeException) {}
\r
522 public void GetEnumerator ()
\r
524 SortedList sl1 = DefaultSL();
\r
525 IDictionaryEnumerator e = sl1.GetEnumerator();
\r
526 AssertNotNull("sl.GetEnumerator: does not return enumerator", e);
\r
527 AssertEquals("sl.GetEnumerator: enumerator not working(1)",e.MoveNext(),true);
\r
528 AssertNotNull("sl.GetEnumerator: enumerator not working(2)",e.Current);
\r
530 Assert ("ICloneable", (e is ICloneable));
\r
531 Assert ("IDictionaryEnumerator", (e is ICloneable));
\r
532 Assert ("IEnumerator", (e is ICloneable));
\r
536 public void TestGetKey() {
\r
537 SortedList sl1 = DefaultSL();
\r
538 AssertEquals("sl.GetKey: failed(1)",sl1.GetKey(4),1.5);
\r
539 AssertEquals("sl.GetKey: failed(2)",sl1.GetKey(8),34.0);
\r
542 Fail("sl.GetKey: does not throw ArgumentOutOfRangeException with negative index");
\r
543 } catch (ArgumentOutOfRangeException) {}
\r
546 Fail("sl.GetKey: does not throw ArgumentOutOfRangeException with too large index");
\r
547 } catch (ArgumentOutOfRangeException) {}
\r
551 public void TestGetKeyList() {
\r
552 SortedList sl1 = DefaultSL();
\r
553 IList keys = sl1.GetKeyList();
\r
554 AssertNotNull("sl.GetKeyList: does not return keylist", keys);
\r
555 Assert("sl.GetKeyList: keylist is not readonly", keys.IsReadOnly);
\r
556 AssertEquals("sl.GetKeyList: incorrect keylist size",keys.Count,9);
\r
557 AssertEquals("sl.GetKeyList: incorrect key(1)",keys[3],1.4);
\r
558 sl1.Add(33.9,"ehhe");
\r
559 AssertEquals("sl.GetKeyList: incorrect keylist size",keys.Count,10);
\r
560 AssertEquals("sl.GetKeyList: incorrect key(2)",keys[8],33.9);
\r
564 public void TestGetValueList() {
\r
565 SortedList sl1 = DefaultSL();
\r
566 IList originalvals = DefaultValues();
\r
567 IList vals = sl1.GetValueList();
\r
568 AssertNotNull("sl.GetValueList: does not return valuelist", vals);
\r
569 Assert("sl.GetValueList: valuelist is not readonly", vals.IsReadOnly);
\r
570 AssertEquals("sl.GetValueList: incorrect valuelist size",vals.Count,sl1.Count);
\r
571 for (int i=0; i<sl1.Count; i++) {
\r
572 AssertEquals("sl.GetValueList: incorrect key(1)",vals[i],originalvals[i]);
\r
575 sl1.Add(0.01,"ehhe");
\r
576 AssertEquals("sl.GetValueList: incorrect valuelist size",vals.Count,10);
\r
577 AssertEquals("sl.GetValueList: incorrect value(2)",vals[8],"dog");
\r
580 // TODO: IEnumerable.GetEnumerator [Explicit Interface Implementation]
\r
582 public void TestIEnumerable_GetEnumerator() {
\r
583 SortedList sl1 = DefaultSL();
\r
584 IEnumerator e = sl1.IEnumerable.GetEnumerator();
\r
585 AssertNotNull("sl.GetEnumerator: does not return enumerator", e);
\r
586 AssertEquals("sl.GetEnumerator: enumerator not working(1)",e.MoveNext(),true);
\r
587 AssertNotNull("sl.GetEnumerator: enumerator not working(2)",e.Current);
\r
592 public void TestIndexOfKey() {
\r
593 SortedList sl1 = new SortedList(24);
\r
596 for (int i = 0; i <= 50; i++) {
\r
597 s=string.Format("{0:D2}", i);
\r
598 sl1.Add("kala "+s,i);
\r
600 AssertEquals("sl.IndexOfKey: does not return -1 for non-existing key", -1, sl1.IndexOfKey("kala "));
\r
603 t=sl1.IndexOfKey(s);
\r
604 Fail("sl.IndexOfKey: ArgumentNullException not caught, when key is null");
\r
606 catch (ArgumentNullException) {}
\r
608 t=sl1.IndexOfKey(10);
\r
609 Fail("sl.IndexOfKey: InvalidOperationException not caught, when key invalid");
\r
611 catch (InvalidOperationException) {}
\r
612 for (int i=0; i<=50; i++) {
\r
613 s=string.Format("{0:D2}", i);
\r
614 AssertEquals("sl.IndexOfKey: incorrect index key", i, sl1.IndexOfKey("kala "+s));
\r
619 public void TestIndexOfValue() {
\r
620 SortedList sl1 = new SortedList(24);
\r
622 for (int i = 0; i < 50; i++) {
\r
623 s=string.Format("{0:D2}", i);
\r
624 sl1.Add("kala "+s,100+i*i);
\r
626 for (int i = 0; i < 50; i++) {
\r
627 s=string.Format("{0:D2}", i+50);
\r
628 sl1.Add("kala "+s,100+i*i);
\r
630 AssertEquals("sl.IndexOfValue: does not return -1 for non-existing value(1)", -1, sl1.IndexOfValue(102));
\r
631 AssertEquals("sl.IndexOfValue: does not return -1 for non-existing value(2)", -1, sl1.IndexOfValue(null));
\r
632 for (int i=0; i<50; i++) {
\r
633 AssertEquals("sl.IndexOfValue: incorrect index key", i, sl1.IndexOfValue(100+i*i));
\r
638 public void TestIndexOfValue2 ()
\r
640 SortedList list = new SortedList ();
\r
641 list.Add ("key0", "la la");
\r
642 list.Add ("key1", "value");
\r
643 list.Add ("key2", "value");
\r
645 int i = list.IndexOfValue ("value");
\r
647 AssertEquals (1, i);
\r
651 public void TestIndexOfValue3 ()
\r
653 SortedList list = new SortedList ();
\r
654 int i = list.IndexOfValue ((string) null);
\r
656 AssertEquals (1, -i);
\r
660 public void TestIndexer ()
\r
662 SortedList list = new SortedList ();
\r
664 list.Add (1, new Queue ());
\r
665 list.Add (2, new Hashtable ());
\r
666 list.Add (3, new Stack ());
\r
668 AssertEquals (typeof (Queue), list [1].GetType ());
\r
669 AssertEquals (typeof (Hashtable), list [2].GetType ());
\r
670 AssertEquals (typeof (Stack), list [3].GetType ());
\r
674 public void TestEnumerator ()
\r
676 SortedList list = new SortedList ();
\r
678 list.Add (1, new Queue ());
\r
679 list.Add (2, new Hashtable ());
\r
680 list.Add (3, new Stack ());
\r
682 foreach (DictionaryEntry d in list) {
\r
684 int key = (int) d.Key;
\r
685 Type value = d.Value.GetType ();
\r
689 AssertEquals (typeof (Queue), value);
\r
693 AssertEquals (typeof (Hashtable), value);
\r
697 AssertEquals (typeof (Stack), value);
\r
701 Fail ("This is incorrect: " + value.FullName);
\r
708 public void TestRemove() {
\r
709 SortedList sl1 = new SortedList(24);
\r
712 for (int i = 0; i < 50; i++) sl1.Add("kala "+i,i);
\r
716 Fail("sl.Remove: ArgumentNullException not caught, when key is null");
\r
717 } catch (ArgumentNullException) {}
\r
719 sl1.Remove("kala ");
\r
720 AssertEquals("sl.Remove: removes an item, when non-existing key given",sl1.Count,k);
\r
723 Fail("sl.Remove: IComparer exception is not thrown");
\r
724 } catch (Exception) {}
\r
726 for (int i=15; i<20; i++) sl1.Remove("kala "+i);
\r
727 for (int i=45; i<55; i++) sl1.Remove("kala "+i);
\r
729 AssertEquals("sl.Remove: removing failed",sl1.Count,40);
\r
730 for (int i=45; i<55; i++)
\r
731 AssertEquals("sl.Remove: removing failed(2)",sl1["kala "+i],null);
\r
735 public void TestRemoveAt() {
\r
736 SortedList sl1 = new SortedList(24);
\r
739 for (int i = 0; i < 50; i++) {
\r
740 s=string.Format("{0:D2}", i);
\r
741 sl1.Add("kala "+s,i);
\r
746 Fail("sl.RemoveAt: ArgumentOutOfRangeException not caught, when key is out of range");
\r
747 } catch (ArgumentOutOfRangeException) {}
\r
750 Fail("sl.RemoveAt: ArgumentOutOfRangeException not caught, when key is out of range");
\r
751 } catch (ArgumentOutOfRangeException) {}
\r
754 for (int i=0; i<20; i++) sl1.RemoveAt(9);
\r
756 AssertEquals("sl.RemoveAt: removing failed",sl1.Count,30);
\r
757 for (int i=0; i<9; i++)
\r
758 AssertEquals("sl.RemoveAt: removing failed(2)",sl1["kala "+string.Format("{0:D2}", i)],i);
\r
759 for (int i=9; i<29; i++)
\r
760 AssertEquals("sl.RemoveAt: removing failed(3)",sl1["kala "+string.Format("{0:D2}", i)],null);
\r
761 for (int i=29; i<50; i++)
\r
762 AssertEquals("sl.RemoveAt: removing failed(4)",sl1["kala "+string.Format("{0:D2}", i)],i);
\r
766 public void TestSetByIndex() {
\r
767 SortedList sl1 = new SortedList(24);
\r
768 for (int i = 49; i>=0; i--) sl1.Add(100+i,i);
\r
771 sl1.SetByIndex(-1,77);
\r
772 Fail("sl.SetByIndex: ArgumentOutOfRangeException not caught, when key is out of range");
\r
773 } catch (ArgumentOutOfRangeException) {}
\r
775 sl1.SetByIndex(100,88);
\r
776 Fail("sl.SetByIndex: ArgumentOutOfRangeException not caught, when key is out of range");
\r
777 } catch (ArgumentOutOfRangeException) {}
\r
779 for(int i=5; i<25; i++) sl1.SetByIndex(i,-1);
\r
780 for(int i=0; i<5; i++)
\r
781 AssertEquals("sl.SetByIndex: set failed(1)",sl1[100+i],i);
\r
782 for(int i=5; i<25; i++)
\r
783 AssertEquals("sl.SetByIndex: set failed(2)",sl1[100+i],-1);
\r
784 for(int i=25; i<50; i++)
\r
785 AssertEquals("sl.SetByIndex: set failed(3)",sl1[100+i],i);
\r
790 public void TestTrimToSize() {
\r
791 SortedList sl1 = new SortedList(24);
\r
794 AssertEquals("sl.TrimToSize: incorrect capacity after trimming empty list",icap,sl1.Capacity);
\r
796 for (int i = 72; i>=0; i--) sl1.Add(100+i,i);
\r
798 AssertEquals("sl.TrimToSize: incorrect capacity after trimming a list",73,sl1.Capacity);
\r