Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

array.cpp 2.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2012 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://sam.zoy.org/projects/COPYING.WTFPL for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include "core.h"
  14. #include "lol/unit.h"
  15. namespace lol
  16. {
  17. LOLUNIT_FIXTURE(ArrayTest)
  18. {
  19. void SetUp() {}
  20. void TearDown() {}
  21. LOLUNIT_TEST(ArrayPush)
  22. {
  23. Array<int> a;
  24. a.Push(0);
  25. a.Push(1);
  26. a.Push(2);
  27. a.Push(3);
  28. LOLUNIT_ASSERT_EQUAL(a[0], 0);
  29. LOLUNIT_ASSERT_EQUAL(a[1], 1);
  30. LOLUNIT_ASSERT_EQUAL(a[2], 2);
  31. LOLUNIT_ASSERT_EQUAL(a[3], 3);
  32. }
  33. LOLUNIT_TEST(ArrayPushWithShift)
  34. {
  35. Array<int> a;
  36. a << 0 << 1 << 2 << 3;
  37. LOLUNIT_ASSERT_EQUAL(a[0], 0);
  38. LOLUNIT_ASSERT_EQUAL(a[1], 1);
  39. LOLUNIT_ASSERT_EQUAL(a[2], 2);
  40. LOLUNIT_ASSERT_EQUAL(a[3], 3);
  41. }
  42. LOLUNIT_TEST(ArrayCopy)
  43. {
  44. Array<int> a;
  45. a << 0 << 1 << 2 << 3;
  46. Array<int> b = a;
  47. LOLUNIT_ASSERT_EQUAL(b[0], 0);
  48. LOLUNIT_ASSERT_EQUAL(b[1], 1);
  49. LOLUNIT_ASSERT_EQUAL(b[2], 2);
  50. LOLUNIT_ASSERT_EQUAL(b[3], 3);
  51. }
  52. LOLUNIT_TEST(ArrayRemove)
  53. {
  54. Array<int> a;
  55. a << 0 << 1 << 2 << 3;
  56. a.Remove(1);
  57. LOLUNIT_ASSERT_EQUAL(a[0], 0);
  58. LOLUNIT_ASSERT_EQUAL(a[1], 2);
  59. LOLUNIT_ASSERT_EQUAL(a[2], 3);
  60. }
  61. LOLUNIT_TEST(EightElements)
  62. {
  63. Array<int, long, float, double, unsigned, char, bool, void *> a;
  64. a.Push(1, 2, 3.f, 4.0, 5, 'a', true, 0);
  65. LOLUNIT_ASSERT_EQUAL(a[0].m1, 1);
  66. LOLUNIT_ASSERT_EQUAL(a[0].m2, 2);
  67. LOLUNIT_ASSERT_EQUAL(a[0].m3, 3.f);
  68. LOLUNIT_ASSERT_EQUAL(a[0].m4, 4.0);
  69. LOLUNIT_ASSERT_EQUAL(a[0].m5, 5);
  70. LOLUNIT_ASSERT_EQUAL(a[0].m6, 'a');
  71. LOLUNIT_ASSERT_EQUAL(a[0].m7, true);
  72. LOLUNIT_ASSERT_EQUAL(a[0].m8, 0);
  73. }
  74. LOLUNIT_TEST(ArrayConcat)
  75. {
  76. Array<int> a, b;
  77. a << 0 << 1;
  78. b << 2 << 3;
  79. Array<int> c = a + b;
  80. LOLUNIT_ASSERT_EQUAL(c[0], 0);
  81. LOLUNIT_ASSERT_EQUAL(c[1], 1);
  82. LOLUNIT_ASSERT_EQUAL(c[2], 2);
  83. LOLUNIT_ASSERT_EQUAL(c[3], 3);
  84. }
  85. LOLUNIT_TEST(ArrayAppend)
  86. {
  87. Array<int> a, b;
  88. a << 0 << 1;
  89. b << 2 << 3;
  90. a += b;
  91. LOLUNIT_ASSERT_EQUAL(a[0], 0);
  92. LOLUNIT_ASSERT_EQUAL(a[1], 1);
  93. LOLUNIT_ASSERT_EQUAL(a[2], 2);
  94. LOLUNIT_ASSERT_EQUAL(a[3], 3);
  95. b += b;
  96. LOLUNIT_ASSERT_EQUAL(b[0], 2);
  97. LOLUNIT_ASSERT_EQUAL(b[1], 3);
  98. LOLUNIT_ASSERT_EQUAL(b[2], 2);
  99. LOLUNIT_ASSERT_EQUAL(b[3], 3);
  100. }
  101. };
  102. } /* namespace lol */