y_functional_tests.inc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. Legal:
  3. Version: MPL 1.1
  4. The contents of this file are subject to the Mozilla Public License Version
  5. 1.1 the "License"; you may not use this file except in compliance with
  6. the License. You may obtain a copy of the License at
  7. http://www.mozilla.org/MPL/
  8. Software distributed under the License is distributed on an "AS IS" basis,
  9. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  10. for the specific language governing rights and limitations under the
  11. License.
  12. The Original Code is the YSI framework.
  13. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  14. Portions created by the Initial Developer are Copyright C 2011
  15. the Initial Developer. All Rights Reserved.
  16. Contributors:
  17. Y_Less
  18. koolk
  19. JoeBullet/Google63
  20. g_aSlice/Slice
  21. Misiur
  22. samphunter
  23. tianmeta
  24. maddinat0r
  25. spacemud
  26. Crayder
  27. Dayvison
  28. Ahmad45123
  29. Zeex
  30. irinel1996
  31. Yiin-
  32. Chaprnks
  33. Konstantinos
  34. Masterchen09
  35. Southclaws
  36. PatchwerkQWER
  37. m0k1
  38. paulommu
  39. udan111
  40. Thanks:
  41. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  42. ZeeX - Very productive conversations.
  43. koolk - IsPlayerinAreaEx code.
  44. TheAlpha - Danish translation.
  45. breadfish - German translation.
  46. Fireburn - Dutch translation.
  47. yom - French translation.
  48. 50p - Polish translation.
  49. Zamaroht - Spanish translation.
  50. Los - Portuguese translation.
  51. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  52. me to strive to better.
  53. Pixels^ - Running XScripters where the idea was born.
  54. Matite - Pestering me to release it and using it.
  55. Very special thanks to:
  56. Thiadmer - PAWN, whose limits continue to amaze me!
  57. Kye/Kalcor - SA:MP.
  58. SA:MP Team past, present and future - SA:MP.
  59. Optional plugins:
  60. Gamer_Z - GPS.
  61. Incognito - Streamer.
  62. Me - sscanf2, fixes2, Whirlpool.
  63. */
  64. #define FUNC_CHECK_ARR(%0,%1) for (new __i, __j = min(sizeof (%0), sizeof (%1)); __i != __j; ++__i) ASSERT(%0[__i] == %1[__i])
  65. TEST__ FUNC_Map1()
  66. {
  67. new
  68. a0[10] = {0, 1, 2, ...},
  69. a1[10] = {0, 2, 4, ...};
  70. inline const Double(x)
  71. {
  72. @return x * 2;
  73. }
  74. Map(using inline Double, a0, a0);
  75. FUNC_CHECK_ARR(a0, a1);
  76. }
  77. TEST__ FUNC_Map2()
  78. {
  79. new
  80. a0[10] = {0, 1, 2, ...},
  81. a1[10] = {0, 2, 4, ...},
  82. a2[10] = {0, 1, 2, ...},
  83. a3[10];
  84. inline const Double(x)
  85. {
  86. @return x * 2;
  87. }
  88. Map(using inline Double, a0, a3);
  89. FUNC_CHECK_ARR(a0, a2);
  90. FUNC_CHECK_ARR(a3, a1);
  91. }
  92. TEST__ FUNC_Map3()
  93. {
  94. new
  95. a0[10] = {0, 1, 2, ...},
  96. a1[10] = {1, 4, 7, ...},
  97. a2[10] = {0, 1, 2, ...},
  98. a3[10];
  99. Map({_0 * 3 + 1}, a0, a3);
  100. FUNC_CHECK_ARR(a0, a2);
  101. FUNC_CHECK_ARR(a3, a1);
  102. }
  103. TEST__ FUNC_Map_1()
  104. {
  105. new
  106. a0[10] = {0, 1, 2, ...},
  107. a1[10] = {0, 1, 2, ...};
  108. inline const Triple(x)
  109. {
  110. @return x * 3;
  111. }
  112. Map_(using inline Triple, a0);
  113. FUNC_CHECK_ARR(a0, a1);
  114. }
  115. TEST__ FUNC_Map_2()
  116. {
  117. new
  118. a0[10] = {0, 1, 2, ...},
  119. a1[10] = {0, 1, 2, ...};
  120. Map_({_0 * 4}, a0);
  121. FUNC_CHECK_ARR(a0, a1);
  122. }
  123. TEST__ FUNC_MapIdx()
  124. {
  125. new
  126. a0[10] = {1, ...},
  127. a1[10] = {2, 4, 6, ...};
  128. inline const AddAndMul(idx, x)
  129. {
  130. @return (x + idx) * 2;
  131. }
  132. MapIdx(using inline AddAndMul, a0, a0);
  133. FUNC_CHECK_ARR(a0, a1);
  134. }
  135. TEST__ FUNC_MapIdx_()
  136. {
  137. new
  138. a0[10] = {0, 1, 2, ...},
  139. a1[10] = {0, 1, 2, ...};
  140. inline const Thing(idx, x)
  141. {
  142. #pragma unused idx, x
  143. @return 42;
  144. }
  145. MapIdx_(using inline Thing, a0);
  146. FUNC_CHECK_ARR(a0, a1);
  147. }
  148. TEST__ FUNC_ZipWith()
  149. {
  150. new
  151. a0[10] = { 0, 1, 2, ...},
  152. a1[10] = {10, 20, 30, ...},
  153. a2[10],
  154. a3[10] = { 0, 20, 60, 120, 200, 300, 420, 560, 720, 900};
  155. inline const Mul(a, b) @return a * b;
  156. ZipWith(using inline Mul, a0, a1, a2);
  157. FUNC_CHECK_ARR(a2, a3);
  158. }
  159. TEST__ FUNC_ZipWith3()
  160. {
  161. new
  162. a0[10] = { 0, 1, 2, ...},
  163. a1[10] = {10, 20, 30, ...},
  164. a9[10] = {22, ...},
  165. a2[10],
  166. a3[10] = {22, 42, 82, 142, 222, 322, 442, 582, 742, 922};
  167. inline const MulAdd(a, b, c) @return a * b + c;
  168. ZipWith3(using inline MulAdd, a0, a1, a9, a2);
  169. FUNC_CHECK_ARR(a2, a3);
  170. }
  171. TEST__ FUNC_FoldR1()
  172. {
  173. new
  174. a0[10] = { 0, 1, 2, ...},
  175. ret;
  176. ret = FoldR({_0 * _1}, a0, 10);
  177. ASSERT_ZE(ret);
  178. }
  179. TEST__ FUNC_FoldR2()
  180. {
  181. new
  182. a0[10] = { 1, 2, 3, ...},
  183. ret;
  184. ret = FoldR({_0 * _1}, a0, 10);
  185. ASSERT_EQ(ret, 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 10);
  186. }
  187. TEST__ FUNC_FoldL1()
  188. {
  189. new
  190. a0[10] = { 1, 2, 3, ...},
  191. ret;
  192. ret = FoldL({_0 * _1}, 11, a0);
  193. ASSERT_EQ(ret, 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11);
  194. }
  195. TEST__ FUNC_FoldL_multiple()
  196. {
  197. new
  198. a0[10] = { 1, 2, 3, ...},
  199. ret;
  200. ret = FoldL({ _0 * _1 }, 11, a0) + FoldL({ _0 + _1 }, 11, a0);
  201. ASSERT_EQ(ret, 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11);
  202. }
  203. static FUNC_FoldL_nested_Add(a, b)
  204. {
  205. return a + b;
  206. }
  207. TEST__ FUNC_FoldL_params()
  208. {
  209. new
  210. a0[10] = { 1, 2, 3, ...},
  211. ret;
  212. ret = FUNC_FoldL_nested_Add(FoldL({ _0 * _1 }, 11, a0), FoldL({ _0 + _1 }, 11, a0));
  213. ASSERT_EQ(ret, 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11);
  214. }
  215. TEST__ FUNC_FoldL_nested()
  216. {
  217. new
  218. a0[10] = { 1, 2, 3, ...},
  219. ret;
  220. ret = FoldL({ _0 * _1 }, FoldL({ _0 + _1 }, 11, a0), a0);
  221. ASSERT_EQ(ret, 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11));
  222. }
  223. TEST__ FUNC_FoldR3()
  224. {
  225. new
  226. a0[10] = { 1, 2, 3, ...},
  227. ret;
  228. ret = FoldR({_0 * _1}, a0, 15, 0);
  229. ASSERT_EQ(ret, 15);
  230. }
  231. TEST__ FUNC_FoldL2()
  232. {
  233. new
  234. a0[10] = { 1, 2, 3, ...},
  235. ret;
  236. ret = FoldL({_0 * _1}, 99, a0, 0);
  237. ASSERT_EQ(ret, 99);
  238. }
  239. #undef FUNC_CHECK_ARR