Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SortedListTest.cs « System.Collections « Test « corlib « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 71668a28873dab42b953fc61c1a29ce09cd7a901 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
// SortedListTest.cs - NUnit Test Cases for the System.Collections.SortedList class
//
// Jaak Simm
//
// Thanks go to David Brandt (bucky@keystreams.com),
// because this file is based on his ArrayListTest.cs
//
// (C) Ximian, Inc.  http://www.ximian.com
// 
// main TODO: additional tests for functions affected by
//            fixedsize and read-only properties 


using System;
using System.Collections;

using NUnit.Framework;


namespace MonoTests.System.Collections {


/// <summary>SortedList test.</summary>
public class SortedListTest : TestCase {
	public SortedListTest() : base ("MonoTests.System.SortedListTest testsuite") {}
	public SortedListTest(string name) : base(name) {}

	protected SortedList sl1;
	protected SortedList sl2;
	protected SortedList emptysl;
	protected const int icap=16;
		
	protected override void SetUp() 
	{
	}

	protected override void TearDown() 
	{
	}

	public static ITest Suite {
		get { 
			return new TestSuite(typeof(SortedListTest)); 
		}
	}
	
	public void TestConstructor1() {
		SortedList temp1 = new SortedList();
		AssertNotNull("sl.constructor-1: returns null", temp1);
		AssertEquals("sl.constructor-1: incorrect initial capacity", temp1.Capacity, icap);
	}
	
	public void TestConstructor2() {
		Comparer c = Comparer.Default;
		SortedList temp1 = new SortedList(c);
		AssertNotNull("sl.constructor-2: returns null", temp1);
		AssertEquals("sl.constructor-2: incorrect initial capacity", temp1.Capacity, icap);
	}

	public void TestConstructor3() {
		Hashtable d = new Hashtable();
		d.Add("one", "Mircosoft");
		d.Add("two", "will");
		d.Add("three", "rule");
		d.Add("four", "the world");
		
		SortedList temp1 = new SortedList(d);
		AssertNotNull("sl.constructor-3: returns null", temp1);
		AssertEquals("sl.constructor-3: incorrect initial capacity", temp1.Capacity, 4);
		AssertEquals("sl.constructor-3: incorrect count", temp1.Count, 4);

		try {
			d=null;
			temp1 = new SortedList(d);
			Fail ("sl.constructor-3: does not throw ArgumentNullException");
		} catch (ArgumentNullException) {}
		try {
			d = new Hashtable();
			d.Add("one", "Mircosoft");
			d.Add("two", "will");
			d.Add("three", "rule");
			d.Add("four", "the world");
			d.Add(7987,"lkj");
			temp1 = new SortedList(d);
			Fail ("sl.constructor-3: does not throw InvalidCastException");
		} catch (InvalidOperationException) {
		} catch (Exception e) {
			Fail ("Unexpected Exception throw: e=" + e);
		}
	}
	
	public void TestConstructor4() {
		SortedList temp1 = new SortedList(17);
		AssertNotNull("sl.constructor-4: returns null", temp1);
		AssertEquals("sl.constructor-4: incorrect initial capacity", temp1.Capacity, 17);
		try {
			temp1 = new SortedList(-6);
			Fail ("sl.constructor-4: does not throw ArgumentOutOfRangeException, with negative values");
		} catch (ArgumentOutOfRangeException) {}
		try {
			temp1 = new SortedList(0);
		} catch (ArgumentOutOfRangeException) {
			Fail ("sl.constructor-4: throws ArgumentOutOfRangeException with 0");
		}
	}

	public void TestConstructor5() {
		Comparer c = Comparer.Default;
		SortedList temp1 = new SortedList(c,27);
		AssertNotNull("sl.constructor-5: returns null", temp1);
		AssertEquals("sl.constructor-5: incorrect initial capacity", temp1.Capacity, 27);
		try {
			temp1 = new SortedList(-12);
			Fail ("sl.constructor-5: does not throw ArgumentOutOfRangeException, with negative values");
		} catch (ArgumentOutOfRangeException) {}
	}

