You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

96 rivejä
2.7 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2014 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <lol/main.h>
  14. #include "lol/unit.h"
  15. namespace lol
  16. {
  17. LOLUNIT_FIXTURE(Array3DTest)
  18. {
  19. void SetUp() {}
  20. void TearDown() {}
  21. LOLUNIT_TEST(Array3DCreate)
  22. {
  23. array3d<int> a(ivec3(10, 10, 10));
  24. a[0][0][0] = 2;
  25. a[9][0][0] = 4;
  26. a[0][9][9] = 6;
  27. a[9][9][9] = 8;
  28. LOLUNIT_ASSERT_EQUAL(a[0][0][0], 2);
  29. LOLUNIT_ASSERT_EQUAL(a[9][0][0], 4);
  30. LOLUNIT_ASSERT_EQUAL(a[0][9][9], 6);
  31. LOLUNIT_ASSERT_EQUAL(a[9][9][9], 8);
  32. array3d<int> const &b = a;
  33. LOLUNIT_ASSERT_EQUAL(b[0][0][0], 2);
  34. LOLUNIT_ASSERT_EQUAL(b[9][0][0], 4);
  35. LOLUNIT_ASSERT_EQUAL(b[0][9][9], 6);
  36. LOLUNIT_ASSERT_EQUAL(b[9][9][9], 8);
  37. }
  38. LOLUNIT_TEST(Array3DInit)
  39. {
  40. array3d<int> a = { { { 1, 2, 3, 4 },
  41. { 5, 6, 7, 8 },
  42. { 9, 8, 7, 6 } },
  43. { { -1, -2, -3, -4 },
  44. { -5, -6, -7, -8 },
  45. { -9, -8, -7, -6 } } };
  46. LOLUNIT_ASSERT_EQUAL(a.GetSize().x, 4);
  47. LOLUNIT_ASSERT_EQUAL(a.GetSize().y, 3);
  48. LOLUNIT_ASSERT_EQUAL(a.GetSize().z, 2);
  49. LOLUNIT_ASSERT_EQUAL(a[0][0][0], 1);
  50. LOLUNIT_ASSERT_EQUAL(a[1][0][0], 2);
  51. LOLUNIT_ASSERT_EQUAL(a[2][0][0], 3);
  52. LOLUNIT_ASSERT_EQUAL(a[3][0][0], 4);
  53. LOLUNIT_ASSERT_EQUAL(a[0][1][0], 5);
  54. LOLUNIT_ASSERT_EQUAL(a[1][1][0], 6);
  55. LOLUNIT_ASSERT_EQUAL(a[2][1][0], 7);
  56. LOLUNIT_ASSERT_EQUAL(a[3][1][0], 8);
  57. LOLUNIT_ASSERT_EQUAL(a[0][2][0], 9);
  58. LOLUNIT_ASSERT_EQUAL(a[1][2][0], 8);
  59. LOLUNIT_ASSERT_EQUAL(a[2][2][0], 7);
  60. LOLUNIT_ASSERT_EQUAL(a[3][2][0], 6);
  61. LOLUNIT_ASSERT_EQUAL(a[0][0][1], -1);
  62. LOLUNIT_ASSERT_EQUAL(a[1][0][1], -2);
  63. LOLUNIT_ASSERT_EQUAL(a[2][0][1], -3);
  64. LOLUNIT_ASSERT_EQUAL(a[3][0][1], -4);
  65. LOLUNIT_ASSERT_EQUAL(a[0][1][1], -5);
  66. LOLUNIT_ASSERT_EQUAL(a[1][1][1], -6);
  67. LOLUNIT_ASSERT_EQUAL(a[2][1][1], -7);
  68. LOLUNIT_ASSERT_EQUAL(a[3][1][1], -8);
  69. LOLUNIT_ASSERT_EQUAL(a[0][2][1], -9);
  70. LOLUNIT_ASSERT_EQUAL(a[1][2][1], -8);
  71. LOLUNIT_ASSERT_EQUAL(a[2][2][1], -7);
  72. LOLUNIT_ASSERT_EQUAL(a[3][2][1], -6);
  73. }
  74. };
  75. } /* namespace lol */