2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

288 linhas
6.5 KiB

  1. #include "../../test/IZ_test.h"
  2. #include "../../common/IZ_common.h"
  3. #include "../../../__mocks__/SDL_stdinc.mock.h"
  4. #include "IZ_list.h"
  5. bool NodeExists(IZ_ListNode** node, u64 _index, IZ_List* list) {
  6. return *((u64*) (*node)->value) == 42069;
  7. }
  8. bool NodeExists2(IZ_ListNode** node, u64 _index, IZ_List* list) {
  9. return *((u64*) (*node)->value) == 69420;
  10. }
  11. bool NodeDoesNotExist(IZ_ListNode** node, u64 _index, IZ_List* list) {
  12. return *((u64*) (*node)->value) == 55555;
  13. }
  14. spec("data") {
  15. describe("list") {
  16. describe("Initialize") {
  17. static IZ_List list;
  18. after_each() {
  19. IZ_ListTeardown(&list);
  20. }
  21. it("sets root to NULL") {
  22. IZ_ListInitialize(&list);
  23. check(list.root == NULL, "List not properly initialized.");
  24. }
  25. }
  26. describe("Teardown") {
  27. static IZ_List list;
  28. before_each() {
  29. static u64 value1 = 69420u;
  30. static u64 value2 = 42069u;
  31. static u64 value3 = 69069u;
  32. IZ_ListInitialize(&list);
  33. IZ_ListAppendNode(&list, &value1);
  34. IZ_ListAppendNode(&list, &value2);
  35. IZ_ListAppendNode(&list, &value3);
  36. }
  37. after_each() {
  38. mock_reset(SDL_free);
  39. }
  40. it("removes all nodes from the list") {
  41. mock_set_expected_calls(SDL_free, 3);
  42. IZ_ListTeardown(&list);
  43. check(
  44. mock_get_expected_calls(SDL_free) == mock_get_actual_calls(SDL_free),
  45. "Deallocator function call count mismatch."
  46. );
  47. }
  48. }
  49. describe("AppendNode") {
  50. static IZ_List list;
  51. static IZ_List list2;
  52. before_each() {
  53. IZ_ListInitialize(&list);
  54. }
  55. before_each() {
  56. IZ_ListInitialize(&list2);
  57. static u64 existing_value = 69420u;
  58. static IZ_ListNode existing_node = {
  59. .value = &existing_value,
  60. .next = NULL,
  61. };
  62. list2.root = &existing_node;
  63. list2.length = 1;
  64. }
  65. after_each() {
  66. mock_reset(SDL_malloc);
  67. }
  68. after_each() {
  69. IZ_ListTeardown(&list);
  70. }
  71. after_each() {
  72. IZ_ListTeardown(&list2);
  73. }
  74. it("appends new node to empty list and sets it as root") {
  75. static u64 value = 69420u;
  76. IZ_ListAppendNode(&list, &value);
  77. check(*((u64*) list.root->value) == 69420u, "Node not properly appended.");
  78. check(
  79. mock_is_called(SDL_malloc),
  80. "Allocator function not called."
  81. );
  82. check(list.length == 1, "Length mismatch.");
  83. }
  84. it("appends new node to non-empty list") {
  85. static u64 value1 = 42069u;
  86. IZ_ListAppendNode(&list2, &value1);
  87. check(*((u64*) list2.root->next->value) == 42069u, "Node not properly appended.");
  88. check(
  89. mock_is_called(SDL_malloc),
  90. "Allocator function not called."
  91. );
  92. check(list2.length == 2, "Length mismatch.");
  93. }
  94. }
  95. describe("InsertNodeAtIndex") {
  96. static IZ_List list;
  97. static IZ_List list2;
  98. before_each() {
  99. IZ_ListInitialize(&list);
  100. }
  101. before_each() {
  102. IZ_ListInitialize(&list2);
  103. static u64 existing_value = 69420u;
  104. static IZ_ListNode existing_node = {
  105. .value = &existing_value,
  106. .next = NULL,
  107. };
  108. list2.root = &existing_node;
  109. list2.length = 1;
  110. }
  111. after_each() {
  112. mock_reset(SDL_malloc);
  113. }
  114. after_each() {
  115. IZ_ListTeardown(&list);
  116. }
  117. after_each() {
  118. IZ_ListTeardown(&list2);
  119. }
  120. it("inserts new node to empty list and sets it as root") {
  121. static u64 value = 69420u;
  122. IZ_ListInsertNodeAtIndex(&list, &value, 0);
  123. check(*((u64*) list.root->value) == 69420u, "Node not properly appended.");
  124. check(
  125. mock_is_called(SDL_malloc),
  126. "Allocator function not called."
  127. );
  128. check(list.length == 1, "Length mismatch.");
  129. }
  130. it("inserts new node to non-empty list") {
  131. static u64 value1 = 42069u;
  132. IZ_ListInsertNodeAtIndex(&list2, &value1, 0);
  133. check(*((u64*) list2.root->value) == 42069u, "Node not properly appended.");
  134. check(
  135. mock_is_called(SDL_malloc),
  136. "Allocator function not called."
  137. );
  138. check(list2.length == 2, "Length mismatch.");
  139. }
  140. }
  141. describe("DeleteFirstNode") {
  142. static IZ_List list;
  143. before_each() {
  144. static u64 value1 = 69420u;
  145. static u64 value2 = 42069u;
  146. static u64 value3 = 69069u;
  147. IZ_ListInitialize(&list);
  148. IZ_ListAppendNode(&list, &value1);
  149. IZ_ListAppendNode(&list, &value2);
  150. IZ_ListAppendNode(&list, &value3);
  151. }
  152. after_each() {
  153. mock_reset(SDL_free);
  154. }
  155. it("removes first node satisfying the filter condition") {
  156. IZ_ListDeleteFirstNode(&list, NodeExists);
  157. check(
  158. mock_is_called(SDL_free),
  159. "Deallocator function not called."
  160. );
  161. check(
  162. IZ_ListFindFirstNode(&list, NodeExists2),
  163. "Node supposed to be present in list is absent."
  164. );
  165. check(
  166. !IZ_ListFindFirstNode(&list, NodeExists),
  167. "Deleted node still present in list."
  168. );
  169. check(list.length == 2, "Length mismatch.");
  170. }
  171. }
  172. describe("FindFirstNode") {
  173. static IZ_List list;
  174. static u64 value1 = 69420u;
  175. static u64 value2 = 42069u;
  176. before_each() {
  177. IZ_ListInitialize(&list);
  178. IZ_ListAppendNode(&list, &value1);
  179. IZ_ListAppendNode(&list, &value2);
  180. }
  181. after_each() {
  182. IZ_ListTeardown(&list);
  183. }
  184. it("retrieves first node satisfying the filter condition") {
  185. static IZ_ListNode** node;
  186. node = IZ_ListFindFirstNode(&list, NodeExists);
  187. check(*((u64*) (*node)->value) == 42069u, "Existing node not found.");
  188. }
  189. it("returns NULL when all nodes do not satisfy the filter condition") {
  190. static IZ_ListNode** node;
  191. node = IZ_ListFindFirstNode(&list, NodeDoesNotExist);
  192. check(node == NULL, "Non-existing node found.");
  193. }
  194. }
  195. describe("Filter") {
  196. static IZ_List original_list;
  197. static IZ_List filtered_list;
  198. before_each() {
  199. IZ_ListInitialize(&original_list);
  200. IZ_ListInitialize(&filtered_list);
  201. static u64 value1 = 69420u;
  202. static u64 value2 = 42069u;
  203. static u64 value3 = 69069u;
  204. IZ_ListAppendNode(&original_list, &value1);
  205. IZ_ListAppendNode(&original_list, &value2);
  206. IZ_ListAppendNode(&original_list, &value3);
  207. }
  208. it("ensures nodes that satisfy find predicate are present") {
  209. IZ_ListFilter(&original_list, NodeExists, &filtered_list);
  210. check(
  211. IZ_ListFindFirstNode(&filtered_list, NodeExists),
  212. "Node supposed to be present in list is absent."
  213. );
  214. check(filtered_list.length == 1, "Length mismatch.");
  215. }
  216. it("ensures nodes that do not satisfy find predicate are absent") {
  217. IZ_ListFilter(&original_list, NodeDoesNotExist, &filtered_list);
  218. check(
  219. IZ_ListFindFirstNode(&filtered_list, NodeDoesNotExist),
  220. "Node supposed to be absent in list is present."
  221. );
  222. check(filtered_list.length == 0, "Length mismatch.");
  223. }
  224. }
  225. describe("Sort") {
  226. }
  227. }
  228. }