	public void TestIsSynchronized() {
		SortedList sl1 = new SortedList();
		Assert("sl: should not be synchronized by default", 
		       !sl1.IsSynchronized);
		SortedList sl2 = SortedList.Synchronized(sl1);
		Assert("sl: synchronized wrapper not working", sl2.IsSynchronized);
	}

	public void TestCapacity() {
		for (int i = 0; i < 100; i++) {
			SortedList sl1 = new SortedList(i);
			AssertEquals("Bad capacity of " + i,
				     i, sl1.Capacity);
		}
	}

	public void TestCount() {
		{
			SortedList sl1 = new SortedList();
			AssertEquals("Bad initial count",
				     0, sl1.Count);
			for (int i = 1; i <= 100; i++) {
				sl1.Add(""+i,""+i);
				AssertEquals("Bad count " + i,
					     i, sl1.Count);
			}
		}
	}

	public void TestIsFixed() {
		SortedList sl1 = new SortedList();
		Assert("should not be fixed by default", !sl1.IsFixedSize);
	}

	public void TestIsReadOnly() {
		SortedList sl1 = new SortedList();
		Assert("should not be ReadOnly by default", !sl1.IsReadOnly);
	}


	public void TestItem() {
		SortedList sl1 = new SortedList();
		string key = null;
		{
			try {
				object o = sl1[-1];
			} catch (ArgumentNullException) {
				Fail ("sl.Item: throws ArgumentNullException with negative values");
			}
			try {
				object o = sl1[key];
				Fail ("sl.Item: does not throw ArgumentNullException with null key");
			} catch (ArgumentNullException) {}
		}

		for (int i = 0; i <= 100; i++) {
			sl1.Add("kala "+i,i);
		}
		for (int i = 0; i <= 100; i++) {
			AssertEquals("sl.Item: item not fetched for " + i,
				     i, sl1["kala "+i]);
		}
	}

  public void TestSyncRoot()
  {
  	SortedList sl1 = new SortedList();
		AssertEquals("sl.SyncRoot: does not function",false, sl1.SyncRoot == null);
		/*
		lock( sl1.SyncRoot ) {
			foreach ( Object item in sl1 ) {
				item="asdf";
				Assert ("sl.SyncRoot: item not read-only",item.IsReadOnly);
 			}
		}
		*/
  }

	public void TestValues()
	{
  	SortedList sl1 = new SortedList();
		ICollection ic1 = sl1.Values;
		for (int i = 0; i <= 100; i++) {
			sl1.Add("kala "+i,i);
			AssertEquals("sl.Values: .Values has different count",ic1.Count,sl1.Count);
		}
	}
	
	
	// TODO: Add with IComparer
	public void TestAdd() {
		// seems SortedList cannot be set fixedsize or readonly
		SortedList sl1 = new SortedList();
		string key = null;
		{
			try {
				sl1.Add(key,"kala");
				Fail ("sl.Add: does not throw ArgumentNullException with null key");
			} catch (ArgumentNullException) {}
		}

		{
			for (int i = 1; i <= 100; i++) {
				sl1.Add("kala "+i,i);
				AssertEquals("sl.Add: incorrect count",i,sl1.Count);
				AssertEquals("sl.Add: incorrect value",i,sl1["kala "+i]);
			}
		}
		{
			try {
				sl1.Add("kala",10);
				sl1.Add("kala",11);
				Fail ("sl.Add: does not throw ArgumentException when adding existing key");
			} catch (ArgumentException) {}
		}
	}
	
	
	public void TestClear() {
		{
			SortedList sl1 = new SortedList(10);
			sl1.Add("kala",'c');
			sl1.Add("kala2",'d');
			AssertEquals("sl.Clear: capacity is incorrect",10, sl1.Capacity);
			AssertEquals("sl.Clear: should have one element",	2, sl1.Count);
			sl1.Clear();
			AssertEquals("sl.Clear: is not cleared",0, sl1.Count);
			AssertEquals("sl.Clear: capacity is altered",16, sl1.Capacity);
		}
	}

