ArrayTests.cpp 987 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "../Tests.hpp"
  2. #include "core/data/Array.hpp"
  3. template class Core::Array<size_t, 3>;
  4. using TestArray = Core::Array<size_t, 3>;
  5. static void testToString1() {
  6. TestArray a;
  7. a[0] = 1;
  8. a[1] = 243;
  9. a[2] = 423;
  10. CORE_TEST_STRING("[1, 243, 423]", a);
  11. }
  12. static void testToString2() {
  13. Core::Array<int, 1> a;
  14. a[0] = 1;
  15. CORE_TEST_STRING("[1]", a);
  16. }
  17. static void testReadConst() {
  18. TestArray a;
  19. for(size_t i = 0; i < a.getLength(); i++) {
  20. a[i] = i;
  21. }
  22. const TestArray& c = a;
  23. for(size_t i = 0; i < c.getLength(); i++) {
  24. CORE_TEST_EQUAL(i, c[i]);
  25. }
  26. }
  27. static void testRangeFor() {
  28. TestArray a;
  29. for(size_t i = 0; i < a.getLength(); i++) {
  30. a[i] = i;
  31. }
  32. for(size_t& i : a) {
  33. i++;
  34. }
  35. for(size_t i = 0; i < a.getLength(); i++) {
  36. CORE_TEST_EQUAL(i + 1, a[i]);
  37. }
  38. }
  39. void Core::testArray() {
  40. testToString1();
  41. testToString2();
  42. testReadConst();
  43. testRangeFor();
  44. }