mono /mcs/class/corlib/Test/System.Collections.Generic/ListTest.cs

Language C# Lines 1469
MD5 Hash 1f2d621dc5521e0bb22ee0ddc767c68a Estimated Cost $31,945 (why?)
Repository https://bitbucket.org/foobar22/mono.git View Raw File View Project SPDX
   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
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
//
// MonoTests.System.Collections.Generic.Test.ListTest
//
// Authors:
//      David Waite (mass@akuma.org)
//      Andres G. Aragoneses (andres.aragoneses@7digital.com)
//
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
// Copyright (C) 2005 David Waite (mass@akuma.org)
// Copyright 2011 Xamarin Inc (http://www.xamarin.com).
// Copyright 2012 7digital Ltd (http://www.7digital.com).
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#if NET_2_0

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;

using NUnit.Framework;

namespace MonoTests.System.Collections.Generic {

	class GenericComparer<T> : IComparer<T> {

		private bool called = false;

		public bool Called {
			get {
				bool result = called;
				called = false;
				return called;
			}
		}

		public int Compare (T x, T y)
		{
			called = true;
			return 0;
		}
	}

	[TestFixture]
	public class ListTest
	{
		static byte [] _serializedList = new byte [] {
			0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00,
			0x7e, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x43, 0x6f, 0x6c,
			0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x47, 0x65,
			0x6e, 0x65, 0x72, 0x69, 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x60,
			0x31, 0x5b, 0x5b, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x49,
			0x6e, 0x74, 0x33, 0x32, 0x2c, 0x20, 0x6d, 0x73, 0x63, 0x6f, 0x72,
			0x6c, 0x69, 0x62, 0x2c, 0x20, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f,
			0x6e, 0x3d, 0x32, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x2c, 0x20,
			0x43, 0x75, 0x6c, 0x74, 0x75, 0x72, 0x65, 0x3d, 0x6e, 0x65, 0x75,
			0x74, 0x72, 0x61, 0x6c, 0x2c, 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69,
			0x63, 0x4b, 0x65, 0x79, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x3d, 0x62,
			0x37, 0x37, 0x61, 0x35, 0x63, 0x35, 0x36, 0x31, 0x39, 0x33, 0x34,
			0x65, 0x30, 0x38, 0x39, 0x5d, 0x5d, 0x03, 0x00, 0x00, 0x00, 0x06,
			0x5f, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x05, 0x5f, 0x73, 0x69, 0x7a,
			0x65, 0x08, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x07,
			0x00, 0x00, 0x08, 0x08, 0x08, 0x09, 0x02, 0x00, 0x00, 0x00, 0x03,
			0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0f, 0x02, 0x00, 0x00,
			0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x0b };
		int [] _list1_contents;
		List <int> _list1;

		[SetUp]
		public void SetUp ()
		{
			// FIXME arrays currently do not support generic collection
			// interfaces
			_list1_contents = new int [] { 55, 50, 22, 80, 56, 52, 40, 63 };
			// _list1 = new List <int> (_list1_contents);
			
			_list1 = new List <int> (8);
			foreach (int i in _list1_contents)
				_list1.Add (i);
		}

		[Test]  // This was for bug #74980
		public void InsertTest ()
		{
			List <string> test = new List <string> ();
			test.Insert (0, "a");
			test.Insert (0, "b");
			test.Insert (1, "c");

			Assert.AreEqual (3, test.Count);
			Assert.AreEqual ("b", test [0]);
			Assert.AreEqual ("c", test [1]);
			Assert.AreEqual ("a", test [2]);
		}

		[Test]
		public void InsertRangeTest ()
		{
			int count = _list1.Count;
			// FIXME arrays currently do not support generic collection 
			// interfaces
			int [] items = {1, 2, 3};
			// List <int> newRange = new List <int> (items);
			List <int> newRange = new List <int> (3);
			foreach (int i in items)
				newRange.Add (i);
			_list1.InsertRange (1, newRange);
			Assert.AreEqual (count + 3, _list1.Count);
			Assert.AreEqual (55, _list1 [0]);
			Assert.AreEqual (1, _list1 [1]);
			Assert.AreEqual (2, _list1 [2]);
			Assert.AreEqual (3, _list1 [3]);
			Assert.AreEqual (50, _list1 [4]);

			newRange = new List <int> ();
			List <int> li = new List <int> ();
			li.Add (1);
			newRange.InsertRange (0, li);
			newRange.InsertRange (newRange.Count, li);
			Assert.AreEqual (2, newRange.Count);
		}
		
		[Test]
		public void InsertSelfTest()
		{
			List <int> range = new List <int> (5);
			for (int i = 0; i < 5; ++ i)
				range.Add (i);
			
			range.InsertRange(2, range);
			Assert.AreEqual (10, range.Count);
			Assert.AreEqual (0, range [0]);
			Assert.AreEqual (1, range [1]);
			Assert.AreEqual (0, range [2]);
			Assert.AreEqual (1, range [3]);
			Assert.AreEqual (2, range [4]);
			Assert.AreEqual (3, range [5]);
			Assert.AreEqual (4, range [6]);
			Assert.AreEqual (2, range [7]);
			Assert.AreEqual (3, range [8]);
			Assert.AreEqual (4, range [9]);
		}