	public void TestClone() {
		{
			SortedList sl1 = new SortedList(10);
			for (int i = 0; i <= 50; i++) {sl1.Add("kala "+i,i);}
			SortedList sl2 = (SortedList)sl1.Clone();
			for (int i = 0; i <= 50; i++) {
				AssertEquals("sl.Clone: copying failed @"+i, sl1["kala "+i], sl2["kala "+i]);
			}
		}
		{
			char[] d10 = {'a', 'b'};
			char[] d11 = {'a', 'c'};
			char[] d12 = {'b', 'c'};
			//char[][] d1 = {d10, d11, d12};
			SortedList sl1 = new SortedList();
			sl1.Add("d1",d10);
			sl1.Add("d2",d11);
			sl1.Add("d3",d12);
			SortedList sl2 = (SortedList)sl1.Clone();
			AssertEquals("sl.Clone: Array not matching", sl1["d1"], sl2["d1"]);
			AssertEquals("sl.Clone: Array not matching", sl1["d2"], sl2["d2"]);
			AssertEquals("sl.Clone: Array not matching", sl1["d3"], sl2["d3"]);
			
			((char[])sl1["d1"])[0] = 'z';
			AssertEquals("s1.Clone: shallow copy", sl1["d1"], sl2["d1"]);
		}
	}

	public void TestContains() {
		SortedList sl1 = new SortedList(55);
		for (int i = 0; i <= 50; i++) {sl1.Add("kala "+i,i);}

		try {
			if (sl1.Contains(null)){}
			Fail ("sl.Contains: does not throw ArgumentNullException with null key");
		} catch (ArgumentNullException) {}
		
		Assert("sl.Contains: can't find existing key", sl1.Contains("kala 17"));
		Assert("sl.Contains: finds non-existing key", !sl1.Contains("ohoo"));
	}

	public void TestContainsKey() {
		SortedList sl1 = new SortedList(55);
		for (int i = 0; i <= 50; i++) {sl1.Add("kala "+i,i);}

		try {
			if (sl1.ContainsKey(null)){}
			Fail ("sl.ContainsKey: does not throw ArgumentNullException with null key");
		} catch (ArgumentNullException) {}
		
		Assert("sl.ContainsKey: can't find existing key", sl1.ContainsKey("kala 17"));
		Assert("sl.ContainsKey: finds non-existing key", !sl1.ContainsKey("ohoo"));
	}

	public void TestContainsValue() {
		SortedList sl1 = new SortedList(55);
    sl1.Add(0, "zero");
    sl1.Add(1, "one");
    sl1.Add(2, "two");
    sl1.Add(3, "three");
    sl1.Add(4, "four");
		Assert("sl.ContainsValue: can't find existing value", sl1.ContainsValue("zero"));
		Assert("sl.ContainsValue: finds non-existing value", !sl1.ContainsValue("ohoo"));
		Assert("sl.ContainsValue: finds non-existing value", !sl1.ContainsValue(null));
	}
	
