HeapArrayTests.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "tests/HeapArrayTests.h"
  2. #include "tests/Test.h"
  3. #include "utils/HeapArray.h"
  4. #include "utils/StringBuffer.h"
  5. typedef StringBuffer<50> String;
  6. static void testToString1(Test& test) {
  7. HeapArray<int> a(3);
  8. a[0] = 1;
  9. a[1] = 243;
  10. a[2] = -423;
  11. test.checkEqual(String("[1, 243, -423]"), String(a), "to string 1");
  12. }
  13. static void testToString2(Test& test) {
  14. HeapArray<int> a(1);
  15. a[0] = 1;
  16. test.checkEqual(String("[1]"), String(a), "to string 2");
  17. }
  18. static void testGrow(Test& test) {
  19. HeapArray<int> a(3);
  20. a[0] = 1;
  21. a[1] = 2;
  22. a[2] = 3;
  23. a.grow(2, 20);
  24. test.checkEqual(5, a.getLength(), "resize length");
  25. test.checkEqual(1, a[0], "resize copy 1");
  26. test.checkEqual(2, a[1], "resize copy 2");
  27. test.checkEqual(3, a[2], "resize copy 3");
  28. test.checkEqual(20, a[3], "resize copy 4");
  29. test.checkEqual(20, a[4], "resize copy 5");
  30. }
  31. void HeapArrayTests::test() {
  32. Test test("HeapArray");
  33. testToString1(test);
  34. testToString2(test);
  35. testGrow(test);
  36. test.finalize();
  37. }