25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 

694 satır
19 KiB

  1. unit uutlListTest;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, TestFramework, contnrs,
  6. uTestHelper, uutlGenerics;
  7. type
  8. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. TIntList = specialize TutlList<Integer>;
  10. TIntfList = specialize TutlList<IUnknown>;
  11. TObjList = specialize TutlList<TObject>;
  12. TutlListTest = class(TIntfObjOwner)
  13. private
  14. fIntList: TIntList;
  15. fIntfList: TIntfList;
  16. fObjList: TObjList;
  17. fEnumerator: TIntList.IutlEnumerator;
  18. procedure AccessCurrentEnueratorItem;
  19. protected
  20. procedure SetUp; override;
  21. procedure TearDown; override;
  22. published
  23. procedure Prop_Count;
  24. procedure Prop_First;
  25. procedure Prop_last;
  26. procedure Prop_Items;
  27. procedure Meth_Add;
  28. procedure Meth_Insert;
  29. procedure Meth_Exchange;
  30. procedure Meth_Move;
  31. procedure Meth_Delete;
  32. procedure Meth_Extract;
  33. procedure Meth_PushFirst;
  34. procedure Meth_PopFirst;
  35. procedure Meth_PushLast;
  36. procedure Meth_PopLast;
  37. procedure Dtor_FreesAllItems;
  38. procedure Meth_IndexOf;
  39. procedure Meth_Extract_WithDefault;
  40. procedure Meth_Remove;
  41. procedure AddRemoveInterfaces;
  42. procedure AddRemoveObject_OwnedByList;
  43. procedure AddRemoveObject_NotOwnedByList;
  44. procedure AddItemWithinEnumeration;
  45. procedure DeleteItemWithinEnumeration;
  46. end;
  47. implementation
  48. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  49. //TutlListTest//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  50. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  51. procedure TutlListTest.AccessCurrentEnueratorItem;
  52. var
  53. i: Integer;
  54. begin
  55. i := fEnumerator.Current;
  56. end;
  57. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  58. procedure TutlListTest.SetUp;
  59. begin
  60. inherited SetUp;
  61. fIntList := TIntList.Create(true);
  62. fIntfList := TIntfList.Create(true);
  63. fObjList := TObjList.Create(true);
  64. end;
  65. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  66. procedure TutlListTest.TearDown;
  67. begin
  68. FreeAndNil(fIntList);
  69. FreeAndNil(fIntfList);
  70. FreeAndNil(fObjList);
  71. inherited TearDown;
  72. end;
  73. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  74. procedure TutlListTest.Prop_Count;
  75. begin
  76. AssertEquals(0, fIntList.Count);
  77. fIntList.Add(123);
  78. AssertEquals(1, fIntList.Count);
  79. fIntList.Add(234);
  80. AssertEquals(2, fIntList.Count);
  81. fIntList.Add(345);
  82. AssertEquals(3, fIntList.Count);
  83. end;
  84. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  85. procedure TutlListTest.Prop_First;
  86. begin
  87. fIntList.Add(123);
  88. AssertEquals(123, fIntList.First);
  89. fIntList.Add(456);
  90. AssertEquals(123, fIntList.First);
  91. end;
  92. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  93. procedure TutlListTest.Prop_last;
  94. begin
  95. fIntList.Add(123);
  96. AssertEquals(123, fIntList.Last);
  97. fIntList.Add(456);
  98. AssertEquals(456, fIntList.Last);
  99. end;
  100. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  101. procedure TutlListTest.Prop_Items;
  102. begin
  103. fIntList.Add(123);
  104. fIntList.Add(234);
  105. fIntList.Add(345);
  106. fIntList.Add(456);
  107. AssertEquals(123, fIntList[0]);
  108. AssertEquals(234, fIntList[1]);
  109. AssertEquals(345, fIntList[2]);
  110. AssertEquals(456, fIntList[3]);
  111. end;
  112. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  113. procedure TutlListTest.Meth_Add;
  114. begin
  115. fIntList.Add(123);
  116. AssertEquals(fIntList.Count, 1);
  117. AssertEquals(123, fIntList[0]);
  118. end;
  119. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  120. procedure TutlListTest.Meth_Insert;
  121. begin
  122. fIntList.Insert(0, 123);
  123. fIntList.Insert(0, 456);
  124. AssertEquals(fIntList.Count, 2);
  125. AssertEquals(123, fIntList[1]);
  126. AssertEquals(456, fIntList[0]);
  127. end;
  128. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  129. procedure TutlListTest.Meth_Exchange;
  130. begin
  131. fIntList.Add(123);
  132. fIntList.Add(234);
  133. fIntList.Add(345);
  134. fIntList.Add(456);
  135. fIntList.Add(567);
  136. fIntList.Exchange(1, 3);
  137. AssertEquals(123, fIntList[0]);
  138. AssertEquals(456, fIntList[1]);
  139. AssertEquals(345, fIntList[2]);
  140. AssertEquals(234, fIntList[3]);
  141. AssertEquals(567, fIntList[4]);
  142. end;
  143. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  144. procedure TutlListTest.Meth_Move;
  145. begin
  146. fIntList.Add(123);
  147. fIntList.Add(234);
  148. fIntList.Add(345);
  149. fIntList.Add(456);
  150. fIntList.Add(567);
  151. fIntList.Move(1, 3);
  152. AssertEquals(123, fIntList[0]);
  153. AssertEquals(345, fIntList[1]);
  154. AssertEquals(456, fIntList[2]);
  155. AssertEquals(234, fIntList[3]);
  156. AssertEquals(567, fIntList[4]);
  157. end;
  158. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  159. procedure TutlListTest.Meth_Delete;
  160. begin
  161. fIntList.Add(123);
  162. fIntList.Add(234);
  163. fIntList.Add(345);
  164. fIntList.Add(456);
  165. fIntList.Add(567);
  166. fIntList.Delete(2);
  167. AssertEquals(4, fIntList.Count);
  168. AssertEquals(456, fIntList[2]);
  169. end;
  170. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  171. procedure TutlListTest.Meth_Extract;
  172. begin
  173. fIntList.Add(123);
  174. fIntList.Add(234);
  175. fIntList.Add(345);
  176. fIntList.Add(456);
  177. fIntList.Add(567);
  178. AssertEquals(234, fIntList.Extract(1));
  179. AssertEquals(4, fIntList.Count);
  180. end;
  181. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  182. procedure TutlListTest.Meth_PushFirst;
  183. begin
  184. fIntList.PushFirst(123);
  185. fIntList.PushFirst(234);
  186. AssertEquals(2, fIntList.Count);
  187. AssertEquals(123, fIntList[1]);
  188. AssertEquals(234, fIntList[0]);
  189. end;
  190. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  191. procedure TutlListTest.Meth_PopFirst;
  192. begin
  193. fIntList.Add(123);
  194. fIntList.Add(234);
  195. fIntList.Add(345);
  196. fIntList.Add(456);
  197. fIntList.Add(567);
  198. AssertEquals(123, fIntList.PopFirst(false));
  199. AssertEquals(234, fIntList.PopFirst(false));
  200. AssertEquals(3, fIntList.Count);
  201. end;
  202. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  203. procedure TutlListTest.Meth_PushLast;
  204. begin
  205. fIntList.PushLast(123);
  206. fIntList.PushLast(234);
  207. fIntList.PushLast(345);
  208. AssertEquals(3, fIntList.Count);
  209. AssertEquals(123, fIntList[0]);
  210. AssertEquals(234, fIntList[1]);
  211. AssertEquals(345, fIntList[2]);
  212. end;
  213. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  214. procedure TutlListTest.Meth_PopLast;
  215. begin
  216. fIntList.Add(123);
  217. fIntList.Add(234);
  218. fIntList.Add(345);
  219. fIntList.Add(456);
  220. fIntList.Add(567);
  221. AssertEquals(567, fIntList.PopLast(false));
  222. AssertEquals(456, fIntList.PopLast(false));
  223. AssertEquals(3, fIntList.Count);
  224. end;
  225. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  226. procedure TutlListTest.Dtor_FreesAllItems;
  227. begin
  228. fObjList.Add(TIntfObj.Create(self));
  229. fObjList.Add(TIntfObj.Create(self));
  230. FreeAndNil(fObjList);
  231. AssertEquals(0, IntfObjCounter);
  232. end;
  233. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  234. procedure TutlListTest.Meth_IndexOf;
  235. begin
  236. fIntList.Add(123);
  237. fIntList.Add(234);
  238. fIntList.Add(345);
  239. fIntList.Add(456);
  240. fIntList.Add(567);
  241. AssertEquals( 1, fIntList.IndexOf(234));
  242. AssertEquals( 3, fIntList.IndexOf(456));
  243. AssertEquals(-1, fIntList.IndexOf(999));
  244. end;
  245. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  246. procedure TutlListTest.Meth_Extract_WithDefault;
  247. begin
  248. fIntList.Add(123);
  249. fIntList.Add(234);
  250. fIntList.Add(345);
  251. fIntList.Add(456);
  252. fIntList.Add(567);
  253. AssertEquals(234, fIntList.Extract(234, 999));
  254. AssertEquals(999, fIntList.Extract(234, 999));
  255. end;
  256. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  257. procedure TutlListTest.Meth_Remove;
  258. begin
  259. fIntList.Add(123);
  260. fIntList.Add(234);
  261. fIntList.Add(345);
  262. fIntList.Add(456);
  263. fIntList.Add(567);
  264. fIntList.Remove(234);
  265. AssertEquals(4, fIntList.Count);
  266. AssertEquals(345, fIntList[1]);
  267. end;
  268. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  269. procedure TutlListTest.AddRemoveInterfaces;
  270. var
  271. i1: IUnknown;
  272. begin
  273. fIntfList.Add(TIntfObj.Create(self));
  274. fIntfList.Add(TIntfObj.Create(self));
  275. fIntfList.Add(TIntfObj.Create(self));
  276. fIntfList.Exchange(0, 2);
  277. fIntfList.Move(0, 2);
  278. fIntfList.Delete(0);
  279. fIntfList.Extract(0);
  280. fIntfList.Clear;
  281. fIntfList.Insert(0, TIntfObj.Create(self));
  282. fIntfList.PopLast(true);
  283. fIntfList.Insert(0, TIntfObj.Create(self));
  284. fIntfList.PopLast(false);
  285. fIntfList.Insert(0, TIntfObj.Create(self));
  286. fIntfList.PopFirst(true);
  287. fIntfList.Insert(0, TIntfObj.Create(self));
  288. fIntfList.PopFirst(false);
  289. i1 := TIntfObj.Create(self);
  290. fIntfList.Insert(0, i1);
  291. fIntfList.Extract(i1, nil);
  292. i1 := nil;
  293. i1 := TIntfObj.Create(self);
  294. fIntfList.Insert(0, i1);
  295. fIntfList.Remove(i1);
  296. i1 := nil;
  297. fIntfList.Add(TIntfObj.Create(self));
  298. fIntfList[0] := TIntfObj.Create(self);
  299. fIntfList.Clear;
  300. AssertEquals(0, IntfObjCounter);
  301. end;
  302. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  303. procedure TutlListTest.AddRemoveObject_OwnedByList;
  304. function CreateObj: TObject;
  305. begin
  306. result := TIntfObj.Create(self);
  307. end;
  308. begin
  309. fObjList.Add(CreateObj);
  310. fObjList.Add(CreateObj);
  311. fObjList.Add(CreateObj);
  312. fObjList.Exchange(0, 2);
  313. fObjList.Move(0, 2);
  314. fObjList.Delete(0);
  315. fObjList.Extract(0).Free;
  316. fObjList.Clear;
  317. fObjList.Add(CreateObj);
  318. fObjList.PopLast(true);
  319. fObjList.Add(CreateObj);
  320. fObjList.PopLast(false).Free;
  321. fObjList.Add(CreateObj);
  322. fObjList.PopFirst(true);
  323. fObjList.Add(CreateObj);
  324. fObjList.PopFirst(false).Free;
  325. fObjList.Add(CreateObj);
  326. fObjList.Extract(fObjList[0], nil).Free;
  327. fObjList.Add(CreateObj);
  328. fObjList.Remove(fObjList[0]);
  329. fObjList.Add(CreateObj);
  330. fObjList[0] := CreateObj;
  331. fObjList.Clear;
  332. AssertEquals(0, IntfObjCounter);
  333. end;
  334. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  335. procedure TutlListTest.AddRemoveObject_NotOwnedByList;
  336. var
  337. lst: TObjectList;
  338. function CreateObj: TObject;
  339. begin
  340. result := TIntfObj.Create(self);
  341. lst.Add(result);
  342. end;
  343. begin
  344. lst := TObjectList.Create(true);
  345. try
  346. fObjList.OwnsItems := false;
  347. fObjList.Add(CreateObj);
  348. fObjList.Add(CreateObj);
  349. fObjList.Add(CreateObj);
  350. fObjList.Exchange(0, 2);
  351. fObjList.Move(0, 2);
  352. fObjList.Delete(0);
  353. fObjList.Extract(0);
  354. fObjList.Clear;
  355. fObjList.Add(CreateObj);
  356. fObjList.PopLast(true);
  357. fObjList.Add(CreateObj);
  358. fObjList.PopLast(false);
  359. fObjList.Add(CreateObj);
  360. fObjList.PopFirst(true);
  361. fObjList.Add(CreateObj);
  362. fObjList.PopFirst(false);
  363. fObjList.Add(CreateObj);
  364. fObjList.Extract(fObjList[0], nil);
  365. fObjList.Add(CreateObj);
  366. fObjList.Remove(fObjList[0]);
  367. fObjList.Add(CreateObj);
  368. fObjList[0] := CreateObj;
  369. fObjList.Clear;
  370. finally
  371. FreeAndNil(lst);
  372. end;
  373. AssertEquals(0, IntfObjCounter);
  374. end;
  375. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  376. procedure TutlListTest.AddItemWithinEnumeration;
  377. procedure InitList;
  378. var i: Integer;
  379. begin
  380. fIntList.Clear;
  381. for i := 0 to 4 do
  382. fIntList.Add(i);
  383. end;
  384. var
  385. e: TIntList.IutlEnumerator;
  386. begin
  387. e := fIntList.GetUtlEnumerator;
  388. // forward - insert behind current
  389. InitList;
  390. e.Reset;
  391. AssertTrue (e.MoveNext);
  392. AssertEquals(0, e.Current);
  393. AssertTrue (e.MoveNext);
  394. AssertEquals(1, e.Current);
  395. fIntList.Insert(2, 999);
  396. AssertEquals(1, e.Current);
  397. AssertTrue (e.MoveNext);
  398. AssertEquals(999, e.Current);
  399. AssertTrue (e.MoveNext);
  400. AssertEquals(2, e.Current);
  401. AssertTrue (e.MoveNext);
  402. AssertEquals(3, e.Current);
  403. AssertTrue (e.MoveNext);
  404. AssertEquals(4, e.Current);
  405. AssertFalse (e.MoveNext);
  406. // forward - insert before current
  407. InitList;
  408. e.Reset;
  409. AssertTrue (e.MoveNext);
  410. AssertEquals(0, e.Current);
  411. AssertTrue (e.MoveNext);
  412. AssertEquals(1, e.Current);
  413. AssertTrue (e.MoveNext);
  414. AssertEquals(2, e.Current);
  415. fIntList.Insert(1, 999);
  416. AssertEquals(2, e.Current);
  417. AssertTrue (e.MoveNext);
  418. AssertEquals(3, e.Current);
  419. AssertTrue (e.MoveNext);
  420. AssertEquals(4, e.Current);
  421. AssertFalse (e.MoveNext);
  422. // forward - insert current
  423. InitList;
  424. e.Reset;
  425. AssertTrue (e.MoveNext);
  426. AssertEquals(0, e.Current);
  427. AssertTrue (e.MoveNext);
  428. AssertEquals(1, e.Current);
  429. fIntList.Insert(1, 999);
  430. AssertEquals(1, e.Current);
  431. AssertTrue (e.MoveNext);
  432. AssertEquals(2, e.Current);
  433. AssertTrue (e.MoveNext);
  434. AssertEquals(3, e.Current);
  435. AssertTrue (e.MoveNext);
  436. AssertEquals(4, e.Current);
  437. AssertFalse (e.MoveNext);
  438. {$IFDEF UTL_ENUMERATORS}
  439. e := e.Reverse;
  440. // reverse - add after current
  441. InitList;
  442. e.Reset;
  443. AssertTrue (e.MoveNext);
  444. AssertEquals(4, e.Current);
  445. AssertTrue (e.MoveNext);
  446. AssertEquals(3, e.Current);
  447. AssertTrue (e.MoveNext);
  448. AssertEquals(2, e.Current);
  449. fIntList.Insert(3, 999);
  450. AssertEquals(2, e.Current);
  451. AssertTrue (e.MoveNext);
  452. AssertEquals(1, e.Current);
  453. AssertTrue (e.MoveNext);
  454. AssertEquals(0, e.Current);
  455. AssertFalse (e.MoveNext);
  456. // reverse - insert before current
  457. InitList;
  458. e.Reset;
  459. AssertTrue (e.MoveNext);
  460. AssertEquals(4, e.Current);
  461. AssertTrue (e.MoveNext);
  462. AssertEquals(3, e.Current);
  463. fIntList.Insert(2, 999);
  464. AssertEquals(3, e.Current);
  465. AssertTrue (e.MoveNext);
  466. AssertEquals(2, e.Current);
  467. AssertTrue (e.MoveNext);
  468. AssertEquals(999, e.Current);
  469. AssertTrue (e.MoveNext);
  470. AssertEquals(1, e.Current);
  471. AssertTrue (e.MoveNext);
  472. AssertEquals(0, e.Current);
  473. AssertFalse (e.MoveNext);
  474. // reverse - insert current
  475. InitList;
  476. e.Reset;
  477. AssertTrue (e.MoveNext);
  478. AssertEquals(4, e.Current);
  479. AssertTrue (e.MoveNext);
  480. AssertEquals(3, e.Current);
  481. fIntList.Insert(3, 999);
  482. AssertEquals(3, e.Current);
  483. AssertTrue (e.MoveNext);
  484. AssertEquals(999, e.Current);
  485. AssertTrue (e.MoveNext);
  486. AssertEquals(2, e.Current);
  487. AssertTrue (e.MoveNext);
  488. AssertEquals(1, e.Current);
  489. AssertTrue (e.MoveNext);
  490. AssertEquals(0, e.Current);
  491. AssertFalse (e.MoveNext);
  492. {$ENDIF}
  493. end;
  494. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  495. procedure TutlListTest.DeleteItemWithinEnumeration;
  496. procedure InitList;
  497. var i: Integer;
  498. begin
  499. fIntList.Clear;
  500. for i := 0 to 4 do
  501. fIntList.Add(i);
  502. end;
  503. var
  504. e: TIntList.IutlEnumerator;
  505. begin
  506. e := fIntList.GetUtlEnumerator;
  507. // forward - delete behind current
  508. InitList;
  509. e.Reset;
  510. AssertTrue (e.MoveNext);
  511. AssertEquals(0, e.Current);
  512. AssertTrue (e.MoveNext);
  513. AssertEquals(1, e.Current);
  514. fIntList.Delete(2);
  515. AssertEquals(1, e.Current);
  516. AssertTrue (e.MoveNext);
  517. AssertEquals(3, e.Current);
  518. AssertTrue (e.MoveNext);
  519. AssertEquals(4, e.Current);
  520. AssertFalse (e.MoveNext);
  521. // forward - delete before current
  522. InitList;
  523. e.Reset;
  524. AssertTrue (e.MoveNext);
  525. AssertEquals(0, e.Current);
  526. AssertTrue (e.MoveNext);
  527. AssertEquals(1, e.Current);
  528. AssertTrue (e.MoveNext);
  529. AssertEquals(2, e.Current);
  530. fIntList.Remove(1);
  531. AssertEquals(2, e.Current);
  532. AssertTrue (e.MoveNext);
  533. AssertEquals(3, e.Current);
  534. AssertTrue (e.MoveNext);
  535. AssertEquals(4, e.Current);
  536. AssertFalse (e.MoveNext);
  537. // forward - delete current
  538. InitList;
  539. e.Reset;
  540. AssertTrue (e.MoveNext);
  541. AssertEquals(0, e.Current);
  542. AssertTrue (e.MoveNext);
  543. AssertEquals(1, e.Current);
  544. fIntList.Remove(1);
  545. fEnumerator := e;
  546. AssertException('Current does not raise exception after deleting current', EInvalidOperation, @AccessCurrentEnueratorItem);
  547. AssertTrue (e.MoveNext);
  548. AssertEquals(2, e.Current);
  549. AssertTrue (e.MoveNext);
  550. AssertEquals(3, e.Current);
  551. AssertTrue (e.MoveNext);
  552. AssertEquals(4, e.Current);
  553. AssertFalse (e.MoveNext);
  554. {$IFDEF UTL_ENUMERATORS}
  555. e := e.Reverse;
  556. // reverse - delete after current
  557. InitList;
  558. e.Reset;
  559. AssertTrue (e.MoveNext);
  560. AssertEquals(4, e.Current);
  561. AssertTrue (e.MoveNext);
  562. AssertEquals(3, e.Current);
  563. fIntList.Remove(4);
  564. AssertEquals(3, e.Current);
  565. AssertTrue (e.MoveNext);
  566. AssertEquals(2, e.Current);
  567. AssertTrue (e.MoveNext);
  568. AssertEquals(1, e.Current);
  569. AssertTrue (e.MoveNext);
  570. AssertEquals(0, e.Current);
  571. AssertFalse (e.MoveNext);
  572. // reverse - delete before current
  573. InitList;
  574. e.Reset;
  575. AssertTrue (e.MoveNext);
  576. AssertEquals(4, e.Current);
  577. AssertTrue (e.MoveNext);
  578. AssertEquals(3, e.Current);
  579. fIntList.Remove(2);
  580. AssertEquals(3, e.Current);
  581. AssertTrue (e.MoveNext);
  582. AssertEquals(1, e.Current);
  583. AssertTrue (e.MoveNext);
  584. AssertEquals(0, e.Current);
  585. AssertFalse (e.MoveNext);
  586. // reverse - delete current
  587. InitList;
  588. e.Reset;
  589. AssertTrue (e.MoveNext);
  590. AssertEquals(4, e.Current);
  591. AssertTrue (e.MoveNext);
  592. AssertEquals(3, e.Current);
  593. fIntList.Remove(3);
  594. fEnumerator := e;
  595. AssertException('Current does not raise exception after deleting current', EInvalidOperation, @AccessCurrentEnueratorItem);
  596. AssertTrue (e.MoveNext);
  597. AssertEquals(2, e.Current);
  598. AssertTrue (e.MoveNext);
  599. AssertEquals(1, e.Current);
  600. AssertTrue (e.MoveNext);
  601. AssertEquals(0, e.Current);
  602. AssertFalse (e.MoveNext);
  603. {$ENDIF}
  604. end;
  605. initialization
  606. RegisterTest(TutlListTest.Suite);
  607. end.