gsettest.pp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. {$mode objfpc}
  2. unit gsettest;
  3. interface
  4. uses fpcunit, testregistry, gset, gutil;
  5. type lesslli=specialize TLess<longint>;
  6. setlli=specialize TSet<longint,lesslli>;
  7. type TGSetTest = class(TTestCase)
  8. Published
  9. procedure SetTest;
  10. public
  11. procedure Setup;override;
  12. private
  13. data:setlli;
  14. end;
  15. implementation
  16. procedure TGSetTest.SetTest;
  17. var it:setlli.pnode;
  18. begin
  19. data.insert(3);
  20. data.insert(5);
  21. data.insert(7);
  22. AssertEquals('Wrong min', 3, data.min()^.data);
  23. AssertEquals('Wrong max', 7, data.max()^.data);
  24. data.delete(3);
  25. AssertEquals('Wrong size', 2, data.size);
  26. AssertEquals('Wrong min', 5, data.min()^.data);
  27. data.insert(3);
  28. data.insert(3);
  29. data.insert(3);
  30. AssertEquals('Wrong size', 3, data.size);
  31. AssertEquals('Wrong min', 3, data.min()^.data);
  32. if(data.find(4)<>nil) then
  33. Fail('Found key which not there');
  34. if(data.find(5)=nil) then
  35. Fail('Not found key which was there');
  36. if(data.FindLess(8)^.data<>7) then
  37. Fail('Wrong less than 8');
  38. if(data.FindLess(7)^.data<>5) then
  39. Fail('Wrong less than 7');
  40. if(data.FindLess(3)<>nil) then
  41. Fail('Wrong less than 3');
  42. if(data.FindLessEqual(8)^.data<>7) then
  43. Fail('Wrong less equal than 8');
  44. if(data.FindLessEqual(7)^.data<>7) then
  45. Fail('Wrong less equal than 7');
  46. if(data.FindLessEqual(6)^.data<>5) then
  47. Fail('Wrong less equal than 6');
  48. if(data.FindLessEqual(2)<>nil) then
  49. Fail('Wrong less equal than 2');
  50. if(data.FindGreater(2)^.data<>3) then
  51. Fail('Wrong greater than 2');
  52. if(data.Findgreater(3)^.data<>5) then
  53. Fail('Wrong greater than 3');
  54. if(data.Findgreater(7)<>nil) then
  55. Fail('Wrong greater than 7');
  56. if(data.FindGreaterEqual(2)^.data<>3) then
  57. Fail('Wrong greater equal than 2');
  58. if(data.FindGreaterEqual(3)^.data<>3) then
  59. Fail('Wrong greater equal than 3');
  60. if(data.FindGreaterEqual(4)^.data<>5) then
  61. Fail('Wrong greater equal than 4');
  62. if(data.FindGreaterEqual(8)<>nil) then
  63. Fail('Wrong greater equal than 8');
  64. data.insert(17);
  65. it:=data.min;
  66. AssertEquals('Wrong min', 3, it^.data);
  67. it:=data.next(it);
  68. AssertEquals('Wrong next', 5, it^.data);
  69. it:=data.next(it);
  70. AssertEquals('Wrong next', 7, it^.data);
  71. it:=data.next(it);
  72. AssertEquals('Wrong next', 17, it^.data);
  73. it:=data.next(it);
  74. if(it<>nil) then
  75. AssertEquals('Last not nil', 0, 1);
  76. it:=data.max;
  77. AssertEquals('Wrong max', 17, it^.data);
  78. it:=data.prev(it);
  79. AssertEquals('Wrong prev', 7, it^.data);
  80. it:=data.prev(it);
  81. AssertEquals('Wrong prev', 5, it^.data);
  82. it:=data.prev(it);
  83. AssertEquals('Wrong prev', 3, it^.data);
  84. it:=data.prev(it);
  85. if(it<>nil) then
  86. AssertEquals('First not nil', 0, 1);
  87. end;
  88. procedure TGSetTest.Setup;
  89. begin
  90. data:=setlli.create;
  91. end;
  92. initialization
  93. RegisterTest(TGSetTest);
  94. end.