	public void TestCopyTo() {
		SortedList sl1 = new SortedList();
		for (int i = 0; i <= 10; i++) {sl1.Add("kala "+i,i);}
		{
			try {
				sl1.CopyTo(null, 2);
				Fail("sl.CopyTo: does not throw ArgumentNullException when target null");
			} catch (ArgumentNullException) {}
		}
		{
			try {
				Char[,] c2 = new Char[2,2];
				sl1.CopyTo(c2, 2);
				Fail("sl.CopyTo: does not throw ArgumentException when target is multiarray");
			} catch (ArgumentException) {}
		}
		{
			try {
				Char[] c1 = new Char[2];
				sl1.CopyTo(c1, -2);
				Fail("sl.CopyTo: does not throw ArgumentOutOfRangeException when index is negative");
			} catch (ArgumentOutOfRangeException) {}
		}
		{
			try {
				Char[] c1 = new Char[2];
				sl1.CopyTo(c1, 3);
				Fail("sl.CopyTo: does not throw ArgumentException when index is too large");
			} catch (ArgumentException) {}
		}
		{
			try {
				Char[] c1 = new Char[2];
				sl1.CopyTo(c1, 1);
				Fail("sl.CopyTo: does not throw ArgumentException when SortedList too big for the array");
			} catch (ArgumentException) {}
		}
		{
			try {
				Char[] c2 = new Char[15];
				sl1.CopyTo(c2, 0);
				Fail("sl.CopyTo: does not throw InvalidCastException when incompatible data types");
			} catch (InvalidCastException) {}
		}

		// CopyTo function does not work well with SortedList
		// even example at MSDN gave InvalidCastException
		// thus, it is NOT testet here
		/*
				sl1.Clear();
				for (int i = 0; i <= 5; i++) {sl1.Add(i,""+i);}
		    Char[] copy = new Char[15];
		    Array.Clear(copy,0,copy.Length);
		    copy.SetValue( "The", 0 );
		    copy.SetValue( "quick", 1 );
		    copy.SetValue( "brown", 2 );
		    copy.SetValue( "fox", 3 );
		    copy.SetValue( "jumped", 4 );
		    copy.SetValue( "over", 5 );
		    copy.SetValue( "the", 6 );
		    copy.SetValue( "lazy", 7 );
		    copy.SetValue( "dog", 8 );
				sl1.CopyTo(copy,1);
				AssertEquals("sl.CopyTo: incorrect copy(1).","The", copy.GetValue(0));
				AssertEquals("sl.CopyTo: incorrect copy(1).","quick", copy.GetValue(1));
				for (int i=2; i<8; i++) AssertEquals("sl.CopyTo: incorrect copy(2).",sl1["kala "+(i-2)], copy.GetValue(i));
				AssertEquals("sl.CopyTo: incorrect copy(3).","dog", copy.GetValue(8));
		*/
	}

	public SortedList DefaultSL() {
		SortedList sl1 = new SortedList();
		sl1.Add( 1.0, "The" );
		sl1.Add( 1.1, "quick" );
		sl1.Add( 34.0, "brown" );
		sl1.Add( -100.75, "fox" );
		sl1.Add( 1.4, "jumped" );
		sl1.Add( 1.5, "over" );
		sl1.Add( 1.6, "the" );
		sl1.Add( 1.7, "lazy" );
		sl1.Add( 1.8, "dog" );
		return sl1;
	}
	
	public IList DefaultValues() {
		IList il = new ArrayList();
		il.Add( "fox" );
		il.Add( "The" );
		il.Add( "quick" );
		il.Add( "jumped" );
		il.Add( "over" );
		il.Add( "the" );
		il.Add( "lazy" );
		il.Add( "dog" );
		il.Add( "brown" );
		return il;
	}
	
	public void TestGetByIndex() {
		SortedList sl1 = DefaultSL();
		AssertEquals("cl.GetByIndex: failed(1)",sl1.GetByIndex(4),"over");
		AssertEquals("cl.GetByIndex: failed(2)",sl1.GetByIndex(8),"brown");
		try {
			sl1.GetByIndex(-1);
			Fail("sl.GetByIndex: does not throw ArgumentOutOfRangeException with negative index");
		} catch (ArgumentOutOfRangeException) {}
		try {
			sl1.GetByIndex(100);
			Fail("sl.GetByIndex: does not throw ArgumentOutOfRangeException with too large index");
		} catch (ArgumentOutOfRangeException) {}
	}

	public void TestGetEnumerator() {
		SortedList sl1 = DefaultSL();
		IDictionaryEnumerator e = sl1.GetEnumerator();
		AssertNotNull("sl.GetEnumerator: does not return enumerator", e);
		AssertEquals("sl.GetEnumerator: enumerator not working(1)",e.MoveNext(),true);
		AssertNotNull("sl.GetEnumerator: enumerator not working(2)",e.Current);
	}

	public void TestGetKey() {
		SortedList sl1 = DefaultSL();
		AssertEquals("sl.GetKey: failed(1)",sl1.GetKey(4),1.5);
		AssertEquals("sl.GetKey: failed(2)",sl1.GetKey(8),34.0);
		try {
			sl1.GetKey(-1);
			Fail("sl.GetKey: does not throw ArgumentOutOfRangeException with negative index");
		} catch (ArgumentOutOfRangeException) {}
		try {
			sl1.GetKey(100);
			Fail("sl.GetKey: does not throw ArgumentOutOfRangeException with too large index");
		} catch (ArgumentOutOfRangeException) {}
	}

