tests.inc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  1. #assert MAX_PLAYERS >= 50
  2. Test:000_y_groups_Global()
  3. {
  4. // Need a certain number just to run this code.
  5. call OnPlayerConnect(42);
  6. ASSERT(Group_GetPlayer(GROUP_GLOBAL, 42));
  7. //call OnPlayerDisconnect(42, 0);
  8. }
  9. Test:y_groups_Valid()
  10. {
  11. new
  12. Group:g = Group_Create("Valid"),
  13. Group:i = Group_Create("Invalid");
  14. Group_Destroy(i);
  15. ASSERT_TRUE(Group_IsValid(g));
  16. ASSERT_FALSE(Group_IsValid(i));
  17. ASSERT_FALSE(Group_IsValid(Group:3));
  18. Group_Destroy(g);
  19. }
  20. Test:y_groups_Create0()
  21. {
  22. new
  23. Group:g = Group_Create();
  24. ASSERT(g != INVALID_GROUP);
  25. Group_Destroy(g);
  26. }
  27. Test:y_groups_Create0b()
  28. {
  29. new
  30. Group:g0 = Group_Create("hello"),
  31. Group:g1 = Group_Create("there");
  32. ASSERT(g0 != INVALID_GROUP);
  33. ASSERT(g1 != INVALID_GROUP);
  34. ASSERT(g0 != g1);
  35. Group_Destroy(g0);
  36. Group_Destroy(g1);
  37. }
  38. Test:y_groups_Create1()
  39. {
  40. new
  41. Group:g = Group_Create("Group 1");
  42. ASSERT(g != INVALID_GROUP);
  43. Group_Destroy(g);
  44. }
  45. Test:y_groups_GetID()
  46. {
  47. new
  48. Group:g = Group_Create("Group 2");
  49. ASSERT(g == Group_GetID("Group 2"));
  50. ASSERT(!strcmp("Group 2", Group_GetName(g)));
  51. Group_Destroy(g);
  52. }
  53. Test:y_groups_GetGang0()
  54. {
  55. new
  56. Group:g = Group_Create("Group 3");
  57. ASSERT_FALSE(Group_GetGang(g));
  58. Group_Destroy(g);
  59. }
  60. Test:y_groups_GetGang1()
  61. {
  62. new
  63. Group:g = Group_Create("Group 4");
  64. Group_SetGang(g, true);
  65. ASSERT_TRUE(Group_GetGang(g));
  66. Group_Destroy(g);
  67. }
  68. Test:y_groups_GetGang2()
  69. {
  70. new
  71. Group:g = Group_Create("Group 5");
  72. Group_SetGang(g, true);
  73. Group_SetGang(g, false);
  74. ASSERT_FALSE(Group_GetGang(g));
  75. Group_Destroy(g);
  76. }
  77. Test:y_groups_GetColour()
  78. {
  79. new
  80. Group:g = Group_Create("Group 6");
  81. Group_SetColour(g, 0x11227654);
  82. ASSERT(Group_GetColor(g) == 0x112276AA);
  83. Group_SetColour(g, 0x76541122);
  84. ASSERT(Group_GetColor(g) == 0x765411AA);
  85. Group_SetColour(g, 0x65127412);
  86. ASSERT(Group_GetColor(g) == 0x651274AA);
  87. Group_Destroy(g);
  88. }
  89. Test:y_groups_Set1()
  90. {
  91. new
  92. Group:g = Group_Create("Group 7");
  93. ASSERT(Group_GetCount(g) == 0);
  94. Group_SetPlayer(g, 42, true);
  95. ASSERT_TRUE(Group_GetPlayer(g, 42));
  96. ASSERT(Group_GetCount(g) == 1);
  97. new
  98. c = 0;
  99. foreach (new p : GroupMember[g])
  100. {
  101. ASSERT(p == 42);
  102. ++c;
  103. }
  104. ASSERT(c == 1);
  105. Group_Destroy(g);
  106. }
  107. Test:y_groups_Set2()
  108. {
  109. new
  110. Group:g = Group_Create("Group 8");
  111. ASSERT(Group_GetCount(g) == 0);
  112. //new k = Group_SetPlayer(g, 42, true);
  113. Group_SetPlayer(g, 42, true);
  114. ASSERT(Group_GetCount(g) == 1);
  115. Group_SetPlayer(g, 42, false);
  116. ASSERT(Group_GetCount(g) == 0);
  117. new
  118. c = 0;
  119. foreach (new p : GroupMember(g))
  120. {
  121. ++c;
  122. }
  123. ASSERT(c == 0);
  124. Group_Destroy(g);
  125. }
  126. Test:y_groups_Set3()
  127. {
  128. new
  129. Group:g = Group_Create("Group 8");
  130. Group_SetPlayer(g, 42, true);
  131. ASSERT(Group_GetCount(g) == 1);
  132. call OnPlayerDisconnect(42, 0);
  133. Group_Destroy(g);
  134. }
  135. Test:y_groups_SetBalanced0()
  136. {
  137. new
  138. Group:g1 = Group_Create("Group 1"),
  139. Group:g2 = Group_Create("Group 2");
  140. call OnPlayerConnect(22);
  141. Group_SetPlayer(g2, 22, true);
  142. Group_SetBalanced(22, g1, g2);
  143. ASSERT(Group_GetCount(g1) == 0 && Group_GetCount(g2) == 1);
  144. call OnPlayerDisconnect(22, 0);
  145. Group_Destroy(g1);
  146. Group_Destroy(g2);
  147. }
  148. Test:y_groups_SetBalanced1()
  149. {
  150. new
  151. Group:g1 = Group_Create("Group 1"),
  152. Group:g2 = Group_Create("Group 2");
  153. call OnPlayerConnect(23);
  154. call OnPlayerConnect(32);
  155. Group_SetBalanced(23, g1, g2);
  156. Group_SetBalanced(32, g1, g2);
  157. ASSERT(Group_GetCount(g1) == 1 && Group_GetCount(g2) == 1);
  158. call OnPlayerDisconnect(23, 0);
  159. call OnPlayerDisconnect(32, 0);
  160. Group_Destroy(g1);
  161. Group_Destroy(g2);
  162. }
  163. Test:y_groups_SetBalanced2()
  164. {
  165. new
  166. Group:g1 = Group_Create("Group 1"),
  167. Group:g2 = Group_Create("Group 2"),
  168. Group:g3 = Group_Create("Group 3");
  169. call OnPlayerConnect(1);
  170. call OnPlayerConnect(2);
  171. call OnPlayerConnect(3);
  172. call OnPlayerConnect(4);
  173. call OnPlayerConnect(5);
  174. call OnPlayerConnect(6);
  175. Group_SetBalanced(1, g1, g2, g3);
  176. Group_SetBalanced(2, g1, g2, g3);
  177. Group_SetBalanced(3, g1, g2, g3);
  178. Group_SetBalanced(4, g1, g2, g3);
  179. Group_SetBalanced(5, g1, g2, g3);
  180. Group_SetBalanced(6, g1, g2, g3);
  181. ASSERT(Group_GetCount(g1) == 2 && Group_GetCount(g2) == 2 && Group_GetCount(g3) == 2);
  182. call OnPlayerDisconnect(1, 0);
  183. call OnPlayerDisconnect(2, 0);
  184. call OnPlayerDisconnect(3, 0);
  185. call OnPlayerDisconnect(4, 0);
  186. call OnPlayerDisconnect(5, 0);
  187. call OnPlayerDisconnect(6, 0);
  188. Group_Destroy(g1);
  189. Group_Destroy(g2);
  190. Group_Destroy(g3);
  191. }
  192. Test:y_groups_SetBalanced3()
  193. {
  194. new
  195. Group:g[3];
  196. g[0] = Group_Create("Group 1");
  197. g[1] = Group_Create("Group 2");
  198. g[2] = Group_Create("Group 3");
  199. call OnPlayerConnect(0);
  200. call OnPlayerConnect(1);
  201. call OnPlayerConnect(2);
  202. call OnPlayerConnect(3);
  203. call OnPlayerConnect(4);
  204. call OnPlayerConnect(5);
  205. call OnPlayerConnect(6);
  206. Group_SetBalancedArray(0, g, sizeof(g));
  207. Group_SetBalancedArray(1, g, sizeof(g));
  208. Group_SetBalancedArray(2, g, sizeof(g));
  209. Group_SetBalancedArray(3, g, sizeof(g));
  210. Group_SetBalancedArray(4, g, sizeof(g));
  211. Group_SetBalancedArray(5, g, sizeof(g));
  212. Group_SetBalancedArray(6, g, sizeof(g));
  213. ASSERT(Group_GetCount(g[0]) == 3);
  214. ASSERT(Group_GetCount(g[1]) == 2);
  215. ASSERT(Group_GetCount(g[2]) == 2);
  216. call OnPlayerDisconnect(0, 0);
  217. call OnPlayerDisconnect(1, 0);
  218. call OnPlayerDisconnect(2, 0);
  219. call OnPlayerDisconnect(3, 0);
  220. call OnPlayerDisconnect(4, 0);
  221. call OnPlayerDisconnect(5, 0);
  222. call OnPlayerDisconnect(6, 0);
  223. Group_Destroy(g[0]);
  224. Group_Destroy(g[1]);
  225. Group_Destroy(g[2]);
  226. }
  227. Test:y_groups_SetBalancedIn1()
  228. {
  229. new
  230. Group:g[3];
  231. g[0] = Group_Create("Group 1");
  232. g[1] = Group_Create("Group 2");
  233. g[2] = Group_Create("Group 3");
  234. call OnPlayerConnect(0);
  235. call OnPlayerConnect(1);
  236. call OnPlayerConnect(2);
  237. call OnPlayerConnect(3);
  238. call OnPlayerConnect(4);
  239. call OnPlayerConnect(5);
  240. call OnPlayerConnect(6);
  241. Group_SetPlayer(g[0], 0, true);
  242. Group_SetPlayer(g[0], 1, true);
  243. Group_SetPlayer(g[0], 2, true);
  244. Group_SetPlayer(g[2], 3, true);
  245. Group_SetPlayer(g[2], 4, true);
  246. Group_SetPlayer(g[2], 5, true);
  247. Group_SetBalancedArray(6, g, sizeof(g));
  248. ASSERT(Group_GetCount(g[0]) == 3);
  249. ASSERT(Group_GetCount(g[1]) == 1);
  250. ASSERT(Group_GetCount(g[2]) == 3);
  251. call OnPlayerDisconnect(0, 0);
  252. call OnPlayerDisconnect(1, 0);
  253. call OnPlayerDisconnect(2, 0);
  254. call OnPlayerDisconnect(3, 0);
  255. call OnPlayerDisconnect(4, 0);
  256. call OnPlayerDisconnect(5, 0);
  257. call OnPlayerDisconnect(6, 0);
  258. Group_Destroy(g[0]);
  259. Group_Destroy(g[1]);
  260. Group_Destroy(g[2]);
  261. }
  262. Test:y_groups_SetBalancedIn2()
  263. {
  264. new
  265. Group:g[3];
  266. g[0] = Group_Create("Group 1");
  267. g[1] = Group_Create("Group 2");
  268. g[2] = Group_Create("Group 3");
  269. call OnPlayerConnect(0);
  270. call OnPlayerConnect(1);
  271. call OnPlayerConnect(2);
  272. call OnPlayerConnect(3);
  273. call OnPlayerConnect(4);
  274. call OnPlayerConnect(5);
  275. call OnPlayerConnect(6);
  276. Group_SetPlayer(g[0], 0, true);
  277. Group_SetPlayer(g[0], 1, true);
  278. Group_SetPlayer(g[0], 2, true);
  279. Group_SetPlayer(g[2], 3, true);
  280. Group_SetPlayer(g[2], 4, true);
  281. Group_SetPlayer(g[2], 5, true);
  282. Group_SetBalancedArray(0, g, sizeof(g));
  283. ASSERT(Group_GetCount(g[0]) == 3);
  284. ASSERT(Group_GetCount(g[1]) == 0);
  285. ASSERT(Group_GetCount(g[2]) == 3);
  286. call OnPlayerDisconnect(0, 0);
  287. call OnPlayerDisconnect(1, 0);
  288. call OnPlayerDisconnect(2, 0);
  289. call OnPlayerDisconnect(3, 0);
  290. call OnPlayerDisconnect(4, 0);
  291. call OnPlayerDisconnect(5, 0);
  292. call OnPlayerDisconnect(6, 0);
  293. Group_Destroy(g[0]);
  294. Group_Destroy(g[1]);
  295. Group_Destroy(g[2]);
  296. }
  297. Test:y_groups_SetBalancedIn3()
  298. {
  299. new
  300. Group:g[3];
  301. g[0] = Group_Create("Group 1");
  302. g[1] = Group_Create("Group 2");
  303. g[2] = Group_Create("Group 3");
  304. call OnPlayerConnect(0);
  305. call OnPlayerConnect(1);
  306. call OnPlayerConnect(2);
  307. call OnPlayerConnect(3);
  308. call OnPlayerConnect(4);
  309. call OnPlayerConnect(5);
  310. call OnPlayerConnect(6);
  311. Group_SetPlayer(g[0], 0, true);
  312. Group_SetPlayer(g[0], 1, true);
  313. Group_SetPlayer(g[0], 2, true);
  314. Group_SetPlayer(g[2], 3, true);
  315. Group_SetPlayer(g[2], 4, true);
  316. Group_SetPlayer(g[2], 5, true);
  317. Group_SetBalancedArray(4, g, sizeof(g));
  318. ASSERT(Group_GetCount(g[0]) == 3);
  319. ASSERT(Group_GetCount(g[1]) == 0);
  320. ASSERT(Group_GetCount(g[2]) == 3);
  321. call OnPlayerDisconnect(0, 0);
  322. call OnPlayerDisconnect(1, 0);
  323. call OnPlayerDisconnect(2, 0);
  324. call OnPlayerDisconnect(3, 0);
  325. call OnPlayerDisconnect(4, 0);
  326. call OnPlayerDisconnect(5, 0);
  327. call OnPlayerDisconnect(6, 0);
  328. Group_Destroy(g[0]);
  329. Group_Destroy(g[1]);
  330. Group_Destroy(g[2]);
  331. }
  332. Test:y_groups_SetBalancedIn3a()
  333. {
  334. new
  335. Group:g[3];
  336. g[0] = Group_Create("Group 1");
  337. g[1] = Group_Create("Group 2");
  338. g[2] = Group_Create("Group 3");
  339. call OnPlayerConnect(0);
  340. call OnPlayerConnect(1);
  341. call OnPlayerConnect(2);
  342. call OnPlayerConnect(3);
  343. call OnPlayerConnect(4);
  344. call OnPlayerConnect(5);
  345. call OnPlayerConnect(6);
  346. Group_SetPlayer(g[0], 0, true);
  347. Group_SetPlayer(g[0], 1, true);
  348. Group_SetPlayer(g[1], 2, true);
  349. Group_SetPlayer(g[1], 3, true);
  350. Group_SetPlayer(g[2], 4, true);
  351. Group_SetPlayer(g[2], 5, true);
  352. Group_SetPlayer(g[0], 6, true);
  353. Group_SetBalancedArray(0, g, sizeof(g));
  354. ASSERT(Group_GetCount(g[0]) == 3);
  355. ASSERT(Group_GetCount(g[1]) == 2);
  356. ASSERT(Group_GetCount(g[2]) == 2);
  357. call OnPlayerDisconnect(0, 0);
  358. call OnPlayerDisconnect(1, 0);
  359. call OnPlayerDisconnect(2, 0);
  360. call OnPlayerDisconnect(3, 0);
  361. call OnPlayerDisconnect(4, 0);
  362. call OnPlayerDisconnect(5, 0);
  363. call OnPlayerDisconnect(6, 0);
  364. Group_Destroy(g[0]);
  365. Group_Destroy(g[1]);
  366. Group_Destroy(g[2]);
  367. }
  368. Test:y_groups_SetBalancedIn3b()
  369. {
  370. new
  371. Group:g[3];
  372. g[0] = Group_Create("Group 1");
  373. g[1] = Group_Create("Group 2");
  374. g[2] = Group_Create("Group 3");
  375. call OnPlayerConnect(0);
  376. call OnPlayerConnect(1);
  377. call OnPlayerConnect(2);
  378. call OnPlayerConnect(3);
  379. call OnPlayerConnect(4);
  380. call OnPlayerConnect(5);
  381. call OnPlayerConnect(6);
  382. Group_SetPlayer(g[0], 0, true);
  383. Group_SetPlayer(g[0], 1, true);
  384. Group_SetPlayer(g[1], 2, true);
  385. Group_SetPlayer(g[1], 3, true);
  386. Group_SetPlayer(g[2], 4, true);
  387. Group_SetPlayer(g[2], 5, true);
  388. Group_SetPlayer(g[1], 6, true);
  389. Group_SetBalancedArray(0, g, sizeof(g));
  390. ASSERT(Group_GetCount(g[0]) == 2);
  391. ASSERT(Group_GetCount(g[1]) == 3);
  392. ASSERT(Group_GetCount(g[2]) == 2);
  393. call OnPlayerDisconnect(0, 0);
  394. call OnPlayerDisconnect(1, 0);
  395. call OnPlayerDisconnect(2, 0);
  396. call OnPlayerDisconnect(3, 0);
  397. call OnPlayerDisconnect(4, 0);
  398. call OnPlayerDisconnect(5, 0);
  399. call OnPlayerDisconnect(6, 0);
  400. Group_Destroy(g[0]);
  401. Group_Destroy(g[1]);
  402. Group_Destroy(g[2]);
  403. }
  404. Test:y_groups_SetBalancedIn3c()
  405. {
  406. new
  407. Group:g[3];
  408. g[0] = Group_Create("Group 1");
  409. g[1] = Group_Create("Group 2");
  410. g[2] = Group_Create("Group 3");
  411. call OnPlayerConnect(0);
  412. call OnPlayerConnect(1);
  413. call OnPlayerConnect(2);
  414. call OnPlayerConnect(3);
  415. call OnPlayerConnect(4);
  416. call OnPlayerConnect(5);
  417. call OnPlayerConnect(6);
  418. Group_SetPlayer(g[0], 0, true);
  419. Group_SetPlayer(g[0], 1, true);
  420. Group_SetPlayer(g[1], 2, true);
  421. Group_SetPlayer(g[1], 3, true);
  422. Group_SetPlayer(g[2], 4, true);
  423. Group_SetPlayer(g[2], 5, true);
  424. Group_SetPlayer(g[2], 6, true);
  425. Group_SetBalancedArray(0, g, sizeof(g));
  426. ASSERT(Group_GetCount(g[0]) == 2);
  427. ASSERT(Group_GetCount(g[1]) == 2);
  428. ASSERT(Group_GetCount(g[2]) == 3);
  429. call OnPlayerDisconnect(0, 0);
  430. call OnPlayerDisconnect(1, 0);
  431. call OnPlayerDisconnect(2, 0);
  432. call OnPlayerDisconnect(3, 0);
  433. call OnPlayerDisconnect(4, 0);
  434. call OnPlayerDisconnect(5, 0);
  435. call OnPlayerDisconnect(6, 0);
  436. Group_Destroy(g[0]);
  437. Group_Destroy(g[1]);
  438. Group_Destroy(g[2]);
  439. }
  440. Test:y_groups_SetBalancedIn4()
  441. {
  442. new
  443. Group:g[3];
  444. g[0] = Group_Create("Group 1");
  445. g[1] = Group_Create("Group 2");
  446. g[2] = Group_Create("Group 3");
  447. call OnPlayerConnect(0);
  448. call OnPlayerConnect(1);
  449. call OnPlayerConnect(2);
  450. call OnPlayerConnect(3);
  451. call OnPlayerConnect(4);
  452. call OnPlayerConnect(5);
  453. call OnPlayerConnect(6);
  454. Group_SetPlayer(g[0], 0, true);
  455. Group_SetPlayer(g[0], 1, true);
  456. Group_SetPlayer(g[1], 2, true);
  457. Group_SetPlayer(g[1], 3, true);
  458. Group_SetPlayer(g[2], 4, true);
  459. Group_SetPlayer(g[1], 6, true);
  460. Group_SetBalancedArray(2, g, sizeof(g));
  461. ASSERT(Group_GetCount(g[0]) == 2);
  462. ASSERT(Group_GetCount(g[1]) == 3);
  463. ASSERT(Group_GetCount(g[2]) == 1);
  464. call OnPlayerDisconnect(0, 0);
  465. call OnPlayerDisconnect(1, 0);
  466. call OnPlayerDisconnect(2, 0);
  467. call OnPlayerDisconnect(3, 0);
  468. call OnPlayerDisconnect(4, 0);
  469. call OnPlayerDisconnect(5, 0);
  470. call OnPlayerDisconnect(6, 0);
  471. Group_Destroy(g[0]);
  472. Group_Destroy(g[1]);
  473. Group_Destroy(g[2]);
  474. }
  475. Test:y_groups_SetBalancedSingle()
  476. {
  477. new
  478. Group:g1 = Group_Create("Group 1"),
  479. Group:result;
  480. call OnPlayerConnect(0);
  481. result = Group_SetBalanced(0, g1, Group:11);
  482. ASSERT(result == g1);
  483. call OnPlayerDisconnect(0, 0);
  484. Group_Destroy(g1);
  485. }
  486. Test:y_groups_SetBalancedInvalid()
  487. {
  488. new
  489. Group:result;
  490. call OnPlayerConnect(0);
  491. result = Group_SetBalanced(0, Group:99, Group:88);
  492. ASSERT(result == INVALID_GROUP);
  493. call OnPlayerDisconnect(0, 0);
  494. }
  495. #define MASTER 60
  496. #tryinclude "..\YSI_Core\y_master"
  497. #tryinclude "..\..\YSI_Core\y_master"
  498. #define _GROUP_MAKE_NAME<%0...%1> %0Test%1
  499. #define _GROUP_MAKE_LIMIT 123
  500. #tryinclude "y_groups\_funcs"
  501. #tryinclude "_funcs"
  502. static
  503. gPl,
  504. gEl,
  505. bool:gS;
  506. Test_SetPlayer(el, playerid, bool:s)
  507. {
  508. P:1("Test_SetPlayer called: %d %d %d", el, playerid, s);
  509. gPl = playerid;
  510. gEl = el;
  511. gS = s;
  512. return 1;
  513. }
  514. Test:0_y_groups_Connect0()
  515. {
  516. gPl = INVALID_PLAYER_ID;
  517. gEl = 100;
  518. gS = false;
  519. //new
  520. // Group:g = Group_Create();
  521. call OnPlayerConnect(45);
  522. ASSERT(gPl == INVALID_PLAYER_ID);
  523. ASSERT(gEl == 100);
  524. ASSERT(gS == false);
  525. //printf("%d %d %d", gPl, gEl, gS);
  526. Test_InitialiseFromGroups(7);
  527. ASSERT(gPl == 45);
  528. ASSERT(gEl == 7);
  529. ASSERT(gS == true);
  530. call OnPlayerDisconnect(45, 0);
  531. }
  532. Test:0_y_groups_Connect1()
  533. {
  534. gPl = INVALID_PLAYER_ID;
  535. gEl = 100;
  536. gS = false;
  537. //new
  538. // Group:g = Group_Create();
  539. Test_InitialiseFromGroups(8);
  540. ASSERT(gPl != INVALID_PLAYER_ID);
  541. ASSERT(gEl != 100);
  542. ASSERT(gS != false);
  543. call OnPlayerConnect(43);
  544. ASSERT(gPl == 43);
  545. ASSERT(gEl == 8);
  546. ASSERT(gS == true);
  547. call OnPlayerDisconnect(43, 0);
  548. }
  549. Test:y_groups_Chains()
  550. {
  551. new
  552. Group:g = Group_Create();
  553. call OnPlayerConnect(44);
  554. ASSERT_FALSE(Group_GetPlayer(g, 44));
  555. Group_SetGlobalGroup(g, true);
  556. ASSERT_TRUE(Group_GetPlayer(g, 44));
  557. call OnPlayerDisconnect(44, 0);
  558. }
  559. Test:y_groups_Children0()
  560. {
  561. new
  562. Group:g0 = Group_Create();
  563. ASSERT(!Group_GetGlobalGroup(g0));
  564. Group_Destroy(g0);
  565. }
  566. Test:y_groups_Children1()
  567. {
  568. new
  569. Group:g0 = Group_Create(),
  570. Group:g1 = Group_Create(),
  571. Group:g2 = Group_Create();
  572. // Check groups ARE descendants of themselves.
  573. ASSERT(Group_IsDescendant(GROUP_GLOBAL, GROUP_GLOBAL));
  574. ASSERT(Group_IsDescendant(g0, g0));
  575. ASSERT(Group_IsDescendant(g1, g1));
  576. ASSERT(Group_IsDescendant(g2, g2));
  577. // Check there are no relationships at all.
  578. ASSERT(!Group_IsDescendant(g0, g1));
  579. ASSERT(!Group_IsDescendant(g0, g2));
  580. ASSERT(!Group_IsDescendant(g1, g0));
  581. ASSERT(!Group_IsDescendant(g1, g2));
  582. ASSERT(!Group_IsDescendant(g2, g0));
  583. ASSERT(!Group_IsDescendant(g2, g1));
  584. // Grlobal group.
  585. ASSERT(!Group_IsDescendant(GROUP_GLOBAL, g0));
  586. ASSERT(!Group_IsDescendant(GROUP_GLOBAL, g1));
  587. ASSERT(!Group_IsDescendant(GROUP_GLOBAL, g2));
  588. ASSERT(!Group_IsDescendant(g0, GROUP_GLOBAL));
  589. ASSERT(!Group_IsDescendant(g1, GROUP_GLOBAL));
  590. ASSERT(!Group_IsDescendant(g2, GROUP_GLOBAL));
  591. Group_Destroy(g0),
  592. Group_Destroy(g1),
  593. Group_Destroy(g2);
  594. }
  595. Test:y_groups_Children2()
  596. {
  597. new
  598. Group:g0 = Group_Create(),
  599. Group:g1 = Group_Create(),
  600. Group:g2 = Group_Create();
  601. // Check groups are children of themselves.
  602. ASSERT(!Group_GetGroup(GROUP_GLOBAL, GROUP_GLOBAL));
  603. ASSERT(!Group_GetGroup(g0, g0));
  604. ASSERT(!Group_GetGroup(g1, g1));
  605. ASSERT(!Group_GetGroup(g2, g2));
  606. // Check there are no relationships at all.
  607. ASSERT(!Group_GetGroup(g0, g1));
  608. ASSERT(!Group_GetGroup(g0, g2));
  609. ASSERT(!Group_GetGroup(g1, g0));
  610. ASSERT(!Group_GetGroup(g1, g2));
  611. ASSERT(!Group_GetGroup(g2, g0));
  612. ASSERT(!Group_GetGroup(g2, g1));
  613. // Grlobal group.
  614. ASSERT(!Group_GetGroup(GROUP_GLOBAL, g0));
  615. ASSERT(!Group_GetGroup(GROUP_GLOBAL, g1));
  616. ASSERT(!Group_GetGroup(GROUP_GLOBAL, g2));
  617. ASSERT(!Group_GetGroup(g0, GROUP_GLOBAL));
  618. ASSERT(!Group_GetGroup(g1, GROUP_GLOBAL));
  619. ASSERT(!Group_GetGroup(g2, GROUP_GLOBAL));
  620. Group_Destroy(g0),
  621. Group_Destroy(g1),
  622. Group_Destroy(g2);
  623. }
  624. Test:y_groups_Children3()
  625. {
  626. new
  627. Group:g0 = Group_Create(),
  628. Group:g1 = Group_Create(),
  629. Group:g2 = Group_Create();
  630. Group_AddChild(g0, g1);
  631. ASSERT(Group_IsDescendant(g0, g1));
  632. // Check there are no other relationships.
  633. ASSERT(!Group_IsDescendant(g0, g2));
  634. ASSERT(!Group_IsDescendant(g1, g0));
  635. ASSERT(!Group_IsDescendant(g1, g2));
  636. ASSERT(!Group_IsDescendant(g2, g0));
  637. ASSERT(!Group_IsDescendant(g2, g1));
  638. Group_Destroy(g0),
  639. Group_Destroy(g1),
  640. Group_Destroy(g2);
  641. }
  642. Test:y_groups_Children4()
  643. {
  644. new
  645. Group:g0 = Group_Create(),
  646. Group:g1 = Group_Create(),
  647. Group:g2 = Group_Create();
  648. Group_AddChild(g0, g1);
  649. Group_AddChild(g1, g2);
  650. // Test chaining.
  651. ASSERT(Group_IsDescendant(g0, g1));
  652. ASSERT(Group_IsDescendant(g1, g2));
  653. ASSERT(Group_IsDescendant(g0, g2));
  654. // Check there are no reverse relationships.
  655. ASSERT(!Group_IsDescendant(g1, g0));
  656. ASSERT(!Group_IsDescendant(g2, g0));
  657. ASSERT(!Group_IsDescendant(g2, g1));
  658. Group_Destroy(g0),
  659. Group_Destroy(g1),
  660. Group_Destroy(g2);
  661. }
  662. Test:y_groups_Children5()
  663. {
  664. new
  665. Group:g0 = Group_Create(),
  666. Group:g1 = Group_Create(),
  667. Group:g2 = Group_Create(),
  668. Group:g3 = Group_Create(),
  669. Group:g4 = Group_Create();
  670. Group_AddChild(g0, g1);
  671. Group_AddChild(g1, g2);
  672. Group_AddChild(g2, g0);
  673. Group_AddChild(g4, g0);
  674. // Test cycles don't hang.
  675. ASSERT(!Group_IsDescendant(g4, g3));
  676. ASSERT(!Group_IsDescendant(g3, g4));
  677. // Test cycles work.
  678. ASSERT(Group_IsDescendant(g4, g2));
  679. ASSERT(!Group_IsDescendant(g2, g4));
  680. ASSERT(Group_IsDescendant(g0, g2));
  681. ASSERT(Group_IsDescendant(g2, g0));
  682. Group_Destroy(g0),
  683. Group_Destroy(g1),
  684. Group_Destroy(g2);
  685. Group_Destroy(g3);
  686. Group_Destroy(g4);
  687. }
  688. Test:y_groups_Children6()
  689. {
  690. new
  691. Group:g0 = Group_Create(),
  692. Group:g1 = Group_Create(),
  693. Group:g2 = Group_Create();
  694. Group_AddChild(g0, g1);
  695. Group_AddChild(g1, g2);
  696. // Test removal
  697. ASSERT(Group_IsDescendant(g0, g2));
  698. Group_RemoveChild(g1, g2);
  699. ASSERT(!Group_IsDescendant(g0, g2));
  700. Group_AddChild(g1, g2);
  701. ASSERT(Group_IsDescendant(g0, g2));
  702. Group_Destroy(g1);
  703. ASSERT(!Group_IsDescendant(g0, g2));
  704. Group_Destroy(g0),
  705. Group_Destroy(g2);
  706. }
  707. Test:y_groups_Children7()
  708. {
  709. new
  710. Group:g0 = Group_Create(),
  711. Group:g1 = Group_Create(),
  712. Group:g2 = Group_Create();
  713. Group_AddChild(g0, g1);
  714. Group_AddChild(g1, g2);
  715. // Test chaining.
  716. ASSERT(Group_IsDescendant(g0, g1));
  717. ASSERT(Group_IsDescendant(g1, g2));
  718. ASSERT(Group_IsDescendant(g0, g2));
  719. // Check there are no reverse relationships.
  720. ASSERT(!Group_IsChild(g0, g2));
  721. Group_Destroy(g0),
  722. Group_Destroy(g1),
  723. Group_Destroy(g2);
  724. }
  725. Test:y_groups_ChildIterator0()
  726. {
  727. new
  728. Group:g0 = Group_Create(),
  729. Group:g1 = Group_Create(),
  730. Group:g2 = Group_Create();
  731. Group_AddChild(g0, g1);
  732. Group_AddChild(g0, g2);
  733. new
  734. total = 0;
  735. foreach (new Group:g : GroupChild(g0))
  736. {
  737. ++total;
  738. }
  739. ASSERT(total == 2);
  740. Group_Destroy(g0),
  741. Group_Destroy(g1),
  742. Group_Destroy(g2);
  743. }
  744. Test:y_groups_ChildIterator1()
  745. {
  746. new
  747. Group:g0 = Group_Create(),
  748. Group:g1 = Group_Create(),
  749. Group:g2 = Group_Create();
  750. Group_AddChild(g0, g1);
  751. Group_AddChild(g0, g2);
  752. ASSERT(Group_IsValid(g0));
  753. ASSERT(Group_IsValid(g1));
  754. ASSERT(Group_IsValid(g2));
  755. foreach (new Group:g : GroupChild(g0))
  756. {
  757. Group_Destroy(g);
  758. }
  759. ASSERT(Group_IsValid(g0));
  760. ASSERT(!Group_IsValid(g1));
  761. ASSERT(!Group_IsValid(g2));
  762. Group_Destroy(g0),
  763. ASSERT(!Group_IsValid(g0));
  764. }
  765. Test:y_groups_ChildIterator2()
  766. {
  767. new
  768. Group:g0 = Group_Create(),
  769. Group:g1 = Group_Create(),
  770. Group:g2 = Group_Create();
  771. Group_AddChild(g0, g1);
  772. Group_AddChild(g0, g2);
  773. ASSERT(Group_IsValid(g0));
  774. ASSERT(Group_IsValid(g1));
  775. ASSERT(Group_IsValid(g2));
  776. new
  777. total = 0;
  778. foreach (new Group:g : GroupChild[g0])
  779. {
  780. Group_Destroy(g);
  781. ++total;
  782. }
  783. ASSERT(total == 2);
  784. ASSERT(Group_IsValid(g0));
  785. ASSERT(!Group_IsValid(g1));
  786. ASSERT(!Group_IsValid(g2));
  787. Group_Destroy(g0),
  788. ASSERT(!Group_IsValid(g0));
  789. }
  790. Test:y_groups_Iterator0()
  791. {
  792. new
  793. Group:g0 = Group_Create(),
  794. Group:g1 = Group_Create(),
  795. Group:g2 = Group_Create();
  796. new
  797. total = 0;
  798. foreach (new Group:g : CreatedGroup)
  799. {
  800. ++total;
  801. }
  802. ASSERT(total >= 3);
  803. total = 0;
  804. foreach (new Group:g : CreatedGroup())
  805. {
  806. ++total;
  807. }
  808. ASSERT(total >= 3);
  809. Group_Destroy(g0),
  810. Group_Destroy(g1),
  811. Group_Destroy(g2);
  812. }
  813. #undef _GROUP_MAKE_LIMIT
  814. #undef _GROUP_MAKE_NAME
  815. #tryinclude "..\YSI_Core\y_master"
  816. #tryinclude "..\..\YSI_Core\y_master"