25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

76 lines
1.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(ArrayNDTest)
  18. {
  19. void SetUp() {}
  20. void TearDown() {}
  21. LOLUNIT_TEST(Array2D)
  22. {
  23. arraynd<2, int> a;
  24. a.SetSize(vec_t<size_t, 2>(1, 2));
  25. a[0][0] = 1;
  26. a[0][1] = 2;
  27. LOLUNIT_ASSERT_EQUAL(a[0][0], 1);
  28. LOLUNIT_ASSERT_EQUAL(a[0][1], 2);
  29. arraynd<2, int> const &b = a;
  30. LOLUNIT_ASSERT_EQUAL(b[0][0], 1);
  31. LOLUNIT_ASSERT_EQUAL(b[0][1], 2);
  32. }
  33. LOLUNIT_TEST(ArrayNDCreate)
  34. {
  35. arraynd<10, int> a;
  36. arraynd<20, float> b;
  37. arraynd<30, uint8_t> c;
  38. arraynd<40, double> d;
  39. }
  40. LOLUNIT_TEST(ArrayNDInit)
  41. {
  42. int const NDIM = 8;
  43. vec_t<size_t, NDIM> size;
  44. for (int i = 0; i < NDIM; ++i)
  45. size[i] = 5;
  46. arraynd<NDIM, uint8_t> a(size);
  47. memset(a.Data(), 0, a.Bytes());
  48. LOLUNIT_ASSERT_EQUAL(a[2][3][2][0][1][4][0][1], 0x00);
  49. vec_t<int, NDIM> v = { 2, 3, 2, 0, 1, 4, 0, 1 };
  50. LOLUNIT_ASSERT_EQUAL(a[v], 0x00);
  51. a[2][3][2][0][1][4][0][1] = 0xcd;
  52. LOLUNIT_ASSERT_EQUAL(a[2][3][2][0][1][4][0][1], 0xcd);
  53. LOLUNIT_ASSERT_EQUAL(a[v], 0xcd);
  54. arraynd<NDIM, uint8_t> const &b = a;
  55. LOLUNIT_ASSERT_EQUAL(b[2][3][2][0][1][4][0][1], 0xcd);
  56. LOLUNIT_ASSERT_EQUAL(b[v], 0xcd);
  57. }
  58. };
  59. } /* namespace lol */