	public void TestGetKeyList() {
		SortedList sl1 = DefaultSL();
		IList keys = sl1.GetKeyList();
		AssertNotNull("sl.GetKeyList: does not return keylist", keys);
		Assert("sl.GetKeyList: keylist is not readonly", keys.IsReadOnly);
		AssertEquals("sl.GetKeyList: incorrect keylist size",keys.Count,9);
		AssertEquals("sl.GetKeyList: incorrect key(1)",keys[3],1.4);
		sl1.Add(33.9,"ehhe");
		AssertEquals("sl.GetKeyList: incorrect keylist size",keys.Count,10);
		AssertEquals("sl.GetKeyList: incorrect key(2)",keys[8],33.9);
	}

	public void TestGetValueList() {
		SortedList sl1 = DefaultSL();
		IList originalvals = DefaultValues();
		IList vals = sl1.GetValueList();
		AssertNotNull("sl.GetValueList: does not return valuelist", vals);
		Assert("sl.GetValueList: valuelist is not readonly", vals.IsReadOnly);
		AssertEquals("sl.GetValueList: incorrect valuelist size",vals.Count,sl1.Count);
		for (int i=0; i<sl1.Count; i++) {
			AssertEquals("sl.GetValueList: incorrect key(1)",vals[i],originalvals[i]);
		}

		sl1.Add(0.01,"ehhe");
		AssertEquals("sl.GetValueList: incorrect valuelist size",vals.Count,10);
		AssertEquals("sl.GetValueList: incorrect value(2)",vals[8],"dog");
	}

	// TODO: IEnumerable.GetEnumerator [Explicit Interface Implementation]
	/*
	public void TestIEnumerable_GetEnumerator() {
		SortedList sl1 = DefaultSL();
		IEnumerator e = sl1.IEnumerable.GetEnumerator();
		AssertNotNull("sl.GetEnumerator: does not return enumerator", e);
		AssertEquals("sl.GetEnumerator: enumerator not working(1)",e.MoveNext(),true);
		AssertNotNull("sl.GetEnumerator: enumerator not working(2)",e.Current);
	}
	*/

	public void TestIndexOfKey() {
		SortedList sl1 = new SortedList(24);
		string s=null;
		int t;
		for (int i = 0; i <= 50; i++) {
			s=string.Format("{0:D2}", i); 
			sl1.Add("kala "+s,i);
		}
		AssertEquals("sl.IndexOfKey: does not return -1 for non-existing key",sl1.IndexOfKey("kala "),-1);
		s=null;
		try {
			t=sl1.IndexOfKey(s);
			Fail("sl.IndexOfKey: ArgumentNullException not caught, when key is null");
		}
		catch (ArgumentNullException) {}
		try {
			t=sl1.IndexOfKey(10);
			Fail("sl.IndexOfKey: InvalidOperationException not caught, when key invalid");
		}
		catch (InvalidOperationException) {}
		for (int i=0; i<=50; i++) {
			s=string.Format("{0:D2}", i); 
			AssertEquals("sl.IndexOfKey: incorrect index key",sl1.IndexOfKey("kala "+s),i);
		}
	}

	public void TestIndexOfValue() {
		SortedList sl1 = new SortedList(24);
		string s=null;
		for (int i = 0; i < 50; i++) {
			s=string.Format("{0:D2}", i); 
			sl1.Add("kala "+s,100+i*i);
		}
		for (int i = 0; i < 50; i++) {
			s=string.Format("{0:D2}", i+50); 
			sl1.Add("kala "+s,100+i*i);
		}
		AssertEquals("sl.IndexOfValue: does not return -1 for non-existing value(1)",sl1.IndexOfValue(102),-1);
		AssertEquals("sl.IndexOfValue: does not return -1 for non-existing value(2)",sl1.IndexOfValue(null),-1);
		for (int i=0; i<50; i++) {
			AssertEquals("sl.IndexOfValue: incorrect index key",sl1.IndexOfValue(100+i*i),i);
		}
	}
	

