/packages/fcl-stl/tests/gsettest.pp

https://github.com/slibre/freepascal · Puppet · 125 lines · 108 code · 17 blank · 0 comment · 17 complexity · 040f67adf059c42000c92d0bab33d0f2 MD5 · raw file

  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. procedure IteratorTest;
  11. public
  12. procedure Setup;override;
  13. private
  14. data:setlli;
  15. end;
  16. implementation
  17. procedure TGSetTest.IteratorTest;
  18. var it:setlli.TIterator;
  19. begin
  20. it:=data.min;
  21. if (it <> nil) then
  22. AssertEquals('not null min', 0, 1);
  23. data.insert(3);
  24. data.insert(5);
  25. data.insert(7);
  26. it:=data.min;
  27. AssertEquals('bad value', 3, it.Data);
  28. AssertEquals('next not true', true, it.Next);
  29. AssertEquals('bad value', 5, it.Data);
  30. AssertEquals('next not true', true, it.Next);
  31. AssertEquals('bad value', 7, it.Data);
  32. AssertEquals('next not false', false, it.Next);
  33. end;
  34. procedure TGSetTest.SetTest;
  35. var it:setlli.TIterator;
  36. begin
  37. data.insert(3);
  38. data.insert(5);
  39. data.insert(7);
  40. AssertEquals('Wrong min', 3, data.min().Data);
  41. AssertEquals('Wrong max', 7, data.max().Data);
  42. data.delete(3);
  43. AssertEquals('Wrong size', 2, data.size);
  44. AssertEquals('Wrong min', 5, data.min().Data);
  45. data.insert(3);
  46. data.insert(3);
  47. data.insert(3);
  48. AssertEquals('Wrong size', 3, data.size);
  49. AssertEquals('Wrong min', 3, data.min().Data);
  50. if(data.find(4)<>nil) then
  51. Fail('Found key which not there');
  52. if(data.find(5)=nil) then
  53. Fail('Not found key which was there');
  54. if(data.FindLess(8).Data<>7) then
  55. Fail('Wrong less than 8');
  56. if(data.FindLess(7).Data<>5) then
  57. Fail('Wrong less than 7');
  58. if(data.FindLess(3)<>nil) then
  59. Fail('Wrong less than 3');
  60. if(data.FindLessEqual(8).Data<>7) then
  61. Fail('Wrong less equal than 8');
  62. if(data.FindLessEqual(7).Data<>7) then
  63. Fail('Wrong less equal than 7');
  64. if(data.FindLessEqual(6).Data<>5) then
  65. Fail('Wrong less equal than 6');
  66. if(data.FindLessEqual(2)<>nil) then
  67. Fail('Wrong less equal than 2');
  68. if(data.FindGreater(2).Data<>3) then
  69. Fail('Wrong greater than 2');
  70. if(data.Findgreater(3).Data<>5) then
  71. Fail('Wrong greater than 3');
  72. if(data.Findgreater(7)<>nil) then
  73. Fail('Wrong greater than 7');
  74. if(data.FindGreaterEqual(2).Data<>3) then
  75. Fail('Wrong greater equal than 2');
  76. if(data.FindGreaterEqual(3).Data<>3) then
  77. Fail('Wrong greater equal than 3');
  78. if(data.FindGreaterEqual(4).Data<>5) then
  79. Fail('Wrong greater equal than 4');
  80. if(data.FindGreaterEqual(8)<>nil) then
  81. Fail('Wrong greater equal than 8');
  82. data.insert(17);
  83. it:=data.min;
  84. AssertEquals('Wrong min', 3, it.Data);
  85. AssertEquals('Next not true', true, it.next);
  86. AssertEquals('Wrong next', 5, it.Data);
  87. AssertEquals('Next not true', true, it.next);
  88. AssertEquals('Wrong next', 7, it.Data);
  89. AssertEquals('Next not true', true, it.next);
  90. AssertEquals('Wrong next', 17, it.Data);
  91. AssertEquals('Last next not fail', false, it.next);
  92. it:=data.max;
  93. AssertEquals('Wrong max', 17, it.Data);
  94. AssertEquals('Prev not true', true, it.prev);
  95. AssertEquals('Wrong prev', 7, it.Data);
  96. AssertEquals('Prev not true', true, it.prev);
  97. AssertEquals('Wrong prev', 5, it.Data);
  98. AssertEquals('Prev not true', true, it.prev);
  99. AssertEquals('Wrong prev', 3, it.Data);
  100. AssertEquals('First prev not fail', false, it.prev);
  101. end;
  102. procedure TGSetTest.Setup;
  103. begin
  104. data:=setlli.create;
  105. end;
  106. initialization
  107. RegisterTest(TGSetTest);
  108. end.