gmaptest.pp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. {$mode objfpc}
  2. unit gmaptest;
  3. interface
  4. uses fpcunit, testregistry, gmap, gutil;
  5. type lesslli=specialize TLess<longint>;
  6. maplli=specialize TMap<longint,longint, lesslli>;
  7. type TGMapTest = class(TTestCase)
  8. Published
  9. procedure MapTest;
  10. public
  11. procedure Setup;override;
  12. private
  13. data:maplli;
  14. end;
  15. implementation
  16. procedure TGMapTest.MapTest;
  17. var it:maplli.TIterator;
  18. begin
  19. data[3]:=3;
  20. data[5]:=5;
  21. data[7]:=7;
  22. AssertEquals('Wrong min key', 3, data.min().GetData.key);
  23. AssertEquals('Wrong max key', 7, data.max().GetData.key);
  24. AssertEquals('Wrong min val', 3, data.min().GetData.value);
  25. AssertEquals('Wrong max val', 7, data.max().GetData.value);
  26. AssertEquals('Wrong val', 5, data[5]);
  27. data.delete(3);
  28. AssertEquals('Wrong min key', 5, data.min().GetData.key);
  29. AssertEquals('Wrong max key', 7, data.max().GetData.key);
  30. AssertEquals('Wrong min val', 5, data.min().GetData.value);
  31. AssertEquals('Wrong max val', 7, data.max().GetData.value);
  32. data[3]:=3;
  33. data[3]:=47;
  34. AssertEquals('Wrong val 2', 47, data[3]);
  35. if(data.find(4)<>nil) then
  36. AssertEquals('Found key which not there', 0, 1);
  37. data[17]:=42;
  38. it:=data.min;
  39. AssertEquals('Wrong min', 3, it.Key);
  40. AssertEquals('Next not true', true, it.Next);
  41. AssertEquals('Wrong next', 5, it.Key);
  42. AssertEquals('Wrong next value', 5, it.Value);
  43. it.Value := it.Value + 17;
  44. AssertEquals('Wrong value update', 22, it.Value);
  45. it.MutableValue^:= 444;
  46. AssertEquals('Wrong mutable value update', 444, it.Value);
  47. AssertEquals('Next not true', true, it.Next);
  48. AssertEquals('Wrong next', 7, it.GetData.key);
  49. AssertEquals('Next not true', true, it.Next);
  50. AssertEquals('Wrong next', 17, it.GetData.key);
  51. AssertEquals('Next not false', false, it.Next);
  52. it:=data.max;
  53. AssertEquals('Wrong max', 17, it.GetData.key);
  54. AssertEquals('Prev not true', true, it.Prev);
  55. AssertEquals('Wrong prev', 7, it.GetData.key);
  56. AssertEquals('Prev not true', true, it.Prev);
  57. AssertEquals('Wrong prev', 5, it.GetData.key);
  58. AssertEquals('Prev not true', true, it.Prev);
  59. AssertEquals('Wrong prev', 3, it.GetData.key);
  60. AssertEquals('Prev not false', false, it.Prev);
  61. end;
  62. procedure TGMapTest.Setup;
  63. begin
  64. data:=maplli.create;
  65. end;
  66. initialization
  67. RegisterTest(TGMapTest);
  68. end.