ArrayTest.cs 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988
  1. // ArrayTest.cs - NUnit Test Cases for the System.Array class
  2. //
  3. // David Brandt ([email protected])
  4. //
  5. // (C) Ximian, Inc. http://www.ximian.com
  6. //
  7. using NUnit.Framework;
  8. using System;
  9. using System.Collections;
  10. using System.Globalization;
  11. namespace MonoTests.System
  12. {
  13. public class ArrayTest : TestCase
  14. {
  15. public ArrayTest() {}
  16. protected override void SetUp()
  17. {
  18. }
  19. protected override void TearDown()
  20. {
  21. }
  22. public void TestIsFixedSize() {
  23. char[] a1 = {'a'};
  24. Assert("All arrays are fixed", a1.IsFixedSize);
  25. }
  26. public void TestIsReadOnly() {
  27. char[] a1 = {'a'};
  28. Assert("No array is readonly", !a1.IsReadOnly);
  29. }
  30. public void TestIsSynchronized() {
  31. char[] a1 = {'a'};
  32. Assert("No array is synchronized", !a1.IsSynchronized);
  33. }
  34. public void TestLength() {
  35. {
  36. char[] a1 = { };
  37. AssertEquals("Zero length array", 0, a1.Length);
  38. }
  39. {
  40. char[] a1 = {'c'};
  41. AssertEquals("One-length array", 1, a1.Length);
  42. }
  43. {
  44. char[] a1 = {'c', 'c'};
  45. AssertEquals("Two-length array", 2, a1.Length);
  46. }
  47. }
  48. public void TestRank() {
  49. char[] a1 = { 'c', 'd', 'e' };
  50. AssertEquals("Rank one", 1, a1.Rank);
  51. char[,] a2 = new Char[3,3];
  52. AssertEquals("Rank two", 2, a2.Rank);
  53. char[,,] a3 = new Char[3,3,3];
  54. AssertEquals("Rank three", 3, a3.Rank);
  55. }
  56. public void TestBinarySearch1() {
  57. bool errorThrown = false;
  58. try {
  59. Array.BinarySearch(null, "blue");
  60. } catch (ArgumentNullException) {
  61. errorThrown = true;
  62. }
  63. Assert("#B01", errorThrown);
  64. errorThrown = false;
  65. try {
  66. char[,] c1 = new Char[2,2];
  67. Array.BinarySearch(c1, "needle");
  68. } catch (RankException) {
  69. errorThrown = true;
  70. }
  71. Assert("#B02", errorThrown);
  72. {
  73. char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
  74. Assert("#B05",
  75. Array.BinarySearch(arr, 'c') >= 3);
  76. Assert("#B06",
  77. Array.BinarySearch(arr, 'c') < 6);
  78. }
  79. {
  80. char[] arr = {'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
  81. AssertEquals("#B07",
  82. -4, Array.BinarySearch(arr, 'c'));
  83. }
  84. {
  85. char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
  86. AssertEquals("#B08",
  87. -9, Array.BinarySearch(arr, 'e'));
  88. }
  89. }
  90. public void TestBinarySearch2() {
  91. bool errorThrown = false;
  92. try {
  93. Array.BinarySearch(null, 0, 1, "blue");
  94. } catch (ArgumentNullException) {
  95. errorThrown = true;
  96. }
  97. Assert("#B20", errorThrown);
  98. errorThrown = false;
  99. try {
  100. char[,] c1 = new Char[2,2];
  101. Array.BinarySearch(c1, 0, 1, "needle");
  102. } catch (RankException) {
  103. errorThrown = true;
  104. }
  105. Assert("#B21", errorThrown);
  106. errorThrown = false;
  107. try {
  108. char[] c1 = {'a'};
  109. Array.BinarySearch(c1, -1, 1, 'a');
  110. } catch (ArgumentOutOfRangeException) {
  111. errorThrown = true;
  112. }
  113. Assert("#B22", errorThrown);
  114. errorThrown = false;
  115. try {
  116. char[] c1 = {'a'};
  117. Array.BinarySearch(c1, 0, -1, 'a');
  118. } catch (ArgumentOutOfRangeException) {
  119. errorThrown = true;
  120. }
  121. Assert("#B23", errorThrown);
  122. errorThrown = false;
  123. try {
  124. char[] c1 = {'a'};
  125. Array.BinarySearch(c1, 0, 4, 'a');
  126. } catch (ArgumentException) {
  127. errorThrown = true;
  128. }
  129. Assert("#B24", errorThrown);
  130. {
  131. char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
  132. Assert("#B26",
  133. Array.BinarySearch(arr, 2, 8, 'c') >= 5);
  134. Assert("#B27",
  135. Array.BinarySearch(arr, 2, 8, 'c') < 8);
  136. }
  137. {
  138. char[] arr = {'z', 'z', 'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
  139. AssertEquals("#B28",
  140. -6, Array.BinarySearch(arr, 2, 8, 'c'));
  141. }
  142. {
  143. char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
  144. AssertEquals("#B29",
  145. -11, Array.BinarySearch(arr, 2, 8, 'e'));
  146. }
  147. }
  148. // TODO - testBinarySearch with explicit IComparer args
  149. public void TestClear() {
  150. bool errorThrown = false;
  151. try {
  152. Array.Clear(null, 0, 1);
  153. } catch (ArgumentNullException) {
  154. errorThrown = true;
  155. }
  156. Assert("#C01", errorThrown);
  157. int[] i1 = { 1, 2, 3, 4 };
  158. {
  159. int[] compare = {1,2,3,4};
  160. AssertEquals("#C02", compare[0], i1[0]);
  161. AssertEquals("#C03", compare[1], i1[1]);
  162. AssertEquals("#C04", compare[2], i1[2]);
  163. AssertEquals("#C05", compare[3], i1[3]);
  164. }
  165. Array.Clear(i1, 3, 1);
  166. {
  167. int[] compare = {1,2,3,0};
  168. AssertEquals("#C06", compare[0], i1[0]);
  169. AssertEquals("#C07", compare[1], i1[1]);
  170. AssertEquals("#C08", compare[2], i1[2]);
  171. AssertEquals("#C09", compare[3], i1[3]);
  172. }
  173. Array.Clear(i1, 1, 1);
  174. {
  175. int[] compare = {1,0,3,0};
  176. AssertEquals("#C10", compare[0], i1[0]);
  177. AssertEquals("#C11", compare[1], i1[1]);
  178. AssertEquals("#C12", compare[2], i1[2]);
  179. AssertEquals("#C13", compare[3], i1[3]);
  180. }
  181. Array.Clear(i1, 1, 3);
  182. {
  183. int[] compare = {1,0,0,0};
  184. AssertEquals("#C14", compare[0], i1[0]);
  185. AssertEquals("#C15", compare[1], i1[1]);
  186. AssertEquals("#C16", compare[2], i1[2]);
  187. AssertEquals("#C17", compare[3], i1[3]);
  188. }
  189. string[] s1 = { "red", "green", "blue" };
  190. Array.Clear(s1, 0, 3);
  191. {
  192. string[] compare = {null, null, null};
  193. AssertEquals("#C18", compare[0], s1[0]);
  194. AssertEquals("#C19", compare[1], s1[1]);
  195. AssertEquals("#C20", compare[2], s1[2]);
  196. }
  197. }
  198. public void TestClone() {
  199. char[] c1 = {'a', 'b', 'c'};
  200. char[] c2 = (char[])c1.Clone();
  201. AssertEquals("#D01", c1[0], c2[0]);
  202. AssertEquals("#D02", c1[1], c2[1]);
  203. AssertEquals("#D03", c1[2], c2[2]);
  204. char[] d10 = {'a', 'b'};
  205. char[] d11 = {'a', 'c'};
  206. char[] d12 = {'b', 'c'};
  207. char[][] d1 = {d10, d11, d12};
  208. char[][] d2 = (char[][])d1.Clone();
  209. AssertEquals("#D04", d1[0], d2[0]);
  210. AssertEquals("#D05", d1[1], d2[1]);
  211. AssertEquals("#D06", d1[2], d2[2]);
  212. d1[0][0] = 'z';
  213. AssertEquals("#D07", d1[0], d2[0]);
  214. }
  215. public void TestCopy() {
  216. {
  217. bool errorThrown = false;
  218. try {
  219. Char[] c1 = {};
  220. Array.Copy(c1, null, 1);
  221. } catch (ArgumentNullException) {
  222. errorThrown = true;
  223. }
  224. Assert("#E01", errorThrown);
  225. }
  226. {
  227. bool errorThrown = false;
  228. try {
  229. Char[] c1 = {};
  230. Array.Copy(null, c1, 1);
  231. } catch (ArgumentNullException) {
  232. errorThrown = true;
  233. }
  234. Assert("#E02", errorThrown);
  235. }
  236. {
  237. bool errorThrown = false;
  238. try {
  239. Char[] c1 = new Char[1];
  240. Char[,] c2 = new Char[1,1];
  241. Array.Copy(c1, c2, 1);
  242. } catch (RankException) {
  243. errorThrown = true;
  244. }
  245. Assert("#E03", errorThrown);
  246. }
  247. {
  248. bool errorThrown = false;
  249. try {
  250. Char[] c1 = new Char[1];
  251. string[] s1 = new String[1];
  252. Array.Copy(c1, s1, 1);
  253. } catch (ArrayTypeMismatchException) {
  254. errorThrown = true;
  255. }
  256. Assert("#E04", errorThrown);
  257. }
  258. {
  259. bool errorThrown = false;
  260. try {
  261. Char[] c1 = new Char[1];
  262. Object[] o1 = new Object[1];
  263. o1[0] = "hello";
  264. Array.Copy(o1, c1, 1);
  265. } catch (InvalidCastException) {
  266. errorThrown = true;
  267. }
  268. Assert("#E05", errorThrown);
  269. }
  270. {
  271. bool errorThrown = false;
  272. try {
  273. Char[] c1 = new Char[1];
  274. Char[] c2 = new Char[1];
  275. Array.Copy(c1, c2, -1);
  276. } catch (ArgumentOutOfRangeException) {
  277. errorThrown = true;
  278. }
  279. Assert("#E06", errorThrown);
  280. }
  281. {
  282. bool errorThrown = false;
  283. try {
  284. Char[] c1 = new Char[1];
  285. Char[] c2 = new Char[2];
  286. Array.Copy(c1, c2, 2);
  287. } catch (ArgumentException) {
  288. errorThrown = true;
  289. }
  290. Assert("#E07", errorThrown);
  291. }
  292. {
  293. bool errorThrown = false;
  294. try {
  295. Char[] c1 = new Char[1];
  296. Char[] c2 = new Char[2];
  297. Array.Copy(c2, c1, 2);
  298. } catch (ArgumentException) {
  299. errorThrown = true;
  300. }
  301. Assert("#E08", errorThrown);
  302. }
  303. char[] orig = {'a', 'b', 'd', 'a'};
  304. char[] copy = new Char[4];
  305. Array.Copy(orig, copy, 4);
  306. for (int i = 0; i < orig.Length; i++) {
  307. AssertEquals("#E09(" + i + ")",
  308. orig[i], copy[i]);
  309. }
  310. Array.Clear(copy, 0, copy.Length);
  311. for (int i = 0; i < orig.Length; i++) {
  312. AssertEquals("#E10(" + i + ")",
  313. (char)0, copy[i]);
  314. }
  315. Array.Copy(orig, copy, 2);
  316. AssertEquals("#E11", orig[0], copy[0]);
  317. AssertEquals("#E12", orig[1], copy[1]);
  318. Assert("#E13", orig[2] != copy[2]);
  319. Assert("#E14", orig[3] != copy[3]);
  320. }
  321. public void TestCopy2() {
  322. {
  323. bool errorThrown = false;
  324. try {
  325. Char[] c1 = new Char[2];
  326. Char[] c2 = new Char[2];
  327. Array.Copy(c2, 1, c1, 0, 2);
  328. } catch (ArgumentException) {
  329. errorThrown = true;
  330. }
  331. Assert("#E31", errorThrown);
  332. }
  333. {
  334. bool errorThrown = false;
  335. try {
  336. Char[] c1 = new Char[2];
  337. Char[] c2 = new Char[2];
  338. Array.Copy(c2, 0, c1, 1, 2);
  339. } catch (ArgumentException) {
  340. errorThrown = true;
  341. }
  342. Assert("#E32", errorThrown);
  343. }
  344. char[] orig = {'a', 'b', 'd', 'a'};
  345. char[] copy = new Char[4];
  346. Array.Copy(orig, 1, copy, 1, 3);
  347. Assert("#E33", copy[0] != orig[0]);
  348. for (int i = 1; i < orig.Length; i++) {
  349. AssertEquals("#E34(" + i + ")",
  350. orig[i], copy[i]);
  351. }
  352. Array.Clear(copy, 0, copy.Length);
  353. Array.Copy(orig, 1, copy, 0, 2);
  354. AssertEquals("#E35", orig[1], copy[0]);
  355. AssertEquals("#E36", orig[2], copy[1]);
  356. Assert("#E37", copy[2] != orig[2]);
  357. Assert("#E38", copy[3] != orig[3]);
  358. }
  359. public void TestCopyTo() {
  360. {
  361. bool errorThrown = false;
  362. try {
  363. Char[] c1 = new Char[2];
  364. c1.CopyTo(null, 2);
  365. } catch (ArgumentNullException) {
  366. errorThrown = true;
  367. }
  368. Assert("#E61", errorThrown);
  369. }
  370. {
  371. bool errorThrown = false;
  372. try {
  373. Char[] c1 = new Char[2];
  374. Char[,] c2 = new Char[2,2];
  375. c1.CopyTo(c2, 2);
  376. } catch (ArgumentException) {
  377. errorThrown = true;
  378. }
  379. Assert("#E62", errorThrown);
  380. }
  381. {
  382. bool errorThrown = false;
  383. try {
  384. Char[,] c1 = new Char[2,2];
  385. Char[] c2 = new Char[2];
  386. c1.CopyTo(c2, -1);
  387. } catch (RankException) {
  388. errorThrown = true;
  389. }
  390. Assert("#E63", errorThrown);
  391. }
  392. {
  393. bool errorThrown = false;
  394. try {
  395. Char[,] c1 = new Char[2,2];
  396. Char[] c2 = new Char[2];
  397. c1.CopyTo(c2, 2);
  398. } catch (RankException) {
  399. errorThrown = true;
  400. }
  401. Assert("#E64", errorThrown);
  402. }
  403. {
  404. bool errorThrown = false;
  405. try {
  406. Char[] c1 = new Char[2];
  407. Char[] c2 = new Char[2];
  408. c1.CopyTo(c2, -1);
  409. } catch (ArgumentOutOfRangeException) {
  410. errorThrown = true;
  411. }
  412. Assert("#E65", errorThrown);
  413. }
  414. {
  415. bool errorThrown = false;
  416. try {
  417. Char[] c1 = new Char[2];
  418. Char[] c2 = new Char[2];
  419. c1.CopyTo(c2, 3);
  420. } catch (ArgumentException) {
  421. errorThrown = true;
  422. }
  423. Assert("#E66", errorThrown);
  424. }
  425. {
  426. bool errorThrown = false;
  427. try {
  428. Char[] c1 = new Char[2];
  429. Char[] c2 = new Char[2];
  430. c1.CopyTo(c2, 1);
  431. } catch (ArgumentException) {
  432. errorThrown = true;
  433. }
  434. Assert("#E67", errorThrown);
  435. }
  436. {
  437. bool errorThrown = false;
  438. try {
  439. String[] c1 = new String[2];
  440. Char[] c2 = new Char[2];
  441. c1.CopyTo(c2, 0);
  442. } catch (ArrayTypeMismatchException) {
  443. errorThrown = true;
  444. }
  445. Assert("#E68", errorThrown);
  446. }
  447. Char[] orig = {'a', 'b', 'c', 'd'};
  448. Char[] copy = new Char[10];
  449. Array.Clear(copy, 0, copy.Length);
  450. orig.CopyTo(copy, 3);
  451. AssertEquals("#E69", (char)0, copy[0]);
  452. AssertEquals("#E70", (char)0, copy[1]);
  453. AssertEquals("#E71", (char)0, copy[2]);
  454. AssertEquals("#E72", orig[0], copy[3]);
  455. AssertEquals("#E73", orig[1], copy[4]);
  456. AssertEquals("#E74", orig[2], copy[5]);
  457. AssertEquals("#E75", orig[3], copy[6]);
  458. AssertEquals("#E76", (char)0, copy[7]);
  459. AssertEquals("#E77", (char)0, copy[8]);
  460. AssertEquals("#E78", (char)0, copy[9]);
  461. {
  462. // The following is valid and must not throw an exception.
  463. bool errorThrown = false;
  464. try {
  465. int[] src = new int [0];
  466. int[] dest = new int [0];
  467. src.CopyTo (dest, 0);
  468. } catch (ArgumentException) {
  469. errorThrown = true;
  470. }
  471. Assert("#E79", !errorThrown);
  472. }
  473. }
  474. public void TestCreateInstance() {
  475. {
  476. bool errorThrown = false;
  477. try {
  478. Array.CreateInstance(null, 12);
  479. } catch (ArgumentNullException) {
  480. errorThrown = true;
  481. }
  482. Assert("#F01", errorThrown);
  483. }
  484. {
  485. bool errorThrown = false;
  486. try {
  487. Array.CreateInstance(Type.GetType("System.Char"), -3);
  488. } catch (ArgumentOutOfRangeException) {
  489. errorThrown = true;
  490. }
  491. Assert("#F02", errorThrown);
  492. }
  493. {
  494. bool errorThrown = false;
  495. try {
  496. Array.CreateInstance(Type.GetType("System.Char"), null);
  497. } catch (ArgumentNullException) {
  498. errorThrown = true;
  499. }
  500. Assert("#F03", errorThrown);
  501. }
  502. {
  503. bool errorThrown = false;
  504. try {
  505. Array.CreateInstance(Type.GetType("System.Char"), null, null);
  506. } catch (ArgumentNullException) {
  507. errorThrown = true;
  508. }
  509. Assert("#F04", errorThrown);
  510. }
  511. {
  512. bool errorThrown = false;
  513. try {
  514. int[] lengths = new int [0];
  515. Array.CreateInstance(Type.GetType("System.Char"), lengths);
  516. } catch (ArgumentException) {
  517. errorThrown = true;
  518. }
  519. Assert("#F05", errorThrown);
  520. }
  521. {
  522. bool errorThrown = false;
  523. try {
  524. int[] lengths = new int [1];
  525. int[] bounds = new int [2];
  526. Array.CreateInstance(Type.GetType("System.Char"), lengths, bounds);
  527. errorThrown = true;
  528. } catch (ArgumentException) {
  529. errorThrown = true;
  530. }
  531. Assert("#F06", errorThrown);
  532. }
  533. char[] c1 = (char[])Array.CreateInstance(Type.GetType("System.Char"), 12);
  534. AssertEquals("#F07", 12, c1.Length);
  535. Array c2 = Array.CreateInstance(Type.GetType("System.Char"), 12, 5);
  536. AssertEquals("#F08", 2, c2.Rank);
  537. AssertEquals("#F09", 60, c2.Length);
  538. {
  539. int[] lengths = { 3 };
  540. int[] bounds = { 5 };
  541. int[] src = { 512, 718, 912 };
  542. Array array = Array.CreateInstance(typeof(int), lengths, bounds);
  543. AssertEquals("#F10", 3, array.Length);
  544. AssertEquals("#F11", 5, array.GetLowerBound(0));
  545. AssertEquals("#F12", 7, array.GetUpperBound(0));
  546. src.CopyTo (array, 5);
  547. for (int i = 0; i < src.Length; i++)
  548. AssertEquals("#F13(" + i + ")", src[i], array.GetValue(i+5));
  549. }
  550. }
  551. public void TestGetEnumerator() {
  552. String[] s1 = {"this", "is", "a", "test"};
  553. IEnumerator en = s1.GetEnumerator ();
  554. AssertNotNull ("#G01", en);
  555. Assert ("#G02", en.MoveNext ());
  556. AssertEquals ("#G03", "this", en.Current);
  557. Assert ("#G04", en.MoveNext ());
  558. AssertEquals ("#G05", "is", en.Current);
  559. Assert ("#G06", en.MoveNext ());
  560. AssertEquals ("#G07", "a", en.Current);
  561. Assert ("#G08", en.MoveNext ());
  562. AssertEquals ("#G09", "test", en.Current);
  563. Assert ("#G10", !en.MoveNext ());
  564. en.Reset ();
  565. Assert("#G11", en.MoveNext ());
  566. AssertEquals ("#G12", "this", en.Current);
  567. // mutation does not invalidate array enumerator!
  568. s1.SetValue ("change", 1);
  569. Assert ("#G13", en.MoveNext ());
  570. AssertEquals ("#G14", "change", en.Current);
  571. }
  572. public void TestGetEnumeratorMultipleDimension() {
  573. String[,] s1 = {{"this", "is"}, {"a", "test"}};
  574. IEnumerator en = s1.GetEnumerator ();
  575. AssertNotNull ("#AA01", en);
  576. Assert ("#AA02", en.MoveNext ());
  577. AssertEquals ("#AA03", "this", en.Current);
  578. Assert ("#AA04", en.MoveNext ());
  579. AssertEquals ("#AA05", "is", en.Current);
  580. Assert ("#AA06", en.MoveNext ());
  581. AssertEquals ("#AA07", "a", en.Current);
  582. Assert ("#AA08", en.MoveNext ());
  583. AssertEquals ("#AA09", "test", en.Current);
  584. Assert ("#AA10", !en.MoveNext ());
  585. en.Reset ();
  586. Assert("#AA11", en.MoveNext ());
  587. AssertEquals ("#AA12", "this", en.Current);
  588. int[] idxs = {0,1};
  589. // mutation does not invalidate array enumerator!
  590. s1.SetValue ("change", idxs);
  591. Assert ("#AA13", en.MoveNext ());
  592. AssertEquals ("#AA14", "change", en.Current);
  593. }
  594. public void TestGetEnumeratorNonZeroLowerBounds() {
  595. int[] myLengthsArray = new int[2] { 3, 5 };
  596. int[] myBoundsArray = new int[2] { 2, 3 };
  597. Array myArray=Array.CreateInstance( typeof(String), myLengthsArray, myBoundsArray );
  598. for ( int i = myArray.GetLowerBound(0); i <= myArray.GetUpperBound(0); i++ )
  599. for ( int j = myArray.GetLowerBound(1); j <= myArray.GetUpperBound(1); j++ ) {
  600. int[] myIndicesArray = new int[2] { i, j };
  601. myArray.SetValue( Convert.ToString(i) + j, myIndicesArray );
  602. }
  603. IEnumerator en = myArray.GetEnumerator ();
  604. AssertNotNull ("#AB01", en);
  605. // check the first couple of values
  606. Assert ("#AB02", en.MoveNext ());
  607. AssertEquals ("#AB03", "23", en.Current);
  608. Assert ("#AB04", en.MoveNext ());
  609. AssertEquals ("#AB05", "24", en.Current);
  610. // then check the last element's value
  611. string lastElement;
  612. do {
  613. lastElement = (string)en.Current;
  614. } while (en.MoveNext());
  615. AssertEquals ("#AB06", "47", lastElement);
  616. }
  617. public void TestIList_Add () {
  618. int[] myLengthsArray = new int[2] { 3, 5 };
  619. int[] myBoundsArray = new int[2] { 2, 3 };
  620. Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
  621. try {
  622. ((IList)myArray).Add ("can not");
  623. Fail ("IList.Add should throw");
  624. }
  625. catch (NotSupportedException) {
  626. return;
  627. }
  628. catch (Exception) {
  629. Fail ("IList.Add threw wrong exception type");
  630. }
  631. Fail("IList.Add shouldn't get this far");
  632. }
  633. public void TestIList_Insert () {
  634. int[] myLengthsArray = new int[2] { 3, 5 };
  635. int[] myBoundsArray = new int[2] { 2, 3 };
  636. Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
  637. try {
  638. ((IList)myArray).Insert (0, "can not");
  639. Fail ("IList.Insert should throw");
  640. }
  641. catch (NotSupportedException) {
  642. return;
  643. }
  644. catch (Exception) {
  645. Fail ("IList.Insert threw wrong exception type");
  646. }
  647. Fail("IList.Insert shouldn't get this far");
  648. }
  649. public void TestIList_Remove () {
  650. int[] myLengthsArray = new int[2] { 3, 5 };
  651. int[] myBoundsArray = new int[2] { 2, 3 };
  652. Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
  653. try {
  654. ((IList)myArray).Remove ("can not");
  655. Fail ("IList.Remove should throw");
  656. }
  657. catch (NotSupportedException) {
  658. return;
  659. }
  660. catch (Exception) {
  661. Fail ("IList.Remove threw wrong exception type");
  662. }
  663. Fail("IList.Remove shouldn't get this far");
  664. }
  665. public void TestIList_RemoveAt () {
  666. int[] myLengthsArray = new int[2] { 3, 5 };
  667. int[] myBoundsArray = new int[2] { 2, 3 };
  668. Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
  669. try {
  670. ((IList)myArray).RemoveAt (0);
  671. Fail ("IList.RemoveAt should throw");
  672. }
  673. catch (NotSupportedException) {
  674. return;
  675. }
  676. catch (Exception) {
  677. Fail ("IList.RemoveAt threw wrong exception type");
  678. }
  679. Fail("IList.RemoveAt shouldn't get this far");
  680. }
  681. public void TestIList_Contains () {
  682. int[] myLengthsArray = new int[2] { 3, 5 };
  683. int[] myBoundsArray = new int[2] { 2, 3 };
  684. Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
  685. try {
  686. bool b = ((IList)myArray).Contains ("23");
  687. Fail("IList.Contains should throw with multi-dimensional arrays");
  688. }
  689. catch (RankException) {
  690. int[] iArr = new int[3] { 1, 2, 3};
  691. // check the first and last items
  692. Assert("AC01", ((IList)iArr).Contains (1));
  693. Assert("AC02", ((IList)iArr).Contains (3));
  694. // and one that is definately not there
  695. Assert("AC03", !((IList)iArr).Contains (42));
  696. return;
  697. }
  698. Fail("Should not get here");
  699. }
  700. public void TestIList_IndexOf () {
  701. int[] myLengthsArray = new int[2] { 3, 5 };
  702. int[] myBoundsArray = new int[2] { 2, 3 };
  703. Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
  704. try {
  705. bool b = ((IList)myArray).Contains ("23");
  706. Fail("IList.Contains should throw with multi-dimensional arrays");
  707. }
  708. catch (RankException) {
  709. int[] iArr = new int[3] { 1, 2, 3};
  710. // check the first and last items
  711. AssertEquals("AD01", 0, ((IList)iArr).IndexOf (1));
  712. AssertEquals("AD02", 2, ((IList)iArr).IndexOf (3));
  713. // and one that is definately not there
  714. AssertEquals("AD03", -1, ((IList)iArr).IndexOf (42));
  715. }
  716. catch (Exception e) {
  717. Fail("Unexpected exception: " + e.ToString());
  718. }
  719. // check that wierd case whem lowerbound is Int32.MinValue,
  720. // so that IndexOf() needs to return Int32.MaxValue when it cannot find the object
  721. int[] myLengthArray = new int[1] { 3 };
  722. int[] myBoundArray = new int[1] { Int32.MinValue };
  723. Array myExtremeArray=Array.CreateInstance ( typeof(String), myLengthArray, myBoundArray );
  724. AssertEquals("AD04", Int32.MaxValue, ((IList)myExtremeArray).IndexOf (42));
  725. }
  726. public void TestGetLength() {
  727. {
  728. bool errorThrown = false;
  729. try {
  730. char[] c1 = {'a', 'b', 'c'};
  731. c1.GetLength(-1);
  732. } catch (IndexOutOfRangeException) {
  733. errorThrown = true;
  734. }
  735. Assert("#H01", errorThrown);
  736. }
  737. {
  738. bool errorThrown = false;
  739. try {
  740. char[] c1 = {'a', 'b', 'c'};
  741. c1.GetLength(1);
  742. } catch (IndexOutOfRangeException) {
  743. errorThrown = true;
  744. }
  745. Assert("#H02", errorThrown);
  746. }
  747. char[] c2 = new Char[5];
  748. AssertEquals("#H03",
  749. 5, c2.GetLength(0));
  750. char[,] c3 = new Char[6,7];
  751. AssertEquals("#H04",
  752. 6, c3.GetLength(0));
  753. AssertEquals("#H05",
  754. 7, c3.GetLength(1));
  755. }
  756. public void TestGetLowerBound() {
  757. {
  758. bool errorThrown = false;
  759. try {
  760. char[] c = {'a', 'b', 'c'};
  761. c.GetLowerBound(-1);
  762. } catch (IndexOutOfRangeException) {
  763. errorThrown = true;
  764. }
  765. Assert("#H31", errorThrown);
  766. }
  767. {
  768. bool errorThrown = false;
  769. try {
  770. char[] c = {'a', 'b', 'c'};
  771. c.GetLowerBound(1);
  772. } catch (IndexOutOfRangeException) {
  773. errorThrown = true;
  774. }
  775. Assert("#H32", errorThrown);
  776. }
  777. char[] c1 = new Char[5];
  778. AssertEquals("#H33",
  779. 0, c1.GetLowerBound(0));
  780. char[,] c2 = new Char[4,4];
  781. AssertEquals("#H34",
  782. 0, c2.GetLowerBound(0));
  783. AssertEquals("#H35",
  784. 0, c2.GetLowerBound(1));
  785. }
  786. public void TestGetUpperBound() {
  787. {
  788. bool errorThrown = false;
  789. try {
  790. char[] c = {'a', 'b', 'c'};
  791. c.GetUpperBound(-1);
  792. } catch (IndexOutOfRangeException) {
  793. errorThrown = true;
  794. }
  795. Assert("#H61", errorThrown);
  796. }
  797. {
  798. bool errorThrown = false;
  799. try {
  800. char[] c = {'a', 'b', 'c'};
  801. c.GetUpperBound(1);
  802. } catch (IndexOutOfRangeException) {
  803. errorThrown = true;
  804. }
  805. Assert("#H62", errorThrown);
  806. }
  807. char[] c1 = new Char[5];
  808. AssertEquals("#H63",
  809. 4, c1.GetUpperBound(0));
  810. char[,] c2 = new Char[4,6];
  811. AssertEquals("#H64",
  812. 3, c2.GetUpperBound(0));
  813. AssertEquals("#H65",
  814. 5, c2.GetUpperBound(1));
  815. }
  816. public void TestGetValue1() {
  817. {
  818. bool errorThrown = false;
  819. try {
  820. char[,] c = new Char[2,2];
  821. c.GetValue(1);
  822. } catch (ArgumentException) {
  823. errorThrown = true;
  824. }
  825. Assert("#I01", errorThrown);
  826. }
  827. {
  828. bool errorThrown = false;
  829. try {
  830. char[] c = {'a', 'b', 'c'};
  831. c.GetValue(-1);
  832. } catch (IndexOutOfRangeException) {
  833. errorThrown = true;
  834. }
  835. Assert("#I02", errorThrown);
  836. }
  837. {
  838. bool errorThrown = false;
  839. try {
  840. char[] c = {'a', 'b', 'c'};
  841. c.GetValue(4);
  842. } catch (IndexOutOfRangeException) {
  843. errorThrown = true;
  844. }
  845. Assert("#I03", errorThrown);
  846. }
  847. char[] c1 = {'a', 'b', 'c', 'd'};
  848. for (int i = 0; i < c1.Length; i++) {
  849. AssertEquals("#I04(" + i + ")", c1[i], c1.GetValue(i));
  850. }
  851. }
  852. public void TestGetValue2() {
  853. {
  854. bool errorThrown = false;
  855. try {
  856. char[] c = new Char[2];
  857. c.GetValue(1,1);
  858. } catch (ArgumentException) {
  859. errorThrown = true;
  860. }
  861. Assert("#I21", errorThrown);
  862. }
  863. {
  864. bool errorThrown = false;
  865. try {
  866. char[,] c = new Char[2,2];
  867. c.GetValue(-1, 1);
  868. } catch (IndexOutOfRangeException) {
  869. errorThrown = true;
  870. }
  871. Assert("#I22", errorThrown);
  872. }
  873. {
  874. bool errorThrown = false;
  875. try {
  876. char[,] c = new Char[2,2];
  877. c.GetValue(4,1);
  878. } catch (IndexOutOfRangeException) {
  879. errorThrown = true;
  880. }
  881. Assert("#I23", errorThrown);
  882. }
  883. char[,] c1 = new Char[4,6];
  884. for (int i = 0; i < 24; i++) {
  885. int first = i / 6;
  886. int second = i % 6;
  887. c1[first,second] = (char)(((int)'a')+i);
  888. }
  889. for (int i = 0; i < c1.GetLength(0); i++) {
  890. for (int j = 0; j < c1.GetLength(1); j++) {
  891. AssertEquals("#I24(" + i + "," + j + ")",
  892. c1[i,j], c1.GetValue(i, j));
  893. }
  894. }
  895. }
  896. public void TestGetValue3() {
  897. {
  898. bool errorThrown = false;
  899. try {
  900. char[] c = new Char[2];
  901. c.GetValue(1,1,1);
  902. } catch (ArgumentException) {
  903. errorThrown = true;
  904. }
  905. Assert("#I41", errorThrown);
  906. }
  907. {
  908. bool errorThrown = false;
  909. try {
  910. char[,,] c = new Char[2,2,2];
  911. c.GetValue(-1, 1, 1);
  912. } catch (IndexOutOfRangeException) {
  913. errorThrown = true;
  914. }
  915. Assert("#I42", errorThrown);
  916. }
  917. {
  918. bool errorThrown = false;
  919. try {
  920. char[,,] c = new Char[2,2,2];
  921. c.GetValue(4,1,1);
  922. } catch (IndexOutOfRangeException) {
  923. errorThrown = true;
  924. }
  925. Assert("#I43", errorThrown);
  926. }
  927. char[,,] c1 = new Char[4,2,3];
  928. for (int i = 0; i < 24; i++) {
  929. int first = i / 6;
  930. int remains = i % 6;
  931. int second = remains / 3;
  932. int third = remains % 3;
  933. c1[first,second, third] = (char)(((int)'a')+i);
  934. }
  935. for (int i = 0; i < c1.GetLength(0); i++) {
  936. for (int j = 0; j < c1.GetLength(1); j++) {
  937. for (int k = 0; k < c1.GetLength(2); k++) {
  938. AssertEquals("#I44(" + i + "," + j + ")",
  939. c1[i,j,k], c1.GetValue(i,j,k));
  940. }
  941. }
  942. }
  943. }
  944. public void TestGetValueN() {
  945. {
  946. bool errorThrown = false;
  947. try {
  948. char[] c = new Char[2];
  949. c.GetValue(null);
  950. } catch (ArgumentNullException) {
  951. errorThrown = true;
  952. }
  953. Assert("#I61", errorThrown);
  954. }
  955. {
  956. bool errorThrown = false;
  957. try {
  958. char[] c = new Char[2];
  959. int[] coords = {1, 1};
  960. c.GetValue(coords);
  961. } catch (ArgumentException) {
  962. errorThrown = true;
  963. }
  964. Assert("#I62", errorThrown);
  965. }
  966. {
  967. bool errorThrown = false;
  968. try {
  969. char[,] c = new Char[2,2];
  970. int[] coords = {-1, 1};
  971. c.GetValue(coords);
  972. } catch (IndexOutOfRangeException) {
  973. errorThrown = true;
  974. }
  975. Assert("#I63", errorThrown);
  976. }
  977. {
  978. bool errorThrown = false;
  979. try {
  980. char[,] c = new Char[2,2];
  981. int[] coords = {4, 1};
  982. c.GetValue(coords);
  983. } catch (IndexOutOfRangeException) {
  984. errorThrown = true;
  985. }
  986. Assert("#I64", errorThrown);
  987. }
  988. char[,] c1 = new Char[4,6];
  989. for (int i = 0; i < 24; i++) {
  990. int first = i / 6;
  991. int second = i % 6;
  992. c1[first,second] = (char)(((int)'a')+i);
  993. }
  994. for (int i = 0; i < c1.GetLength(0); i++) {
  995. for (int j = 0; j < c1.GetLength(1); j++) {
  996. int[] coords = {i, j};
  997. AssertEquals("#I65(" + i + "," + j + ")",
  998. c1[i,j], c1.GetValue(coords));
  999. }
  1000. }
  1001. }
  1002. public void TestIndexOf1() {
  1003. {
  1004. bool errorThrown = false;
  1005. try {
  1006. Array.IndexOf(null, "huh?");
  1007. } catch (ArgumentNullException) {
  1008. errorThrown = true;
  1009. }
  1010. Assert("#J01", errorThrown);
  1011. }
  1012. {
  1013. bool errorThrown = false;
  1014. try {
  1015. char[,] c = new Char[2,2];
  1016. Array.IndexOf(c, "huh?");
  1017. } catch (RankException) {
  1018. errorThrown = true;
  1019. }
  1020. Assert("#J02", errorThrown);
  1021. }
  1022. String[] s1 = {"this", "is", "a", "test"};
  1023. AssertEquals("#J03", -1, Array.IndexOf(s1, null));
  1024. AssertEquals("#J04", -1, Array.IndexOf(s1, "nothing"));
  1025. AssertEquals("#J05", 0, Array.IndexOf(s1, "this"));
  1026. AssertEquals("#J06", 3, Array.IndexOf(s1, "test"));
  1027. }
  1028. public void TestIndexOf2() {
  1029. {
  1030. bool errorThrown = false;
  1031. try {
  1032. Array.IndexOf(null, "huh?", 0);
  1033. } catch (ArgumentNullException) {
  1034. errorThrown = true;
  1035. }
  1036. Assert("#J21", errorThrown);
  1037. }
  1038. {
  1039. bool errorThrown = false;
  1040. try {
  1041. char[,] c = new Char[2,2];
  1042. Array.IndexOf(c, "huh?", 0);
  1043. } catch (RankException) {
  1044. errorThrown = true;
  1045. }
  1046. Assert("#J22", errorThrown);
  1047. }
  1048. {
  1049. bool errorThrown = false;
  1050. try {
  1051. char[] c = new Char[2];
  1052. Array.IndexOf(c, "huh?", 3);
  1053. } catch (ArgumentOutOfRangeException) {
  1054. errorThrown = true;
  1055. }
  1056. Assert("#J23", errorThrown);
  1057. }
  1058. String[] s1 = {"this", "is", "really", "a", "test"};
  1059. AssertEquals("#J24", -1, Array.IndexOf(s1, null, 1));
  1060. AssertEquals("#J25", -1, Array.IndexOf(s1, "nothing", 1));
  1061. AssertEquals("#J26", -1, Array.IndexOf(s1, "this", 1));
  1062. AssertEquals("#J27", 1, Array.IndexOf(s1, "is", 1));
  1063. AssertEquals("#J28", 4, Array.IndexOf(s1, "test", 1));
  1064. }
  1065. public void TestIndexOf3() {
  1066. {
  1067. bool errorThrown = false;
  1068. try {
  1069. Array.IndexOf(null, "huh?", 0, 1);
  1070. } catch (ArgumentNullException) {
  1071. errorThrown = true;
  1072. }
  1073. Assert("#J41", errorThrown);
  1074. }
  1075. {
  1076. bool errorThrown = false;
  1077. try {
  1078. char[,] c = new Char[2,2];
  1079. Array.IndexOf(c, "huh?", 0, 1);
  1080. } catch (RankException) {
  1081. errorThrown = true;
  1082. }
  1083. Assert("#J42", errorThrown);
  1084. }
  1085. {
  1086. bool errorThrown = false;
  1087. try {
  1088. char[] c = new Char[2];
  1089. Array.IndexOf(c, "huh?", 3, 1);
  1090. } catch (ArgumentOutOfRangeException) {
  1091. errorThrown = true;
  1092. }
  1093. Assert("#J43", errorThrown);
  1094. }
  1095. {
  1096. bool errorThrown = false;
  1097. try {
  1098. char[] c = new Char[2];
  1099. Array.IndexOf(c, "huh?", 0, 5);
  1100. } catch (ArgumentOutOfRangeException) {
  1101. errorThrown = true;
  1102. }
  1103. Assert("#J44", errorThrown);
  1104. }
  1105. String[] s1 = {"this", "is", "really", "a", "test"};
  1106. AssertEquals("#J45", -1, Array.IndexOf(s1, null, 1, 3));
  1107. AssertEquals("#J46", -1, Array.IndexOf(s1, "nothing", 1, 3));
  1108. AssertEquals("#J47", -1, Array.IndexOf(s1, "this", 1, 3));
  1109. AssertEquals("#J48", 1, Array.IndexOf(s1, "is", 1, 3));
  1110. AssertEquals("#J49", -1, Array.IndexOf(s1, "test", 1, 3));
  1111. AssertEquals("#J50", 3, Array.IndexOf(s1, "a", 1, 3));
  1112. }
  1113. public void TestLastIndexOf1() {
  1114. {
  1115. bool errorThrown = false;
  1116. try {
  1117. Array.LastIndexOf(null, "huh?");
  1118. } catch (ArgumentNullException) {
  1119. errorThrown = true;
  1120. }
  1121. Assert("#K01", errorThrown);
  1122. }
  1123. {
  1124. bool errorThrown = false;
  1125. try {
  1126. char[,] c = new Char[2,2];
  1127. Array.LastIndexOf(c, "huh?");
  1128. } catch (RankException) {
  1129. errorThrown = true;
  1130. }
  1131. Assert("#K02", errorThrown);
  1132. }
  1133. String[] s1 = {"this", "is", "a", "a", "test"};
  1134. AssertEquals("#K03", -1, Array.LastIndexOf(s1, null));
  1135. AssertEquals("#K04", -1, Array.LastIndexOf(s1, "nothing"));
  1136. AssertEquals("#K05", 0, Array.LastIndexOf(s1, "this"));
  1137. AssertEquals("#K06", 4, Array.LastIndexOf(s1, "test"));
  1138. AssertEquals("#K07", 3, Array.LastIndexOf(s1, "a"));
  1139. }
  1140. public void TestLastIndexOf2() {
  1141. {
  1142. bool errorThrown = false;
  1143. try {
  1144. Array.LastIndexOf(null, "huh?", 0);
  1145. } catch (ArgumentNullException) {
  1146. errorThrown = true;
  1147. }
  1148. Assert("#K21", errorThrown);
  1149. }
  1150. {
  1151. bool errorThrown = false;
  1152. try {
  1153. char[,] c = new Char[2,2];
  1154. Array.LastIndexOf(c, "huh?", 0);
  1155. } catch (RankException) {
  1156. errorThrown = true;
  1157. }
  1158. Assert("#K22", errorThrown);
  1159. }
  1160. {
  1161. bool errorThrown = false;
  1162. try {
  1163. char[] c = new Char[2];
  1164. Array.LastIndexOf(c, "huh?", 3);
  1165. } catch (ArgumentOutOfRangeException) {
  1166. errorThrown = true;
  1167. }
  1168. Assert("#K23", errorThrown);
  1169. }
  1170. String[] s1 = {"this", "is", "really", "a", "test"};
  1171. AssertEquals("#K24", -1, Array.LastIndexOf(s1, null, 3));
  1172. AssertEquals("#K25", -1, Array.LastIndexOf(s1, "nothing", 3));
  1173. AssertEquals("#K26", -1, Array.LastIndexOf(s1, "test", 3));
  1174. AssertEquals("#K27", 3, Array.LastIndexOf(s1, "a", 3));
  1175. AssertEquals("#K28", 0, Array.LastIndexOf(s1, "this", 3));
  1176. }
  1177. public void TestLastIndexOf3() {
  1178. {
  1179. bool errorThrown = false;
  1180. try {
  1181. Array.LastIndexOf(null, "huh?", 0, 1);
  1182. } catch (ArgumentNullException) {
  1183. errorThrown = true;
  1184. }
  1185. Assert("#K41", errorThrown);
  1186. }
  1187. {
  1188. bool errorThrown = false;
  1189. try {
  1190. char[,] c = new Char[2,2];
  1191. Array.LastIndexOf(c, "huh?", 0, 1);
  1192. } catch (RankException) {
  1193. errorThrown = true;
  1194. }
  1195. Assert("#K42", errorThrown);
  1196. }
  1197. {
  1198. bool errorThrown = false;
  1199. try {
  1200. char[] c = new Char[2];
  1201. Array.LastIndexOf(c, "huh?", 3, 1);
  1202. } catch (ArgumentOutOfRangeException) {
  1203. errorThrown = true;
  1204. }
  1205. Assert("#K43", errorThrown);
  1206. }
  1207. {
  1208. bool errorThrown = false;
  1209. try {
  1210. char[] c = new Char[2];
  1211. Array.LastIndexOf(c, "huh?", 0, 5);
  1212. } catch (ArgumentOutOfRangeException) {
  1213. errorThrown = true;
  1214. }
  1215. Assert("#K44", errorThrown);
  1216. }
  1217. String[] s1 = {"this", "is", "really", "a", "test"};
  1218. AssertEquals("#K45",
  1219. -1, Array.LastIndexOf(s1, null, 3, 3));
  1220. AssertEquals("#K46",
  1221. -1, Array.LastIndexOf(s1, "nothing", 3, 3));
  1222. AssertEquals("#K47",
  1223. -1, Array.LastIndexOf(s1, "this", 3, 3));
  1224. AssertEquals("#K48",
  1225. 1, Array.LastIndexOf(s1, "is", 3, 3));
  1226. AssertEquals("#K49",
  1227. -1, Array.LastIndexOf(s1, "test", 3, 3));
  1228. AssertEquals("#K50",
  1229. 3, Array.LastIndexOf(s1, "a", 3, 3));
  1230. }
  1231. public void TestReverse() {
  1232. {
  1233. bool errorThrown = false;
  1234. try {
  1235. Array.Reverse(null);
  1236. } catch (ArgumentNullException) {
  1237. errorThrown = true;
  1238. }
  1239. Assert("#L01", errorThrown);
  1240. }
  1241. {
  1242. bool errorThrown = false;
  1243. try {
  1244. char[,] c = new Char[2,2];
  1245. Array.Reverse(c);
  1246. } catch (RankException) {
  1247. errorThrown = true;
  1248. }
  1249. Assert("#L02", errorThrown);
  1250. }
  1251. char[] c1 = {'a', 'b', 'c', 'd'};
  1252. Array.Reverse(c1);
  1253. AssertEquals("#L03", 'd', c1[0]);
  1254. AssertEquals("#L04", 'c', c1[1]);
  1255. AssertEquals("#L05", 'b', c1[2]);
  1256. AssertEquals("#L06", 'a', c1[3]);
  1257. {
  1258. bool errorThrown = false;
  1259. try {
  1260. Array.Reverse(null, 0, 0);
  1261. } catch (ArgumentNullException) {
  1262. errorThrown = true;
  1263. }
  1264. Assert("#L07", errorThrown);
  1265. }
  1266. {
  1267. bool errorThrown = false;
  1268. try {
  1269. char[,] c = new Char[2,2];
  1270. Array.Reverse(c, 0, 0);
  1271. } catch (RankException) {
  1272. errorThrown = true;
  1273. }
  1274. Assert("#L08", errorThrown);
  1275. }
  1276. //{
  1277. //bool errorThrown = false;
  1278. //try {
  1279. // char[] c = new Char[2];
  1280. // Array.Reverse(c, 0, 3);
  1281. //} catch (ArgumentOutOfRangeException) {
  1282. // errorThrown = true;
  1283. //}
  1284. //Assert("#L09", errorThrown);
  1285. //}
  1286. //{
  1287. //bool errorThrown = false;
  1288. //try {
  1289. // char[] c = new Char[2];
  1290. // Array.Reverse(c, 3, 0);
  1291. //} catch (ArgumentOutOfRangeException) {
  1292. // errorThrown = true;
  1293. //}
  1294. //Assert("#L10", errorThrown);
  1295. //}
  1296. char[] c2 = { 'a', 'b', 'c', 'd'};
  1297. Array.Reverse(c2, 1, 2);
  1298. AssertEquals("#L11", 'a', c2[0]);
  1299. AssertEquals("#L12", 'c', c2[1]);
  1300. AssertEquals("#L13", 'b', c2[2]);
  1301. AssertEquals("#L14", 'd', c2[3]);
  1302. }
  1303. public void TestSetValue1() {
  1304. {
  1305. bool errorThrown = false;
  1306. try {
  1307. char[,] c = new Char[2,2];
  1308. c.SetValue("buh", 1);
  1309. } catch (ArgumentException) {
  1310. errorThrown = true;
  1311. }
  1312. Assert("#M01", errorThrown);
  1313. }
  1314. {
  1315. bool errorThrown = false;
  1316. try {
  1317. char[] c = {'a', 'b', 'c'};
  1318. c.SetValue("buh", -1);
  1319. } catch (IndexOutOfRangeException) {
  1320. errorThrown = true;
  1321. }
  1322. Assert("#M02", errorThrown);
  1323. }
  1324. {
  1325. bool errorThrown = false;
  1326. try {
  1327. char[] c = {'a', 'b', 'c'};
  1328. c.SetValue("buh", 4);
  1329. } catch (IndexOutOfRangeException) {
  1330. errorThrown = true;
  1331. }
  1332. Assert("#M03", errorThrown);
  1333. }
  1334. char[] c1 = {'a', 'b', 'c', 'd'};
  1335. char[] c2 = new char[4];
  1336. for (int i = 0; i < c1.Length; i++) {
  1337. c2.SetValue(c1[i], i);
  1338. }
  1339. for (int i = 0; i < c1.Length; i++) {
  1340. AssertEquals("#M04(" + i + ")", c1[i], c2[i]);
  1341. }
  1342. int[] c3 = { 1, 2, 3 };
  1343. long[] c4 = new long [3];
  1344. for (int i = 0; i < c3.Length; i++)
  1345. c4.SetValue (c3 [i], i);
  1346. try {
  1347. c3.CopyTo (c4, 0);
  1348. } catch (Exception e) {
  1349. Fail ("c3.CopyTo(): e=" + e);
  1350. }
  1351. for (int i = 0; i < c3.Length; i++)
  1352. Assert ("#M05(" + i + ")", c3[i] == c4[i]);
  1353. Object[] c5 = new Object [3];
  1354. long[] c6 = new long [3];
  1355. try {
  1356. c4.CopyTo (c5, 0);
  1357. } catch (Exception e) {
  1358. Fail ("c4.CopyTo(): e=" + e);
  1359. }
  1360. try {
  1361. c5.CopyTo (c6, 0);
  1362. } catch (Exception e) {
  1363. Fail ("c5.CopyTo(): e=" + e);
  1364. }
  1365. // for (int i = 0; i < c5.Length; i++)
  1366. // Assert ("#M06(" + i + ")", c5[i] == c6[i]);
  1367. }
  1368. public void TestSetValue2() {
  1369. {
  1370. bool errorThrown = false;
  1371. try {
  1372. char[] c = new Char[2];
  1373. c.SetValue("buh", 1,1);
  1374. } catch (ArgumentException) {
  1375. errorThrown = true;
  1376. }
  1377. Assert("#M21", errorThrown);
  1378. }
  1379. {
  1380. bool errorThrown = false;
  1381. try {
  1382. char[,] c = new Char[2,2];
  1383. c.SetValue("buh", -1, 1);
  1384. } catch (IndexOutOfRangeException) {
  1385. errorThrown = true;
  1386. }
  1387. Assert("#M22", errorThrown);
  1388. }
  1389. {
  1390. bool errorThrown = false;
  1391. try {
  1392. char[,] c = new Char[2,2];
  1393. c.SetValue("buh", 4,1);
  1394. } catch (IndexOutOfRangeException) {
  1395. errorThrown = true;
  1396. }
  1397. Assert("#M23", errorThrown);
  1398. }
  1399. char[,] c1 = new Char[4,6];
  1400. char[,] c2 = new Char[4,6];
  1401. for (int i = 0; i < 24; i++) {
  1402. int first = i / 6;
  1403. int second = i % 6;
  1404. c1[first,second] = (char)(((int)'a')+i);
  1405. c2.SetValue(c1[first,second], first, second);
  1406. }
  1407. for (int i = 0; i < c1.GetLength(0); i++) {
  1408. for (int j = 0; j < c1.GetLength(1); j++) {
  1409. AssertEquals("#M24(" + i + "," + j + ")",
  1410. c1[i,j], c2[i, j]);
  1411. }
  1412. }
  1413. }
  1414. public void TestSetValue3() {
  1415. {
  1416. bool errorThrown = false;
  1417. try {
  1418. char[] c = new Char[2];
  1419. c.SetValue("buh", 1,1,1);
  1420. } catch (ArgumentException) {
  1421. errorThrown = true;
  1422. }
  1423. Assert("#M41", errorThrown);
  1424. }
  1425. {
  1426. bool errorThrown = false;
  1427. try {
  1428. char[,,] c = new Char[2,2,2];
  1429. c.SetValue("buh", -1, 1, 1);
  1430. } catch (IndexOutOfRangeException) {
  1431. errorThrown = true;
  1432. }
  1433. Assert("#M42", errorThrown);
  1434. }
  1435. {
  1436. bool errorThrown = false;
  1437. try {
  1438. char[,,] c = new Char[2,2,2];
  1439. c.SetValue("buh", 4,1,1);
  1440. } catch (IndexOutOfRangeException) {
  1441. errorThrown = true;
  1442. }
  1443. Assert("#M43", errorThrown);
  1444. }
  1445. char[,,] c1 = new Char[4,2,3];
  1446. char[,,] c2 = new Char[4,2,3];
  1447. for (int i = 0; i < 24; i++) {
  1448. int first = i / 6;
  1449. int remains = i % 6;
  1450. int second = remains / 3;
  1451. int third = remains % 3;
  1452. c1[first,second, third] = (char)(((int)'a')+i);
  1453. c2.SetValue(c1[first, second, third], first, second, third);
  1454. }
  1455. for (int i = 0; i < c1.GetLength(0); i++) {
  1456. for (int j = 0; j < c1.GetLength(1); j++) {
  1457. for (int k = 0; k < c1.GetLength(2); k++) {
  1458. AssertEquals("#M44(" + i + "," + j + " )",
  1459. c1[i,j,k], c2[i,j,k]);
  1460. }
  1461. }
  1462. }
  1463. }
  1464. public void TestSetValueN() {
  1465. {
  1466. bool errorThrown = false;
  1467. try {
  1468. char[] c = new Char[2];
  1469. c.SetValue("buh", null);
  1470. } catch (ArgumentNullException) {
  1471. errorThrown = true;
  1472. }
  1473. Assert("#M61", errorThrown);
  1474. }
  1475. {
  1476. bool errorThrown = false;
  1477. try {
  1478. char[] c = new Char[2];
  1479. int[] coords = {1, 1};
  1480. c.SetValue("buh", coords);
  1481. } catch (ArgumentException) {
  1482. errorThrown = true;
  1483. }
  1484. Assert("#M62", errorThrown);
  1485. }
  1486. {
  1487. bool errorThrown = false;
  1488. try {
  1489. char[,] c = new Char[2,2];
  1490. int[] coords = {-1, 1};
  1491. c.SetValue("buh", coords);
  1492. } catch (IndexOutOfRangeException) {
  1493. errorThrown = true;
  1494. }
  1495. Assert("#M63", errorThrown);
  1496. }
  1497. {
  1498. bool errorThrown = false;
  1499. try {
  1500. char[,] c = new Char[2,2];
  1501. int[] coords = {4, 1};
  1502. c.SetValue("buh", coords);
  1503. } catch (IndexOutOfRangeException) {
  1504. errorThrown = true;
  1505. }
  1506. Assert("#M64", errorThrown);
  1507. }
  1508. char[,] c1 = new Char[4,6];
  1509. char[,] c2 = new Char[4,6];
  1510. for (int i = 0; i < 24; i++) {
  1511. int first = i / 6;
  1512. int second = i % 6;
  1513. c1[first,second] = (char)(((int)'a')+i);
  1514. int[] coords = {first, second};
  1515. c2.SetValue(c1[first,second], coords);
  1516. }
  1517. for (int i = 0; i < c1.GetLength(0); i++) {
  1518. for (int j = 0; j < c1.GetLength(1); j++) {
  1519. AssertEquals("#M65(" + i + "," + j + ")",
  1520. c1[i,j], c2[i,j]);
  1521. }
  1522. }
  1523. }
  1524. public void TestSetValue4() {
  1525. {
  1526. int[] c1 = { 1, 2, 3 };
  1527. long[] c2 = new long [3];
  1528. for (int i = 0; i < c1.Length; i++)
  1529. c2.SetValue (c1 [i], i);
  1530. for (int i = 0; i < c1.Length; i++) {
  1531. Assert ("#M81(" + i + ")", c1[i] == c2[i]);
  1532. AssertEquals ("#M82(" + i + ")", typeof (long), c2[i].GetType ());
  1533. }
  1534. }
  1535. {
  1536. long[] c1 = { 1, 2, 3 };
  1537. int[] c2 = new int [3];
  1538. bool errorThrown = false;
  1539. try {
  1540. c2.SetValue (c1 [0], 0);
  1541. } catch (ArgumentException) {
  1542. errorThrown = true;
  1543. }
  1544. Assert("#M83", errorThrown);
  1545. }
  1546. {
  1547. int[] c1 = { 1, 2, 3 };
  1548. Object[] c2 = new Object [3];
  1549. for (int i = 0; i < c1.Length; i++)
  1550. c2.SetValue (c1 [i], i);
  1551. for (int i = 0; i < c1.Length; i++)
  1552. AssertEquals ("#M84(" + i + ")", c1[i], Convert.ToInt32 (c2[i]));
  1553. }
  1554. {
  1555. Object[] c1 = new Object [3];
  1556. Object[] c2 = new Object [3];
  1557. c1[0] = new Object ();
  1558. for (int i = 0; i < c1.Length; i++)
  1559. c2.SetValue (c1 [i], i);
  1560. for (int i = 0; i < c1.Length; i++)
  1561. AssertEquals ("#M85(" + i + ")", c1[i], c2[i]);
  1562. }
  1563. {
  1564. Object[] c1 = new Object [3];
  1565. string[] c2 = new String [3];
  1566. string test = "hello";
  1567. c1[0] = test;
  1568. c2.SetValue (c1 [0], 0);
  1569. AssertEquals ("#M86", c1[0], c2[0]);
  1570. AssertEquals ("#M87", "hello", c2[0]);
  1571. }
  1572. {
  1573. char[] c1 = { 'a', 'b', 'c' };
  1574. string[] c2 = new string [3];
  1575. try {
  1576. c2.SetValue (c1 [0], 0);
  1577. Fail ("#M88");
  1578. } catch (InvalidCastException) {}
  1579. }
  1580. {
  1581. Single[] c1 = { 1.2F, 2.3F, 3.4F, 4.5F };
  1582. long[] c2 = new long [3];
  1583. try {
  1584. c2.SetValue (c1 [0], 0);
  1585. Fail ("#M89");
  1586. } catch (ArgumentException) {}
  1587. }
  1588. {
  1589. Type[] types = {
  1590. typeof (Boolean),
  1591. typeof (Byte),
  1592. typeof (Char),
  1593. typeof (Double),
  1594. typeof (Int16),
  1595. typeof (Int32),
  1596. typeof (Int64),
  1597. typeof (SByte),
  1598. typeof (Single),
  1599. typeof (UInt16),
  1600. typeof (UInt32),
  1601. typeof (UInt64)
  1602. };
  1603. bool v1 = true;
  1604. Byte v2 = 1;
  1605. Char v3 = 'a';
  1606. Double v4 = -1.2;
  1607. Int16 v5 = -32;
  1608. Int32 v6 = -234;
  1609. Int64 v7 = -34523;
  1610. SByte v8 = -1;
  1611. Single v9 = -4.8F;
  1612. UInt16 v10 = 24234;
  1613. UInt32 v11 = 235354;
  1614. UInt64 v12 = 234552;
  1615. Object[] va1 = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 };
  1616. Object[] va2 = { "true", "1", "a", "-1.2", "-32", "-234", "-34523", "-1",
  1617. "-4.8F", "24234", "235354", "234552" };
  1618. Object[][] vt = { va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1 };
  1619. int[] arg_ex = {
  1620. 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1621. 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
  1622. 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
  1623. 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
  1624. 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1,
  1625. 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1,
  1626. 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1,
  1627. 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1,
  1628. 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1,
  1629. 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
  1630. 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0,
  1631. 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0
  1632. };
  1633. // SetValue
  1634. for (int i = 0; i < types.Length; i++) {
  1635. for (int j = 0; j < types.Length; j++) {
  1636. Array array = Array.CreateInstance (types [j], 2);
  1637. Object value = vt[j][i];
  1638. bool errorThrown = false;
  1639. try {
  1640. array.SetValue (value, 0);
  1641. } catch (ArgumentException) {
  1642. errorThrown = true;
  1643. }
  1644. int ex_index = (i * types.Length) + j;
  1645. AssertEquals ("#M90(" + types [i] + "," + types [j] + ")",
  1646. errorThrown, arg_ex [ex_index] == 1);
  1647. }
  1648. }
  1649. for (int i = 0; i < types.Length; i++) {
  1650. String[] array = new String [2];
  1651. Object value = va1 [i];
  1652. bool errorThrown = false;
  1653. try {
  1654. array.SetValue (value, 0);
  1655. } catch (InvalidCastException) {
  1656. errorThrown = true;
  1657. }
  1658. Assert ("#M91(" + types [i] + ")", errorThrown);
  1659. }
  1660. for (int i = 0; i < types.Length; i++) {
  1661. Array array = Array.CreateInstance (types [i], 2);
  1662. Object value = va2 [i];
  1663. bool errorThrown = false;
  1664. try {
  1665. array.SetValue (value, 0);
  1666. } catch (InvalidCastException) {
  1667. errorThrown = true;
  1668. }
  1669. Assert ("#M92(" + types [i] + ")", errorThrown);
  1670. }
  1671. for (int i = 0; i < types.Length; i++) {
  1672. Array array = Array.CreateInstance (types [i], 2);
  1673. Object value = null;
  1674. bool errorThrown = false;
  1675. try {
  1676. array.SetValue (value, 0);
  1677. } catch (InvalidCastException) {
  1678. errorThrown = true;
  1679. }
  1680. Assert ("#M93(" + types [i] + ")", !errorThrown);
  1681. }
  1682. // Copy
  1683. for (int i = 0; i < types.Length; i++) {
  1684. for (int j = 0; j < types.Length; j++) {
  1685. Array source = Array.CreateInstance (types [i], 2);
  1686. Array array = Array.CreateInstance (types [j], 2);
  1687. source.SetValue (vt[j][i], 0);
  1688. source.SetValue (vt[j][i], 1);
  1689. bool errorThrown = false;
  1690. try {
  1691. Array.Copy (source, array, 2);
  1692. } catch (ArrayTypeMismatchException) {
  1693. errorThrown = true;
  1694. }
  1695. int ex_index = (i * types.Length) + j;
  1696. AssertEquals ("#M94(" + types [i] + "," + types [j] + ")",
  1697. errorThrown, arg_ex [ex_index] == 1);
  1698. }
  1699. }
  1700. for (int i = 0; i < types.Length; i++) {
  1701. Array source = Array.CreateInstance (types [i], 2);
  1702. String[] array = new String [2];
  1703. source.SetValue (va1 [i], 0);
  1704. source.SetValue (va1 [i], 1);
  1705. bool errorThrown = false;
  1706. try {
  1707. Array.Copy (source, array, 2);
  1708. } catch (ArrayTypeMismatchException) {
  1709. errorThrown = true;
  1710. }
  1711. Assert ("#M95(" + types [i] + ")", errorThrown);
  1712. }
  1713. for (int i = 0; i < types.Length; i++) {
  1714. String[] source = new String [2];
  1715. Array array = Array.CreateInstance (types [i], 2);
  1716. source.SetValue (va2 [i], 0);
  1717. source.SetValue (va2 [i], 1);
  1718. bool errorThrown = false;
  1719. try {
  1720. Array.Copy (source, array, 2);
  1721. } catch (ArrayTypeMismatchException) {
  1722. errorThrown = true;
  1723. }
  1724. Assert ("#M96(" + types [i] + ")", errorThrown);
  1725. }
  1726. }
  1727. }
  1728. public void TestSort() {
  1729. {
  1730. bool errorThrown = false;
  1731. try {
  1732. Array.Sort(null);
  1733. } catch (ArgumentNullException) {
  1734. errorThrown = true;
  1735. }
  1736. Assert("#N01", errorThrown);
  1737. }
  1738. {
  1739. bool errorThrown = false;
  1740. try {
  1741. Array.Sort(null, 0, 1);
  1742. } catch (ArgumentNullException) {
  1743. errorThrown = true;
  1744. }
  1745. Assert("#N02", errorThrown);
  1746. }
  1747. {
  1748. bool errorThrown = false;
  1749. try {
  1750. char[] c1 = new Char[2];
  1751. Array.Sort(null, c1);
  1752. } catch (ArgumentNullException) {
  1753. errorThrown = true;
  1754. }
  1755. Assert("#N03", errorThrown);
  1756. }
  1757. {
  1758. bool errorThrown = false;
  1759. try {
  1760. char[] c1 = new Char[2];
  1761. Array.Sort(null, c1, 0, 1);
  1762. } catch (ArgumentNullException) {
  1763. errorThrown = true;
  1764. }
  1765. Assert("#N04", errorThrown);
  1766. }
  1767. // note: null second array => just sort first array
  1768. char[] starter = {'d', 'b', 'f', 'e', 'a', 'c'};
  1769. int[] starter1 = {1,2,3,4,5,6};
  1770. {
  1771. char[] c1 = (char[])starter.Clone();
  1772. Array.Sort(c1);
  1773. AssertEquals("#N21", 'a', c1[0]);
  1774. AssertEquals("#N22", 'b', c1[1]);
  1775. AssertEquals("#N23", 'c', c1[2]);
  1776. AssertEquals("#N24", 'd', c1[3]);
  1777. AssertEquals("#N25", 'e', c1[4]);
  1778. AssertEquals("#N26", 'f', c1[5]);
  1779. }
  1780. {
  1781. char[] c1 = (char[])starter.Clone();
  1782. int[] i1 = (int[])starter1.Clone();
  1783. Array.Sort(c1, i1);
  1784. AssertEquals("#N41", 'a', c1[0]);
  1785. AssertEquals("#N42", 'b', c1[1]);
  1786. AssertEquals("#N43", 'c', c1[2]);
  1787. AssertEquals("#N44", 'd', c1[3]);
  1788. AssertEquals("#N45", 'e', c1[4]);
  1789. AssertEquals("#N46", 'f', c1[5]);
  1790. AssertEquals("#N47", 5, i1[0]);
  1791. AssertEquals("#N48", 2, i1[1]);
  1792. AssertEquals("#N49", 6, i1[2]);
  1793. AssertEquals("#N50", 1, i1[3]);
  1794. AssertEquals("#N51", 4, i1[4]);
  1795. AssertEquals("#N52", 3, i1[5]);
  1796. }
  1797. {
  1798. char[] c1 = (char[])starter.Clone();
  1799. Array.Sort(c1, 1, 4);
  1800. AssertEquals("#N61", 'd', c1[0]);
  1801. AssertEquals("#N62", 'a', c1[1]);
  1802. AssertEquals("#N63", 'b', c1[2]);
  1803. AssertEquals("#N64", 'e', c1[3]);
  1804. AssertEquals("#N65", 'f', c1[4]);
  1805. AssertEquals("#N66", 'c', c1[5]);
  1806. }
  1807. {
  1808. char[] c1 = (char[])starter.Clone();
  1809. int[] i1 = (int[])starter1.Clone();
  1810. Array.Sort(c1, i1, 1, 4);
  1811. AssertEquals("#N81", 'd', c1[0]);
  1812. AssertEquals("#N82", 'a', c1[1]);
  1813. AssertEquals("#N83", 'b', c1[2]);
  1814. AssertEquals("#N84", 'e', c1[3]);
  1815. AssertEquals("#N85", 'f', c1[4]);
  1816. AssertEquals("#N86", 'c', c1[5]);
  1817. AssertEquals("#N87", 1, i1[0]);
  1818. AssertEquals("#N88", 5, i1[1]);
  1819. AssertEquals("#N89", 2, i1[2]);
  1820. AssertEquals("#N90", 4, i1[3]);
  1821. AssertEquals("#N91", 3, i1[4]);
  1822. AssertEquals("#N92", 6, i1[5]);
  1823. }
  1824. }
  1825. // TODO - TestSort passed-in IComparable versions
  1826. }
  1827. }