Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

94 Zeilen
2.4 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(ArrayNDTest)
  18. {
  19. void SetUp() {}
  20. void TearDown() {}
  21. LOLUNIT_TEST(Array2D)
  22. {
  23. arraynd<2, int> a;
  24. a.SetSize(vec_t<ptrdiff_t, 2>(2, 2));
  25. /* Non-const accessors */
  26. a[0][0] = 1;
  27. a[0][1] = 2;
  28. a[1][0] = 3;
  29. a[1][1] = 4;
  30. LOLUNIT_ASSERT_EQUAL(a[0][0], 1);
  31. LOLUNIT_ASSERT_EQUAL(a[0][1], 2);
  32. LOLUNIT_ASSERT_EQUAL(a[1][0], 3);
  33. LOLUNIT_ASSERT_EQUAL(a[1][1], 4);
  34. /* Const accessors */
  35. arraynd<2, int> const &b = a;
  36. LOLUNIT_ASSERT_EQUAL(b[0][0], 1);
  37. LOLUNIT_ASSERT_EQUAL(b[0][1], 2);
  38. LOLUNIT_ASSERT_EQUAL(b[1][0], 3);
  39. LOLUNIT_ASSERT_EQUAL(b[1][1], 4);
  40. }
  41. LOLUNIT_TEST(ArrayNDCreate)
  42. {
  43. arraynd<10, int> a;
  44. arraynd<20, float> b;
  45. arraynd<30, uint8_t> c;
  46. arraynd<40, double> d;
  47. arraynd<3, double> e = { { {1, 2}, {3, 4} }, { {5, 6}, {7, 8} }};
  48. LOLUNIT_ASSERT_EQUAL(e[0][0][0], 1);
  49. LOLUNIT_ASSERT_EQUAL(e[0][0][1], 2);
  50. LOLUNIT_ASSERT_EQUAL(e[0][1][0], 3);
  51. LOLUNIT_ASSERT_EQUAL(e[0][1][1], 4);
  52. LOLUNIT_ASSERT_EQUAL(e[1][0][0], 5);
  53. LOLUNIT_ASSERT_EQUAL(e[1][0][1], 6);
  54. LOLUNIT_ASSERT_EQUAL(e[1][1][0], 7);
  55. LOLUNIT_ASSERT_EQUAL(e[1][1][1], 8);
  56. }
  57. LOLUNIT_TEST(ArrayNDInit)
  58. {
  59. int const NDIM = 8;
  60. vec_t<ptrdiff_t, NDIM> size;
  61. for (int i = 0; i < NDIM; ++i)
  62. size[i] = 5;
  63. arraynd<NDIM, uint8_t> a(size);
  64. memset(a.Data(), 0, a.Bytes());
  65. LOLUNIT_ASSERT_EQUAL(a[2][3][2][0][1][4][0][1], 0x00);
  66. vec_t<int, NDIM> v = { 2, 3, 2, 0, 1, 4, 0, 1 };
  67. LOLUNIT_ASSERT_EQUAL(a[v], 0x00);
  68. a[2][3][2][0][1][4][0][1] = 0xcd;
  69. LOLUNIT_ASSERT_EQUAL(a[2][3][2][0][1][4][0][1], 0xcd);
  70. LOLUNIT_ASSERT_EQUAL(a[v], 0xcd);
  71. arraynd<NDIM, uint8_t> const &b = a;
  72. LOLUNIT_ASSERT_EQUAL(b[2][3][2][0][1][4][0][1], 0xcd);
  73. LOLUNIT_ASSERT_EQUAL(b[v], 0xcd);
  74. }
  75. };
  76. } /* namespace lol */