		[Test, ExpectedException (typeof (ArgumentNullException))]
		public void InsertRangeNullTest ()
		{
			IEnumerable <int> n = null;
			_list1.InsertRange (0, n);
		}

		[Test, ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void InsertRangeNegativeIndexTest ()
		{
			_list1.InsertRange (-1, _list1);
		}

		[Test]
		public void IndexOfTest ()
		{
			List <int> l = new List <int> ();

			l.Add (100);
			l.Add (200);

			Assert.AreEqual (1, l.IndexOf (200), "Could not find value");
		}
		
		[Test, ExpectedException(typeof (ArgumentException))]
		public void IList_InsertInvalidType1 ()
		{
			IList list = _list1 as IList;
			list.Insert(0, new object());
		}

		[Test, ExpectedException(typeof (ArgumentException))]
		public void IList_InsertInvalidType2 ()
		{
			IList list = _list1 as IList;
			list.Insert(0, null);
		}
		
		[Test, ExpectedException(typeof (ArgumentException))]
		public void IList_AddInvalidType1()
		{
			IList list = _list1 as IList;
			list.Add(new object());
		}

		[Test, ExpectedException(typeof (ArgumentException))]
		public void IList_AddInvalidType2()
		{
			IList list = _list1 as IList;
			list.Add(null);
		}
		
		[Test]
		public void IList_RemoveInvalidType()
		{
			IList list = _list1 as IList;
			int nCount = list.Count;
			list.Remove(new object());
			Assert.AreEqual(nCount, list.Count);

			list.Remove(null);
			Assert.AreEqual(nCount, list.Count);
		}

		[Test, ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void IndexOfOutOfRangeTest ()
		{
			List <int> l = new List <int> (4);
			l.IndexOf (0, 0, 4);
		}

		[Test]
		public void GetRangeTest ()
		{
			List <int> r = _list1.GetRange (2, 4);
			Assert.AreEqual (4, r.Count);
			Assert.AreEqual (22, r [0]);
			Assert.AreEqual (80, r [1]);
			Assert.AreEqual (56, r [2]);
			Assert.AreEqual (52, r [3]);
		}

		[Test]
		public void EnumeratorTest ()
		{
			List <int>.Enumerator e = _list1.GetEnumerator ();
			for (int i = 0; i < _list1_contents.Length; i++)
			{
				Assert.IsTrue (e.MoveNext ());
				Assert.AreEqual (_list1_contents [i], e.Current);
			}
			Assert.IsFalse (e.MoveNext ());
		}

		[Test]
		public void ConstructWithSizeTest ()
		{
			List <object> l_1 = new List <object> (1);
			List <object> l_2 = new List <object> (50);
			List <object> l_3 = new List <object> (0);

			Assert.AreEqual (1, l_1.Capacity);
			Assert.AreEqual (50, l_2.Capacity);
			Assert.AreEqual (0, l_3.Capacity);
		}

		[Test, ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void ConstructWithInvalidSizeTest ()
		{
			List <int> l = new List <int> (-1);
		}

		[Test]
		public void ConstructWithCollectionTest ()
		{
			List <int> l1 = new List <int> (_list1);
			Assert.AreEqual (_list1.Count, l1.Count);
			Assert.AreEqual (l1.Count, l1.Capacity);
			for (int i = 0; i < l1.Count; i++)
				Assert.AreEqual (_list1 [i], l1 [i]);
		}

		[Test, ExpectedException (typeof (ArgumentNullException))]
		public void ConstructWithInvalidCollectionTest ()
		{
			List <int> n = null;
			List <int> l1 = new List <int> (n);
		}

		[Test]
		public void AddTest ()
		{
			int count = _list1.Count;
			_list1.Add (-1);
			Assert.AreEqual (count + 1, _list1.Count);
			Assert.AreEqual (-1, _list1 [_list1.Count - 1]);
		}

		[Test]
		public void AddRangeTest ()
		{
			int count = _list1.Count;
			// FIXME arrays currently do not support generic collection
			// interfaces
			int [] range = { -1, -2, -3 };
			List <int> tmp = new List <int> (3);
			foreach (int i in range)
				tmp.Add (i);
			// _list1.AddRange (range);
			_list1.AddRange (tmp);
			
			Assert.AreEqual (count + 3, _list1.Count);
			Assert.AreEqual (-1, _list1 [_list1.Count - 3]);
			Assert.AreEqual (-2, _list1 [_list1.Count - 2]);
			Assert.AreEqual (-3, _list1 [_list1.Count - 1]);
		}

		[Test, ExpectedException (typeof (ArgumentNullException))]
		public void AddNullRangeTest ()
		{
			int [] n = null;
			_list1.AddRange (n);
		}

		[Test]
		public void BinarySearchTest ()
		{
			List <int> l = new List <int> (_list1);
			l.Sort ();
			Assert.AreEqual (0, l.BinarySearch (22));
			Assert.AreEqual (-2, l.BinarySearch (23));
			Assert.AreEqual (- (l.Count + 1), l.BinarySearch (int.MaxValue));
		}

#if !NET_4_0 && !NET_2_1 // FIXME: the blob contains the 2.0 mscorlib version

		[Test]
		[Category ("TargetJvmNotWorking")]
		public void SerializeTest ()
		{
			List <int> list = new List <int> ();
			list.Add (5);
			list.Add (0);
			list.Add (7);

#if TARGET_JVM
			BinaryFormatter bf = (BinaryFormatter)vmw.@internal.remoting.BinaryFormatterUtils.CreateBinaryFormatter (false);
#else
			BinaryFormatter bf = new BinaryFormatter ();
#endif // TARGET_JVM
			MemoryStream ms = new MemoryStream ();
			bf.Serialize (ms, list);

			byte [] buffer = new byte [ms.Length];
			ms.Position = 0;
			ms.Read (buffer, 0, buffer.Length);

			Assert.AreEqual (_serializedList, buffer);
		}

#endif

		[Test]
		[Category ("TargetJvmNotWorking")]
		public void DeserializeTest ()
		{
			MemoryStream ms = new MemoryStream ();
			ms.Write (_serializedList, 0, _serializedList.Length);
			ms.Position = 0;

#if TARGET_JVM
			BinaryFormatter bf = (BinaryFormatter)vmw.@internal.remoting.BinaryFormatterUtils.CreateBinaryFormatter (false);
#else
			BinaryFormatter bf = new BinaryFormatter ();
#endif // TARGET_JVM
			List<int> list = (List<int>) bf.Deserialize (ms);
			Assert.AreEqual (3, list.Count, "#1");
			Assert.AreEqual (5, list [0], "#2");
			Assert.AreEqual (0, list [1], "#3");
			Assert.AreEqual (7, list [2], "#4");
		}

		[Test]
		public void SortTest ()
		{
			List <int> l = new List <int> (_list1);
			l.Sort ();
			Assert.AreEqual (_list1.Count, l.Count);
			Assert.AreEqual (22, l [0]);
			int minimum = 22;
			foreach (int i in l)
			{
				Assert.IsTrue (minimum <= i);
				minimum = i;
			}
		}

		[Test]
		public void ClearTest ()
		{
			int capacity = _list1.Capacity;
			_list1.Clear ();
			Assert.AreEqual (0, _list1.Count);
			Assert.AreEqual (capacity, _list1.Capacity);
		}

		[Test]
		public void ContainsTest ()
		{
			Assert.IsTrue (_list1.Contains (22));
			Assert.IsFalse (_list1.Contains (23));
		}

		private string StringConvert (int i)
		{
			return i.ToString ();
		}
		
		[Test]
		public void ConvertAllTest ()
		{
			List <string> s = _list1.ConvertAll ( (Converter <int, string>)StringConvert);
			Assert.AreEqual (_list1.Count, s.Count);
			Assert.AreEqual ("55", s [0]);
		}

		[Test]
		public void CopyToTest ()
		{
			int [] a = new int [2];
			_list1.CopyTo (1, a, 0, 2);
			Assert.AreEqual (50, a [0]);
			Assert.AreEqual (22, a [1]);

			int [] b = new int [_list1.Count + 1];
			b [_list1.Count] = 555;
			_list1.CopyTo (b);
			Assert.AreEqual (55, b [0]);
			Assert.AreEqual (555, b [_list1.Count]);

			b [0] = 888;
			_list1.CopyTo (b, 1);
			Assert.AreEqual (888, b [0]);
			Assert.AreEqual (55, b [1]);
		}

		[Test, ExpectedException (typeof (ArgumentNullException))]
		public void CopyToNullTest ()
		{
			int [] a = null;
			_list1.CopyTo (0, a, 0, 0);
		}

		static bool FindMultipleOfThree (int i)
		{
			return (i % 3) == 0;
		}

		static bool FindMultipleOfFour (int i)
		{
			return (i % 4) == 0;
		}

		static bool FindMultipleOfTwelve (int i)
		{
			return (i % 12) == 0;
		}

		[Test]
		public void FindTest ()
		{
			int i = _list1.Find (FindMultipleOfThree);
			Assert.AreEqual (63, i);

			i = _list1.Find (FindMultipleOfTwelve);
			Assert.AreEqual (default (int), i);
		}

		[Test, ExpectedException (typeof (ArgumentNullException))]
		public void FindNullTest ()
		{
			int i = _list1.Find (null);
		}

		[Test]
		public void FindAllSmallTest ()
		{
			List <int> findings = _list1.FindAll (FindMultipleOfFour);
			Assert.AreEqual (4, findings.Count);
			Assert.AreEqual (80, findings [0]);
			Assert.AreEqual (56, findings [1]);
			Assert.AreEqual (52, findings [2]);
			Assert.AreEqual (40, findings [3]);

			findings = _list1.FindAll (FindMultipleOfTwelve);
			Assert.IsNotNull (findings);
			Assert.AreEqual (0, findings.Count);
		}
		
		[Test]
		public void FindAllMediumTest ()
		{
			List <int> integers = new List <int> (10000);
			for (int i = 1; i <= 10000; i++)
				integers.Add (i);
			
			List <int> results = integers.FindAll (FindMultipleOfFour);
			
			Assert.IsNotNull (results);
			Assert.AreEqual (2500, results.Count);
			
			results = integers.FindAll (FindMultipleOfTwelve);
			
			Assert.IsNotNull (results);
			Assert.AreEqual (833, results.Count);
		}
		
		[Test]
		public void FindAllLargeTest ()
		{
			List <int> integers = new List <int> (70000);
			for (int i = 1; i <= 80000; i++)
				integers.Add (i);
			
			List <int> results = integers.FindAll (FindMultipleOfFour);
			
			Assert.IsNotNull (results);
			Assert.AreEqual (20000, results.Count);
			
			results = integers.FindAll (FindMultipleOfTwelve);
			
			Assert.IsNotNull (results);
			Assert.AreEqual (6666, results.Count);
		}

		[Test, ExpectedException (typeof (ArgumentNullException))]
		public void FindAllNullTest ()
		{
			List <int> findings = _list1.FindAll (null);
		}

		[Test]
		public void FindIndexTest ()
		{
			int i = _list1.FindIndex (FindMultipleOfThree);
			Assert.AreEqual (7, i);

			i = _list1.FindIndex (FindMultipleOfTwelve);
			Assert.AreEqual (-1, i);
		}

		[Test, ExpectedException (typeof (ArgumentNullException))]
		public void FindIndexNullTest ()
		{
			int i = _list1.FindIndex (null);
		}

		[Test]
		public void FindLastTest ()
		{
			int i = _list1.FindLast (FindMultipleOfFour);
			Assert.AreEqual (40, i);

			i = _list1.FindLast (FindMultipleOfTwelve);
			Assert.AreEqual (default (int), i);
		}

		[Test, ExpectedException (typeof (ArgumentNullException))]
		public void FindLastNullTest ()
		{
			int i = _list1.FindLast (null);
		}

		// FIXME currently generates Invalid IL Code error
		/*
		[Test]
		public void ForEachTest ()
		{
			int i = 0;
			_list1.ForEach (delegate (int j) { i += j; });

			Assert.AreEqual (418, i);
		}
		*/
		[Test]
		public void FindLastIndexTest ()
		{
			int i = _list1.FindLastIndex (FindMultipleOfFour);
			Assert.AreEqual (6, i);

			i = _list1.FindLastIndex (5, FindMultipleOfFour);
			Assert.AreEqual (5, i);

			i = _list1.FindIndex (FindMultipleOfTwelve);
			Assert.AreEqual (-1, i);
		}

		[Test, ExpectedException (typeof (ArgumentNullException))]
		public void FindLastIndexNullTest ()
		{
			int i = _list1.FindLastIndex (null);
		}

		[Test]
		public void RemoveTest ()
		{
			int count = _list1.Count;
			bool result = _list1.Remove (22);
			Assert.IsTrue (result);
			Assert.AreEqual (count - 1, _list1.Count);

			Assert.AreEqual (-1, _list1.IndexOf (22));

			result = _list1.Remove (0);
			Assert.IsFalse (result);
		}

		[Test]
		public void RemoveAllTest ()
		{
			int count = _list1.Count;
			int removedCount = _list1.RemoveAll (FindMultipleOfFour);
			Assert.AreEqual (4, removedCount);
			Assert.AreEqual (count - 4, _list1.Count);

			removedCount = _list1.RemoveAll (FindMultipleOfTwelve);
			Assert.AreEqual (0, removedCount);
			Assert.AreEqual (count - 4, _list1.Count);
		}

		[Test]
		public void RemoveAtTest ()
		{
			int count = _list1.Count;
			_list1.RemoveAt (0);
			Assert.AreEqual (count - 1, _list1.Count);
			Assert.AreEqual (50, _list1 [0]);
		}

		[Test, ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void RemoveOutOfRangeTest ()
		{
			_list1.RemoveAt (_list1.Count);
		}

		[Test]
		public void RemoveRangeTest ()
		{
			int count = _list1.Count;
			_list1.RemoveRange (1, 2);
			Assert.AreEqual (count - 2, _list1.Count);
			Assert.AreEqual (55, _list1 [0]);
			Assert.AreEqual (80, _list1 [1]);

			_list1.RemoveRange (0, 0);
			Assert.AreEqual (count - 2, _list1.Count);
		}

		[Test]
		public void RemoveRangeFromEmptyListTest ()
		{
			List<int> l = new List<int> ();
			l.RemoveRange (0, 0);
		}

		[Test, ExpectedException (typeof (ArgumentException))]
		public void RemoveRangeOutOfRangeTest ()
		{
			_list1.RemoveRange (1, _list1.Count);
		}

		[Test]
		public void ReverseTest ()
		{
			int count = _list1.Count;
			_list1.Reverse ();
			Assert.AreEqual (count, _list1.Count);

			Assert.AreEqual (63, _list1 [0]);
			Assert.AreEqual (55, _list1 [count - 1]);

			_list1.Reverse (0, 2);

			Assert.AreEqual (40, _list1 [0]);
			Assert.AreEqual (63, _list1 [1]);
		}

		[Test, ExpectedException (typeof (ArgumentException))]
		public void ReverseOutOfRangeTest ()
		{
			_list1.Reverse (1, _list1.Count);
		}

		[Test]
		public void ToArrayTest ()
		{
			int [] copiedContents = _list1.ToArray ();
			Assert.IsFalse (ReferenceEquals (copiedContents, _list1_contents));

			Assert.AreEqual (_list1.Count, copiedContents.Length);
			Assert.AreEqual (_list1 [0], copiedContents [0]);
		}

		[Test]
		public void TrimExcessTest ()
		{
			List <string> l = new List <string> ();
			l.Add ("foo");

			Assert.IsTrue (l.Count < l.Capacity);
			l.TrimExcess ();
			Assert.AreEqual (l.Count, l.Capacity);
		}

		bool IsPositive (int i)
		{
			return i >= 0;
		}

		[Test]
		public void TrueForAllTest ()
		{
			Assert.IsFalse (_list1.TrueForAll (FindMultipleOfFour));
			Assert.IsTrue (_list1.TrueForAll (IsPositive));
		}

		[Test, ExpectedException (typeof (ArgumentNullException))]
		public void TrueForAllNullTest ()
		{
			_list1.TrueForAll (null);
		}

		[Test, ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void CapacityOutOfRangeTest ()
		{
			_list1.Capacity = _list1.Count - 1;
		}

		[Test]
		public void BinarySearch_EmptyList ()
		{
			GenericComparer<int> comparer = new GenericComparer<int> ();
			List<int> l = new List<int> ();
			Assert.AreEqual (-1, l.BinarySearch (0, comparer), "BinarySearch");
			// bug 77030 - the comparer isn't called for an empty array/list
			Assert.IsFalse (comparer.Called, "Called");
		}

		[Test]
		public void BinarySearch2_EmptyList ()
		{
			GenericComparer<int> comparer = new GenericComparer<int> ();
			List<int> l = new List<int> ();
			Assert.AreEqual (-1, l.BinarySearch (0, 0, 0, comparer), "BinarySearch");
			// bug 77030 - the comparer isn't called for an empty array/list
			Assert.IsFalse (comparer.Called, "Called");
		}

		[Test]
		public void AddRange_Bug77019 ()
		{
			List<int> l = new List<int> ();
			Dictionary<string, int> d = new Dictionary<string, int> ();
			l.AddRange (d.Values);
			Assert.AreEqual (0, l.Count, "Count");
		}

		[Test]
		public void VersionCheck_Add ()
		{
			List<int> list = new List<int> ();
			IEnumerator enumerator = list.GetEnumerator ();
			list.Add (5);

			try {
				enumerator.MoveNext ();
				Assert.Fail ("#1");
			} catch (InvalidOperationException) {
			}

			try {
				enumerator.Reset ();
				Assert.Fail ("#2");
			} catch (InvalidOperationException) {
			}

			enumerator = list.GetEnumerator ();
			enumerator.MoveNext ();
		}

		[Test]
		public void VersionCheck_AddRange ()
		{
			List<int> list = new List<int> ();
			IEnumerator enumerator = list.GetEnumerator ();
			list.AddRange (new int [] { 5, 7 });

			try {
				enumerator.MoveNext ();
				Assert.Fail ("#1");
			} catch (InvalidOperationException) {
			}

			try {
				enumerator.Reset ();
				Assert.Fail ("#2");
			} catch (InvalidOperationException) {
			}

			enumerator = list.GetEnumerator ();
			enumerator.MoveNext ();
		}

		[Test]
		public void VersionCheck_Clear ()
		{
			List<int> list = new List<int> ();
			IEnumerator enumerator = list.GetEnumerator ();
			list.Clear ();

			try {
				enumerator.MoveNext ();
				Assert.Fail ("#1");
			} catch (InvalidOperationException) {
			}

			try {
				enumerator.Reset ();
				Assert.Fail ("#2");
			} catch (InvalidOperationException) {
			}

			enumerator = list.GetEnumerator ();
			enumerator.MoveNext ();
		}

		[Test]
		public void VersionCheck_Insert ()
		{
			List<int> list = new List<int> ();
			IEnumerator enumerator = list.GetEnumerator ();
			list.Insert (0, 7);

			try {
				enumerator.MoveNext ();
				Assert.Fail ("#1");
			} catch (InvalidOperationException) {
			}

			try {
				enumerator.Reset ();
				Assert.Fail ("#2");
			} catch (InvalidOperationException) {
			}

			enumerator = list.GetEnumerator ();
			enumerator.MoveNext ();
		}

		[Test]
		public void VersionCheck_InsertRange ()
		{
			List<int> list = new List<int> ();
			IEnumerator enumerator = list.GetEnumerator ();
			list.InsertRange (0, new int [] { 5, 7 });

			try {
				enumerator.MoveNext ();
				Assert.Fail ("#1");
			} catch (InvalidOperationException) {
			}

			try {
				enumerator.Reset ();
				Assert.Fail ("#2");
			} catch (InvalidOperationException) {
			}

			enumerator = list.GetEnumerator ();
			enumerator.MoveNext ();
		}

		[Test]
		public void VersionCheck_Remove ()
		{
			List<int> list = new List<int> ();
			list.Add (5);
			IEnumerator enumerator = list.GetEnumerator ();
			// version number is not incremented if item does not exist in list
			list.Remove (7);
			enumerator.MoveNext ();
			list.Remove (5);

			try {
				enumerator.MoveNext ();
				Assert.Fail ("#1");
			} catch (InvalidOperationException) {
			}

			try {
				enumerator.Reset ();
				Assert.Fail ("#2");
			} catch (InvalidOperationException) {
			}

			enumerator = list.GetEnumerator ();
			enumerator.MoveNext ();
		}

		[Test]
		public void VersionCheck_RemoveAll ()
		{
			List<int> list = new List<int> ();
			list.Add (5);
			IEnumerator enumerator = list.GetEnumerator ();
			// version is not incremented if there are no items to remove
			list.RemoveAll (FindMultipleOfFour);
			enumerator.MoveNext ();
			list.Add (4);

			enumerator = list.GetEnumerator ();
			list.RemoveAll (FindMultipleOfFour);

			try {
				enumerator.MoveNext ();
				Assert.Fail ("#1");
			} catch (InvalidOperationException) {
			}

			try {
				enumerator.Reset ();
				Assert.Fail ("#2");
			} catch (InvalidOperationException) {
			}

			enumerator = list.GetEnumerator ();
			enumerator.MoveNext ();
		}

		[Test]
		public void VersionCheck_RemoveAt ()
		{
			List<int> list = new List<int> ();
			list.Add (5);
			IEnumerator enumerator = list.GetEnumerator ();
			list.RemoveAt (0);

			try {
				enumerator.MoveNext ();
				Assert.Fail ("#1");
			} catch (InvalidOperationException) {
			}

			try {
				enumerator.Reset ();
				Assert.Fail ("#2");
			} catch (InvalidOperationException) {
			}

			enumerator = list.GetEnumerator ();
			enumerator.MoveNext ();
		}

		[Test]
		public void VersionCheck_RemoveRange ()
		{
			List<int> list = new List<int> ();
			list.Add (5);
			IEnumerator enumerator = list.GetEnumerator ();
			// version is not incremented if count is zero
			list.RemoveRange (0, 0);
			enumerator.MoveNext ();
			enumerator.Reset ();
			list.RemoveRange (0, 1);

			try {
				enumerator.MoveNext ();
				Assert.Fail ("#1");
			} catch (InvalidOperationException) {
			}

			try {
				enumerator.Reset ();
				Assert.Fail ("#2");
			} catch (InvalidOperationException) {
			}

			enumerator = list.GetEnumerator ();
			enumerator.MoveNext ();
		}

		[Test, ExpectedException (typeof (InvalidOperationException))] // #699182
		public void VersionCheck_Indexer ()
		{
			var list = new List<int> () { 0, 2, 3 };
			var enumerator = list.GetEnumerator ();

			list [0] = 1;

			enumerator.MoveNext ();
		}

		[Test]
		public void VersionCheck_Reverse ()
		{
			List<int> list = new List<int> ();
			IEnumerator enumerator = list.GetEnumerator ();
			list.Reverse ();

			try {
				enumerator.MoveNext ();
				Assert.Fail ("#A1");
			} catch (InvalidOperationException) {
			}

			try {
				enumerator.Reset ();
				Assert.Fail ("#A2");
			} catch (InvalidOperationException) {
			}

			enumerator = list.GetEnumerator ();
			list.Reverse (0, 0);

			try {
				enumerator.MoveNext ();
				Assert.Fail ("#B1");
			} catch (InvalidOperationException) {
			}

			try {
				enumerator.Reset ();
				Assert.Fail ("#B2");
			} catch (InvalidOperationException) {
			}

			enumerator = list.GetEnumerator ();
			enumerator.MoveNext ();
		}

		class SortTestComparer: IComparer<string> {

			public int Compare (string s1, string s2)
			{
				return String.Compare (s1, s2);
			}
		}

		[Test]
		public void Sort_Bug76361 ()
		{
			SortTestComparer comparer = new SortTestComparer ();
			List<string> l = new List<string> ();
			l.Add ("foo");
			l.Add ("bar");
			l.Sort (comparer);
			Assert.AreEqual ("bar", l[0], "0");
			Assert.AreEqual ("foo", l[1], "1");
			Assert.AreEqual (2, l.Count, "Count");
		}

		// for bug #77039 test case
		class GenericIComparable: IComparable<GenericIComparable> {
			private int _NumberToSortOn;

			public int NumberToSortOn {
				get { return _NumberToSortOn; }
				set { _NumberToSortOn = value; }
			}

			public GenericIComparable (int val)
			{
				_NumberToSortOn = val;
			}

			public int CompareTo (GenericIComparable other)
			{
				return NumberToSortOn.CompareTo (other.NumberToSortOn);
			}
		}

		[Test]
		public void Sort_GenericIComparable_Bug77039 ()
		{
			List<GenericIComparable> l = new List<GenericIComparable> ();
			l.Add (new GenericIComparable (2));
			l.Add (new GenericIComparable (1));
			l.Add (new GenericIComparable (3));
			l.Sort ();
			Assert.AreEqual (1, l[0].NumberToSortOn, "0");
			Assert.AreEqual (2, l[1].NumberToSortOn, "1");
			Assert.AreEqual (3, l[2].NumberToSortOn, "2");
		}

		class NonGenericIComparable: IComparable {
			private int _NumberToSortOn;

			public int NumberToSortOn {
				get { return _NumberToSortOn; }
				set { _NumberToSortOn = value; }
			}

			public NonGenericIComparable (int val)
			{
				_NumberToSortOn = val;
			}

			public int CompareTo (object obj)
			{
				return NumberToSortOn.CompareTo ((obj as NonGenericIComparable).NumberToSortOn);
			}
		}

		[Test]
		public void Sort_NonGenericIComparable ()
		{
			List<NonGenericIComparable> l = new List<NonGenericIComparable> ();
			l.Add (new NonGenericIComparable (2));
			l.Add (new NonGenericIComparable (1));
			l.Add (new NonGenericIComparable (3));
			l.Sort ();
			Assert.AreEqual (1, l[0].NumberToSortOn, "0");
			Assert.AreEqual (2, l[1].NumberToSortOn, "1");
			Assert.AreEqual (3, l[2].NumberToSortOn, "2");
		}

		class NonComparable {
		}

		[Test]
		public void Sort_GenericNonIComparable ()
		{
			List<NonComparable> l = new List<NonComparable> ();
			l.Sort ();
			// no element -> no sort -> no exception
			l.Add (new NonComparable ());
			l.Sort ();
			// one element -> no sort -> no exception
		}

		[Test]
		[ExpectedException (typeof (InvalidOperationException))]
		public void Sort_GenericNonIComparable_2 ()
		{
			List<NonComparable> l = new List<NonComparable> ();
			l.Add (new NonComparable ());
			l.Add (new NonComparable ());
			l.Sort ();
			// two element -> sort -> exception!
		}
		
		[Test]
		public void IList_Contains_InvalidType()
		{
			List<string> list = new List<string>();
			list.Add("foo");
			Assert.IsFalse (((IList)list).Contains(new object()));

			Assert.IsFalse (((IList)_list1).Contains(null));
		}
		
		[Test]
		public void IList_IndexOf_InvalidType()
		{
			List<string> list = new List<string>();
			list.Add("foo");
			Assert.AreEqual (-1, ((IList)list).IndexOf(new object()));

			Assert.AreEqual (-1, ((IList)_list1).IndexOf(null));
		}

		// for bug #77277 test case
		[Test]
		public void Test_ContainsAndIndexOf_EquatableItem ()
		{
			List<EquatableClass> list = new List<EquatableClass> ();
			EquatableClass item0 = new EquatableClass (0);
			EquatableClass item1 = new EquatableClass (1);

			list.Add (item0);
			list.Add (item1);
			list.Add (item0);

			Assert.AreEqual (true, list.Contains (item0), "#0");
			Assert.AreEqual (true, list.Contains (new EquatableClass (0)), "#1");
			Assert.AreEqual (0, list.IndexOf (item0), "#2");
			Assert.AreEqual (0, list.IndexOf (new EquatableClass (0)), "#3");
			Assert.AreEqual (2, list.LastIndexOf (item0), "#4");
			Assert.AreEqual (2, list.LastIndexOf (new EquatableClass (0)), "#5");
		}

		// for bug #81387 test case
		[Test]
		public void Test_Contains_After_Remove ()
		{
			List<int> list = new List<int> ();
            list.Add (2);

            list.Remove (2);

			Assert.AreEqual (false, list.Contains (2), "#0");
		}
		
		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void SetItem_OutOfRange()
		{
			List<string> list = new List<string>();
			list[0] = "foo";
		}
		
		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void SetItem_IList_OutOfRange()
		{
			IList<string> list = new List<string>();
			list[0] = "foo";
		}

		public class EquatableClass : IEquatable<EquatableClass>
		{
			int _x;
			public EquatableClass (int x)
			{
				_x = x;
			}

			public bool Equals (EquatableClass other)
			{
				return this._x == other._x;
			}
		}

		delegate void D ();
		bool Throws (D d)
		{
			try {
				d ();
				return false;
			} catch {
				return true;
			}
		}

		[Test]
		// based on #491858, #517415
		public void Enumerator_Current ()
		{
			var e1 = new List<int>.Enumerator ();
			Assert.IsFalse (Throws (delegate { var x = e1.Current; }));

			var d = new List<int> ();
			var e2 = d.GetEnumerator ();
			Assert.IsFalse (Throws (delegate { var x = e2.Current; }));
			e2.MoveNext ();
			Assert.IsFalse (Throws (delegate { var x = e2.Current; }));
			e2.Dispose ();
			Assert.IsFalse (Throws (delegate { var x = e2.Current; }));

			var e3 = ((IEnumerable<int>) d).GetEnumerator ();
			Assert.IsFalse (Throws (delegate { var x = e3.Current; }));
			e3.MoveNext ();
			Assert.IsFalse (Throws (delegate { var x = e3.Current; }));
			e3.Dispose ();
			Assert.IsFalse (Throws (delegate { var x = e3.Current; }));

			var e4 = ((IEnumerable) d).GetEnumerator ();
			Assert.IsTrue (Throws (delegate { var x = e4.Current; }));
			e4.MoveNext ();
			Assert.IsTrue (Throws (delegate { var x = e4.Current; }));
			((IDisposable) e4).Dispose ();
			Assert.IsTrue (Throws (delegate { var x = e4.Current; }));
		}

		[Test] //bug #672907
		public void ICollectionCopyToExceptions ()
		{
			var l = new List <int> ();
			ICollection x = l;
			try {
				x.CopyTo (null, 0);
				Assert.Fail ("#1");
			} catch (Exception e) {
				Assert.IsTrue (e is ArgumentNullException, "#2");
			}

			try {
				x.CopyTo (new int [10], -1);
				Assert.Fail ("#3");
			} catch (Exception e) {
				Assert.IsTrue (e is ArgumentOutOfRangeException, "#4");
			}

			try {
				x.CopyTo (new int [10, 1], 0);
				Assert.Fail ("#5");
			} catch (Exception e) {
				Assert.IsTrue (e is ArgumentException, "#6");
			}

			try {
				x.CopyTo (Array.CreateInstance (typeof (int), new int [] { 10 }, new int[] { 1 }), 0);
				Assert.Fail ("#7");
			} catch (Exception e) {
				Assert.IsTrue (e is ArgumentException, "#8");
			}

			l.Add (10); l.Add (20);
			try {
				x.CopyTo (new int [1], 0);
				Assert.Fail ("#9");
			} catch (Exception e) {
				Assert.IsTrue (e is ArgumentException, "#10");
			}
		}

		[Test]
		public void LastIndexOfEmpty_2558 () {
			var l = new List<int> ();
			Assert.AreEqual (-1, l.IndexOf (-1));
		}


#region Enumerator mutability

		class Bar
		{
		}

		class Foo : IEnumerable<Bar>
		{
			Baz enumerator;

			public Foo ()
			{
				enumerator = new Baz ();
			}

			public IEnumerator<Bar> GetEnumerator ()
			{
				return enumerator;
			}

			IEnumerator IEnumerable.GetEnumerator ()
			{
				return enumerator;
			}
		}

		class Baz : IEnumerator<Bar>
		{
			public bool DisposeWasCalled = false;

			public void Dispose ()
			{
				DisposeWasCalled = true;
			}

			public bool MoveNext ()
			{
				return false; //assume empty collection
			}

			public void Reset ()
			{
			}

			public Bar Current
			{
				get { return null; }
			}

			object IEnumerator.Current
			{
				get { return Current; }
			}
		}

		[Test]
		public void PremiseAboutDisposeBeingCalledWhenLooping ()
		{
			Foo enumerable = new Foo ();
			Baz enumerator = enumerable.GetEnumerator () as Baz;
			Assert.IsNotNull (enumerator);
			Assert.AreEqual (false, enumerator.DisposeWasCalled);
			foreach (var element in enumerable) ; //sic
			Assert.AreEqual (true, enumerator.DisposeWasCalled);
		}

		[Test]
		public void TwoEnumeratorsOfTwoDifferentListsAreDifferent ()
		{
			var twoThree = new List<int> { 2, 3 };
			var oneTwo = new List<int> { 2, 4 };
			Assert.IsFalse (oneTwo.GetEnumerator ().Equals (twoThree.GetEnumerator ()));
		}

		[Test]
		public void TwoEnumeratorsOfTwoDifferentListsWithSameElementsAreDifferent ()
		{
			var twoThree = new List<int> { 2, 3 };
			var anotherTwoThree = new List<int> { 2, 3 };
			Assert.IsFalse(twoThree.GetEnumerator ().Equals (anotherTwoThree.GetEnumerator ()));
		}

		[Test]
		public void EnumeratorIsSameInSameListAfterSubsequentCalls ()
		{
			var enumerable = new List<Bar> ();
			var enumerator = enumerable.GetEnumerator ();
			var enumerator2 = enumerable.GetEnumerator ();

			Assert.IsFalse (ReferenceEquals (enumerator2, enumerator)); //because they are value-types

			Assert.IsTrue (enumerator2.Equals (enumerator));
		}


		[Test] // was bug in Mono 2.10.9
		public void EnumeratorIsStillSameInSubsequentCallsEvenHavingADisposalInBetween ()
		{
			var enumerable = new List<Bar> ();
			var enumerator = enumerable.GetEnumerator ();
			enumerator.Dispose ();
			var enumerator2 = enumerable.GetEnumerator ();

			Assert.IsFalse (ReferenceEquals (enumerator2, enumerator)); //because they are value-types

			Assert.IsTrue (enumerator2.Equals (enumerator));
		}

		[Test]
		public void EnumeratorIsObviouslyDifferentAfterListChanges ()
		{
			var enumerable = new List<Bar> ();
			var enumerator = enumerable.GetEnumerator ();
			enumerable.Add (new Bar ());
			var enumerator2 = enumerable.GetEnumerator ();

			Assert.IsFalse (ReferenceEquals (enumerator2, enumerator)); //because they are value-types

			Assert.IsFalse (enumerator2.Equals (enumerator));
		}

		[Test] // was bug in Mono 2.10.9
		public void DotNetDoesntThrowObjectDisposedExceptionAfterSubsequentDisposes()
		{
			var enumerable = new List<Bar> ();
			var enumerator = enumerable.GetEnumerator ();
			Assert.AreEqual (false, enumerator.MoveNext ());
			enumerator.Dispose();
			Assert.AreEqual (false, enumerator.MoveNext ());
		}
#endregion


	}
}
#endif
Back to Top