test_array.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. /**************************************************************************/
  2. /* test_array.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef TEST_ARRAY_H
  31. #define TEST_ARRAY_H
  32. #include "core/variant/array.h"
  33. #include "tests/test_macros.h"
  34. #include "tests/test_tools.h"
  35. namespace TestArray {
  36. static inline Array build_array() {
  37. return Array();
  38. }
  39. template <typename... Targs>
  40. static inline Array build_array(Variant item, Targs... Fargs) {
  41. Array a = build_array(Fargs...);
  42. a.push_front(item);
  43. return a;
  44. }
  45. static inline Dictionary build_dictionary() {
  46. return Dictionary();
  47. }
  48. template <typename... Targs>
  49. static inline Dictionary build_dictionary(Variant key, Variant item, Targs... Fargs) {
  50. Dictionary d = build_dictionary(Fargs...);
  51. d[key] = item;
  52. return d;
  53. }
  54. TEST_CASE("[Array] size(), clear(), and is_empty()") {
  55. Array arr;
  56. CHECK(arr.size() == 0);
  57. CHECK(arr.is_empty());
  58. arr.push_back(1);
  59. CHECK(arr.size() == 1);
  60. arr.clear();
  61. CHECK(arr.is_empty());
  62. CHECK(arr.size() == 0);
  63. }
  64. TEST_CASE("[Array] Assignment and comparison operators") {
  65. Array arr1;
  66. Array arr2;
  67. arr1.push_back(1);
  68. CHECK(arr1 != arr2);
  69. CHECK(arr1 > arr2);
  70. CHECK(arr1 >= arr2);
  71. arr2.push_back(2);
  72. CHECK(arr1 != arr2);
  73. CHECK(arr1 < arr2);
  74. CHECK(arr1 <= arr2);
  75. CHECK(arr2 > arr1);
  76. CHECK(arr2 >= arr1);
  77. Array arr3 = arr2;
  78. CHECK(arr3 == arr2);
  79. }
  80. TEST_CASE("[Array] append_array()") {
  81. Array arr1;
  82. Array arr2;
  83. arr1.push_back(1);
  84. arr1.append_array(arr2);
  85. CHECK(arr1.size() == 1);
  86. arr2.push_back(2);
  87. arr1.append_array(arr2);
  88. CHECK(arr1.size() == 2);
  89. CHECK(int(arr1[0]) == 1);
  90. CHECK(int(arr1[1]) == 2);
  91. }
  92. TEST_CASE("[Array] resize(), insert(), and erase()") {
  93. Array arr;
  94. arr.resize(2);
  95. CHECK(arr.size() == 2);
  96. arr.insert(0, 1);
  97. CHECK(int(arr[0]) == 1);
  98. arr.insert(0, 2);
  99. CHECK(int(arr[0]) == 2);
  100. arr.erase(2);
  101. CHECK(int(arr[0]) == 1);
  102. }
  103. TEST_CASE("[Array] front() and back()") {
  104. Array arr;
  105. arr.push_back(1);
  106. CHECK(int(arr.front()) == 1);
  107. CHECK(int(arr.back()) == 1);
  108. arr.push_back(3);
  109. CHECK(int(arr.front()) == 1);
  110. CHECK(int(arr.back()) == 3);
  111. }
  112. TEST_CASE("[Array] has() and count()") {
  113. Array arr;
  114. arr.push_back(1);
  115. arr.push_back(1);
  116. CHECK(arr.has(1));
  117. CHECK(!arr.has(2));
  118. CHECK(arr.count(1) == 2);
  119. CHECK(arr.count(2) == 0);
  120. }
  121. TEST_CASE("[Array] remove_at()") {
  122. Array arr;
  123. arr.push_back(1);
  124. arr.push_back(2);
  125. arr.remove_at(0);
  126. CHECK(arr.size() == 1);
  127. CHECK(int(arr[0]) == 2);
  128. arr.remove_at(0);
  129. CHECK(arr.size() == 0);
  130. // The array is now empty; try to use `remove_at()` again.
  131. // Normally, this prints an error message so we silence it.
  132. ERR_PRINT_OFF;
  133. arr.remove_at(0);
  134. ERR_PRINT_ON;
  135. CHECK(arr.size() == 0);
  136. }
  137. TEST_CASE("[Array] get()") {
  138. Array arr;
  139. arr.push_back(1);
  140. CHECK(int(arr.get(0)) == 1);
  141. }
  142. TEST_CASE("[Array] sort()") {
  143. Array arr;
  144. arr.push_back(3);
  145. arr.push_back(4);
  146. arr.push_back(2);
  147. arr.push_back(1);
  148. arr.sort();
  149. int val = 1;
  150. for (int i = 0; i < arr.size(); i++) {
  151. CHECK(int(arr[i]) == val);
  152. val++;
  153. }
  154. }
  155. TEST_CASE("[Array] push_front(), pop_front(), pop_back()") {
  156. Array arr;
  157. arr.push_front(1);
  158. arr.push_front(2);
  159. CHECK(int(arr[0]) == 2);
  160. arr.pop_front();
  161. CHECK(int(arr[0]) == 1);
  162. CHECK(arr.size() == 1);
  163. arr.push_front(2);
  164. arr.push_front(3);
  165. arr.pop_back();
  166. CHECK(int(arr[1]) == 2);
  167. CHECK(arr.size() == 2);
  168. }
  169. TEST_CASE("[Array] pop_at()") {
  170. ErrorDetector ed;
  171. Array arr;
  172. arr.push_back(2);
  173. arr.push_back(4);
  174. arr.push_back(6);
  175. arr.push_back(8);
  176. arr.push_back(10);
  177. REQUIRE(int(arr.pop_at(2)) == 6);
  178. REQUIRE(arr.size() == 4);
  179. CHECK(int(arr[0]) == 2);
  180. CHECK(int(arr[1]) == 4);
  181. CHECK(int(arr[2]) == 8);
  182. CHECK(int(arr[3]) == 10);
  183. REQUIRE(int(arr.pop_at(2)) == 8);
  184. REQUIRE(arr.size() == 3);
  185. CHECK(int(arr[0]) == 2);
  186. CHECK(int(arr[1]) == 4);
  187. CHECK(int(arr[2]) == 10);
  188. // Negative index.
  189. REQUIRE(int(arr.pop_at(-1)) == 10);
  190. REQUIRE(arr.size() == 2);
  191. CHECK(int(arr[0]) == 2);
  192. CHECK(int(arr[1]) == 4);
  193. // Invalid pop.
  194. ed.clear();
  195. ERR_PRINT_OFF;
  196. const Variant ret = arr.pop_at(-15);
  197. ERR_PRINT_ON;
  198. REQUIRE(ret.is_null());
  199. CHECK(ed.has_error);
  200. REQUIRE(int(arr.pop_at(0)) == 2);
  201. REQUIRE(arr.size() == 1);
  202. CHECK(int(arr[0]) == 4);
  203. REQUIRE(int(arr.pop_at(0)) == 4);
  204. REQUIRE(arr.is_empty());
  205. // Pop from empty array.
  206. ed.clear();
  207. REQUIRE(arr.pop_at(24).is_null());
  208. CHECK_FALSE(ed.has_error);
  209. }
  210. TEST_CASE("[Array] max() and min()") {
  211. Array arr;
  212. arr.push_back(3);
  213. arr.push_front(4);
  214. arr.push_back(5);
  215. arr.push_back(2);
  216. int max = int(arr.max());
  217. int min = int(arr.min());
  218. CHECK(max == 5);
  219. CHECK(min == 2);
  220. }
  221. TEST_CASE("[Array] slice()") {
  222. Array array;
  223. array.push_back(0);
  224. array.push_back(1);
  225. array.push_back(2);
  226. array.push_back(3);
  227. array.push_back(4);
  228. array.push_back(5);
  229. Array slice0 = array.slice(0, 0);
  230. CHECK(slice0.size() == 0);
  231. Array slice1 = array.slice(1, 3);
  232. CHECK(slice1.size() == 2);
  233. CHECK(slice1[0] == Variant(1));
  234. CHECK(slice1[1] == Variant(2));
  235. Array slice2 = array.slice(1, -1);
  236. CHECK(slice2.size() == 4);
  237. CHECK(slice2[0] == Variant(1));
  238. CHECK(slice2[1] == Variant(2));
  239. CHECK(slice2[2] == Variant(3));
  240. CHECK(slice2[3] == Variant(4));
  241. Array slice3 = array.slice(3);
  242. CHECK(slice3.size() == 3);
  243. CHECK(slice3[0] == Variant(3));
  244. CHECK(slice3[1] == Variant(4));
  245. CHECK(slice3[2] == Variant(5));
  246. Array slice4 = array.slice(2, -2);
  247. CHECK(slice4.size() == 2);
  248. CHECK(slice4[0] == Variant(2));
  249. CHECK(slice4[1] == Variant(3));
  250. Array slice5 = array.slice(-2);
  251. CHECK(slice5.size() == 2);
  252. CHECK(slice5[0] == Variant(4));
  253. CHECK(slice5[1] == Variant(5));
  254. Array slice6 = array.slice(2, 42);
  255. CHECK(slice6.size() == 4);
  256. CHECK(slice6[0] == Variant(2));
  257. CHECK(slice6[1] == Variant(3));
  258. CHECK(slice6[2] == Variant(4));
  259. CHECK(slice6[3] == Variant(5));
  260. Array slice7 = array.slice(4, 0, -2);
  261. CHECK(slice7.size() == 2);
  262. CHECK(slice7[0] == Variant(4));
  263. CHECK(slice7[1] == Variant(2));
  264. Array slice8 = array.slice(5, 0, -2);
  265. CHECK(slice8.size() == 3);
  266. CHECK(slice8[0] == Variant(5));
  267. CHECK(slice8[1] == Variant(3));
  268. CHECK(slice8[2] == Variant(1));
  269. Array slice9 = array.slice(10, 0, -2);
  270. CHECK(slice9.size() == 3);
  271. CHECK(slice9[0] == Variant(5));
  272. CHECK(slice9[1] == Variant(3));
  273. CHECK(slice9[2] == Variant(1));
  274. Array slice10 = array.slice(2, -10, -1);
  275. CHECK(slice10.size() == 3);
  276. CHECK(slice10[0] == Variant(2));
  277. CHECK(slice10[1] == Variant(1));
  278. CHECK(slice10[2] == Variant(0));
  279. ERR_PRINT_OFF;
  280. Array slice11 = array.slice(4, 1);
  281. CHECK(slice11.size() == 0);
  282. Array slice12 = array.slice(3, -4);
  283. CHECK(slice12.size() == 0);
  284. ERR_PRINT_ON;
  285. Array slice13 = Array().slice(1);
  286. CHECK(slice13.size() == 0);
  287. Array slice14 = array.slice(6);
  288. CHECK(slice14.size() == 0);
  289. }
  290. TEST_CASE("[Array] Duplicate array") {
  291. // a = [1, [2, 2], {3: 3}]
  292. Array a = build_array(1, build_array(2, 2), build_dictionary(3, 3));
  293. // Deep copy
  294. Array deep_a = a.duplicate(true);
  295. CHECK_MESSAGE(deep_a.id() != a.id(), "Should create a new array");
  296. CHECK_MESSAGE(Array(deep_a[1]).id() != Array(a[1]).id(), "Should clone nested array");
  297. CHECK_MESSAGE(Dictionary(deep_a[2]).id() != Dictionary(a[2]).id(), "Should clone nested dictionary");
  298. CHECK_EQ(deep_a, a);
  299. deep_a.push_back(1);
  300. CHECK_NE(deep_a, a);
  301. deep_a.pop_back();
  302. Array(deep_a[1]).push_back(1);
  303. CHECK_NE(deep_a, a);
  304. Array(deep_a[1]).pop_back();
  305. CHECK_EQ(deep_a, a);
  306. // Shallow copy
  307. Array shallow_a = a.duplicate(false);
  308. CHECK_MESSAGE(shallow_a.id() != a.id(), "Should create a new array");
  309. CHECK_MESSAGE(Array(shallow_a[1]).id() == Array(a[1]).id(), "Should keep nested array");
  310. CHECK_MESSAGE(Dictionary(shallow_a[2]).id() == Dictionary(a[2]).id(), "Should keep nested dictionary");
  311. CHECK_EQ(shallow_a, a);
  312. Array(shallow_a).push_back(1);
  313. CHECK_NE(shallow_a, a);
  314. }
  315. TEST_CASE("[Array] Duplicate recursive array") {
  316. // Self recursive
  317. Array a;
  318. a.push_back(a);
  319. Array a_shallow = a.duplicate(false);
  320. CHECK_EQ(a, a_shallow);
  321. // Deep copy of recursive array ends up with recursion limit and return
  322. // an invalid result (multiple nested arrays), the point is we should
  323. // not end up with a segfault and an error log should be printed
  324. ERR_PRINT_OFF;
  325. a.duplicate(true);
  326. ERR_PRINT_ON;
  327. // Nested recursive
  328. Array a1;
  329. Array a2;
  330. a2.push_back(a1);
  331. a1.push_back(a2);
  332. Array a1_shallow = a1.duplicate(false);
  333. CHECK_EQ(a1, a1_shallow);
  334. // Same deep copy issue as above
  335. ERR_PRINT_OFF;
  336. a1.duplicate(true);
  337. ERR_PRINT_ON;
  338. // Break the recursivity otherwise Array teardown will leak memory
  339. a.clear();
  340. a1.clear();
  341. a2.clear();
  342. }
  343. TEST_CASE("[Array] Hash array") {
  344. // a = [1, [2, 2], {3: 3}]
  345. Array a = build_array(1, build_array(2, 2), build_dictionary(3, 3));
  346. uint32_t original_hash = a.hash();
  347. a.push_back(1);
  348. CHECK_NE(a.hash(), original_hash);
  349. a.pop_back();
  350. CHECK_EQ(a.hash(), original_hash);
  351. Array(a[1]).push_back(1);
  352. CHECK_NE(a.hash(), original_hash);
  353. Array(a[1]).pop_back();
  354. CHECK_EQ(a.hash(), original_hash);
  355. (Dictionary(a[2]))[1] = 1;
  356. CHECK_NE(a.hash(), original_hash);
  357. Dictionary(a[2]).erase(1);
  358. CHECK_EQ(a.hash(), original_hash);
  359. Array a2 = a.duplicate(true);
  360. CHECK_EQ(a2.hash(), a.hash());
  361. }
  362. TEST_CASE("[Array] Hash recursive array") {
  363. Array a1;
  364. a1.push_back(a1);
  365. Array a2;
  366. a2.push_back(a2);
  367. // Hash should reach recursion limit
  368. ERR_PRINT_OFF;
  369. CHECK_EQ(a1.hash(), a2.hash());
  370. ERR_PRINT_ON;
  371. // Break the recursivity otherwise Array teardown will leak memory
  372. a1.clear();
  373. a2.clear();
  374. }
  375. TEST_CASE("[Array] Empty comparison") {
  376. Array a1;
  377. Array a2;
  378. // test both operator== and operator!=
  379. CHECK_EQ(a1, a2);
  380. CHECK_FALSE(a1 != a2);
  381. }
  382. TEST_CASE("[Array] Flat comparison") {
  383. Array a1 = build_array(1);
  384. Array a2 = build_array(1);
  385. Array other_a = build_array(2);
  386. // test both operator== and operator!=
  387. CHECK_EQ(a1, a1); // compare self
  388. CHECK_FALSE(a1 != a1);
  389. CHECK_EQ(a1, a2); // different equivalent arrays
  390. CHECK_FALSE(a1 != a2);
  391. CHECK_NE(a1, other_a); // different arrays with different content
  392. CHECK_FALSE(a1 == other_a);
  393. }
  394. TEST_CASE("[Array] Nested array comparison") {
  395. // a1 = [[[1], 2], 3]
  396. Array a1 = build_array(build_array(build_array(1), 2), 3);
  397. Array a2 = a1.duplicate(true);
  398. // other_a = [[[1, 0], 2], 3]
  399. Array other_a = build_array(build_array(build_array(1, 0), 2), 3);
  400. // test both operator== and operator!=
  401. CHECK_EQ(a1, a1); // compare self
  402. CHECK_FALSE(a1 != a1);
  403. CHECK_EQ(a1, a2); // different equivalent arrays
  404. CHECK_FALSE(a1 != a2);
  405. CHECK_NE(a1, other_a); // different arrays with different content
  406. CHECK_FALSE(a1 == other_a);
  407. }
  408. TEST_CASE("[Array] Nested dictionary comparison") {
  409. // a1 = [{1: 2}, 3]
  410. Array a1 = build_array(build_dictionary(1, 2), 3);
  411. Array a2 = a1.duplicate(true);
  412. // other_a = [{1: 0}, 3]
  413. Array other_a = build_array(build_dictionary(1, 0), 3);
  414. // test both operator== and operator!=
  415. CHECK_EQ(a1, a1); // compare self
  416. CHECK_FALSE(a1 != a1);
  417. CHECK_EQ(a1, a2); // different equivalent arrays
  418. CHECK_FALSE(a1 != a2);
  419. CHECK_NE(a1, other_a); // different arrays with different content
  420. CHECK_FALSE(a1 == other_a);
  421. }
  422. TEST_CASE("[Array] Recursive comparison") {
  423. Array a1;
  424. a1.push_back(a1);
  425. Array a2;
  426. a2.push_back(a2);
  427. // Comparison should reach recursion limit
  428. ERR_PRINT_OFF;
  429. CHECK_EQ(a1, a2);
  430. CHECK_FALSE(a1 != a2);
  431. ERR_PRINT_ON;
  432. a1.push_back(1);
  433. a2.push_back(1);
  434. // Comparison should reach recursion limit
  435. ERR_PRINT_OFF;
  436. CHECK_EQ(a1, a2);
  437. CHECK_FALSE(a1 != a2);
  438. ERR_PRINT_ON;
  439. a1.push_back(1);
  440. a2.push_back(2);
  441. // Comparison should reach recursion limit
  442. ERR_PRINT_OFF;
  443. CHECK_NE(a1, a2);
  444. CHECK_FALSE(a1 == a2);
  445. ERR_PRINT_ON;
  446. // Break the recursivity otherwise Array tearndown will leak memory
  447. a1.clear();
  448. a2.clear();
  449. }
  450. TEST_CASE("[Array] Recursive self comparison") {
  451. Array a1;
  452. Array a2;
  453. a2.push_back(a1);
  454. a1.push_back(a2);
  455. CHECK_EQ(a1, a1);
  456. CHECK_FALSE(a1 != a1);
  457. // Break the recursivity otherwise Array tearndown will leak memory
  458. a1.clear();
  459. a2.clear();
  460. }
  461. TEST_CASE("[Array] Iteration") {
  462. Array a1 = build_array(1, 2, 3);
  463. Array a2 = build_array(1, 2, 3);
  464. int idx = 0;
  465. for (Variant &E : a1) {
  466. CHECK_EQ(int(a2[idx]), int(E));
  467. idx++;
  468. }
  469. CHECK_EQ(idx, a1.size());
  470. idx = 0;
  471. for (const Variant &E : (const Array &)a1) {
  472. CHECK_EQ(int(a2[idx]), int(E));
  473. idx++;
  474. }
  475. CHECK_EQ(idx, a1.size());
  476. a1.clear();
  477. }
  478. TEST_CASE("[Array] Iteration and modification") {
  479. Array a1 = build_array(1, 2, 3);
  480. Array a2 = build_array(2, 3, 4);
  481. Array a3 = build_array(1, 2, 3);
  482. Array a4 = build_array(1, 2, 3);
  483. a3.make_read_only();
  484. int idx = 0;
  485. for (Variant &E : a1) {
  486. E = a2[idx];
  487. idx++;
  488. }
  489. CHECK_EQ(a1, a2);
  490. // Ensure read-only is respected.
  491. idx = 0;
  492. for (Variant &E : a3) {
  493. E = a2[idx];
  494. }
  495. CHECK_EQ(a3, a4);
  496. a1.clear();
  497. a2.clear();
  498. a4.clear();
  499. }
  500. TEST_CASE("[Array] Typed copying") {
  501. TypedArray<int> a1;
  502. a1.push_back(1);
  503. TypedArray<double> a2;
  504. a2.push_back(1.0);
  505. Array a3 = a1;
  506. TypedArray<int> a4 = a3;
  507. Array a5 = a2;
  508. TypedArray<int> a6 = a5;
  509. a3[0] = 2;
  510. a4[0] = 3;
  511. // Same typed TypedArray should be shared.
  512. CHECK_EQ(a1[0], Variant(3));
  513. CHECK_EQ(a3[0], Variant(3));
  514. CHECK_EQ(a4[0], Variant(3));
  515. a5[0] = 2.0;
  516. a6[0] = 3.0;
  517. // Different typed TypedArray should not be shared.
  518. CHECK_EQ(a2[0], Variant(2.0));
  519. CHECK_EQ(a5[0], Variant(2.0));
  520. CHECK_EQ(a6[0], Variant(3.0));
  521. a1.clear();
  522. a2.clear();
  523. a3.clear();
  524. a4.clear();
  525. a5.clear();
  526. a6.clear();
  527. }
  528. static bool _find_custom_callable(const Variant &p_val) {
  529. return (int)p_val % 2 == 0;
  530. }
  531. TEST_CASE("[Array] Test find_custom") {
  532. Array a1 = build_array(1, 3, 4, 5, 8, 9);
  533. // Find first even number.
  534. int index = a1.find_custom(callable_mp_static(_find_custom_callable));
  535. CHECK_EQ(index, 2);
  536. }
  537. TEST_CASE("[Array] Test rfind_custom") {
  538. Array a1 = build_array(1, 3, 4, 5, 8, 9);
  539. // Find last even number.
  540. int index = a1.rfind_custom(callable_mp_static(_find_custom_callable));
  541. CHECK_EQ(index, 4);
  542. }
  543. } // namespace TestArray
  544. #endif // TEST_ARRAY_H