	public void TestRemove() {
		SortedList sl1 = new SortedList(24);
		string s=null;
		int k;
		for (int i = 0; i < 50; i++) sl1.Add("kala "+i,i);
		
		try {
			sl1.Remove(s);
			Fail("sl.Remove: ArgumentNullException not caught, when key is null");
		} catch (ArgumentNullException) {}
		k=sl1.Count;
		sl1.Remove("kala ");
		AssertEquals("sl.Remove: removes an item, when non-existing key given",sl1.Count,k);
		try {
			sl1.Remove(15);
			Fail("sl.Remove: IComparer exception is not thrown");
		} catch (Exception) {}

		for (int i=15; i<20; i++) sl1.Remove("kala "+i);
		for (int i=45; i<55; i++) sl1.Remove("kala "+i);
		
		AssertEquals("sl.Remove: removing failed",sl1.Count,40);
		for (int i=45; i<55; i++)
			AssertEquals("sl.Remove: removing failed(2)",sl1["kala "+i],null);
	}

	public void TestRemoveAt() {
		SortedList sl1 = new SortedList(24);
		int k;
		string s=null;
		for (int i = 0; i < 50; i++) {
			s=string.Format("{0:D2}", i); 
			sl1.Add("kala "+s,i);
		}
		
		try {
			sl1.RemoveAt(-1);
			Fail("sl.RemoveAt: ArgumentOutOfRangeException not caught, when key is out of range");
		} catch (ArgumentOutOfRangeException) {}
		try {
			sl1.RemoveAt(100);
			Fail("sl.RemoveAt: ArgumentOutOfRangeException not caught, when key is out of range");
		} catch (ArgumentOutOfRangeException) {}
		k=sl1.Count;

		for (int i=0; i<20; i++) sl1.RemoveAt(9);
		
		AssertEquals("sl.RemoveAt: removing failed",sl1.Count,30);
		for (int i=0; i<9; i++)
			AssertEquals("sl.RemoveAt: removing failed(2)",sl1["kala "+string.Format("{0:D2}", i)],i);
		for (int i=9; i<29; i++)
			AssertEquals("sl.RemoveAt: removing failed(3)",sl1["kala "+string.Format("{0:D2}", i)],null);
		for (int i=29; i<50; i++)
			AssertEquals("sl.RemoveAt: removing failed(4)",sl1["kala "+string.Format("{0:D2}", i)],i);
	}

	public void TestSetByIndex() {
		SortedList sl1 = new SortedList(24);
		for (int i = 49; i>=0; i--) sl1.Add(100+i,i);
		
		try {
			sl1.SetByIndex(-1,77);
			Fail("sl.SetByIndex: ArgumentOutOfRangeException not caught, when key is out of range");
		} catch (ArgumentOutOfRangeException) {}
		try {
			sl1.SetByIndex(100,88);
			Fail("sl.SetByIndex: ArgumentOutOfRangeException not caught, when key is out of range");
		} catch (ArgumentOutOfRangeException) {}

		for(int i=5; i<25; i++) sl1.SetByIndex(i,-1);
		for(int i=0; i<5; i++)
			AssertEquals("sl.SetByIndex: set failed(1)",sl1[100+i],i);
		for(int i=5; i<25; i++)
			AssertEquals("sl.SetByIndex: set failed(2)",sl1[100+i],-1);
		for(int i=25; i<50; i++)
			AssertEquals("sl.SetByIndex: set failed(3)",sl1[100+i],i);

	}

	public void TestTrimToSize() {
		SortedList sl1 = new SortedList(24);
		
		sl1.TrimToSize();
		AssertEquals("sl.TrimToSize: incorrect capacity after trimming empty list",icap,sl1.Capacity);
		
		for (int i = 72; i>=0; i--) sl1.Add(100+i,i);
		sl1.TrimToSize();
		AssertEquals("sl.TrimToSize: incorrect capacity after trimming a list",73,sl1.Capacity);
	}
}

}