ArrayTests.cpp 968 B

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