Research portable Memory game | Исследовать портируемую игру Память
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

237 lines
5.5KB

  1. #include <map>
  2. #include <string>
  3. #include <vector>
  4. #include "llm.h"
  5. #include "memory_Context.h"
  6. #include "main.h"
  7. std::string memory_test_detectMismatchedItems(
  8. ) {
  9. auto c = memory_createContext();
  10. c.playfieldSize = 2;
  11. c.recentField = "playfieldSize";
  12. c = memory_generateConstPlayfield(c);
  13. // Select two items of different groups.
  14. c.selectedId = 0;
  15. c.recentField = "selectedId";
  16. c = memory_selectItem(c);
  17. c.selectedId = 2;
  18. c.recentField = "selectedId";
  19. c = memory_selectItem(c);
  20. // Detect mismatching.
  21. c = memory_detectMismatchedItems(c);
  22. // See if the two selected items do not match.
  23. if (
  24. c.recentField == "mismatchedItems" &&
  25. c.mismatchedItems.size() == 2 &&
  26. c.mismatchedItems[0] == 0 &&
  27. c.mismatchedItems[1] == 2
  28. ) {
  29. return "OK: memory_detectMismatchedItems";
  30. }
  31. return "ERR: memory_detectMismatchedItems";
  32. }
  33. std::string memory_test_detectMismatchedItems_itemTwice(
  34. ) {
  35. auto c = memory_createContext();
  36. c.playfieldSize = 2;
  37. c.recentField = "playfieldSize";
  38. c = memory_generateConstPlayfield(c);
  39. // Select the same item twice.
  40. c.selectedId = 0;
  41. c.recentField = "selectedId";
  42. c = memory_selectItem(c);
  43. c.selectedId = 0;
  44. c.recentField = "selectedId";
  45. c = memory_selectItem(c);
  46. // Detect mismatching.
  47. c = memory_detectMismatchedItems(c);
  48. // See if the two selected items do not match.
  49. if (
  50. c.recentField == "mismatchedItems" &&
  51. c.mismatchedItems.size() == 1 &&
  52. c.mismatchedItems[0] == 0
  53. ) {
  54. return "OK: memory_detectMismatchedItems_itemTwice";
  55. }
  56. return "ERR: memory_detectMismatchedItems_itemTwice";
  57. }
  58. std::string memory_test_detectVictory(
  59. ) {
  60. auto c = memory_createContext();
  61. c.playfieldSize = 2;
  62. c.recentField = "playfieldSize";
  63. c = memory_generateConstPlayfield(c);
  64. // Select the first two items of the same group.
  65. c.selectedId = 0;
  66. c.recentField = "selectedId";
  67. c = memory_selectItem(c);
  68. c.selectedId = 1;
  69. c.recentField = "selectedId";
  70. c = memory_selectItem(c);
  71. // Hide the first pair.
  72. c = memory_hideMatchingItems(c);
  73. // Select the last two items of the same group.
  74. c.selectedId = 2;
  75. c.recentField = "selectedId";
  76. c = memory_selectItem(c);
  77. c.selectedId = 3;
  78. c.recentField = "selectedId";
  79. c = memory_selectItem(c);
  80. // Hide the second pair.
  81. c = memory_hideMatchingItems(c);
  82. // Detect victory.
  83. c = memory_detectVictory(c);
  84. // See if victory has been detected.
  85. if (
  86. c.recentField == "victory" &&
  87. c.victory == true
  88. ) {
  89. return "OK: memory_detectVictory";
  90. }
  91. return "ERR: memory_detectVictory";
  92. }
  93. std::string memory_test_generateConstPlayfield(
  94. ) {
  95. auto c = memory_createContext();
  96. c.playfieldSize = 2;
  97. c.recentField = "playfieldSize";
  98. c = memory_generateConstPlayfield(c);
  99. if (
  100. c.recentField == "playfieldItems" &&
  101. c.playfieldItems.size() == 4 &&
  102. c.playfieldItems[0] == 0 &&
  103. c.playfieldItems[1] == 0 &&
  104. c.playfieldItems[2] == 1 &&
  105. c.playfieldItems[3] == 1
  106. ) {
  107. return "OK: memory_generateConstPlayfield";
  108. }
  109. return "ERR: memory_generateConstPlayfield";
  110. }
  111. std::string memory_test_hideMatchingItems(
  112. ) {
  113. auto c = memory_createContext();
  114. c.playfieldSize = 2;
  115. c.recentField = "playfieldSize";
  116. c = memory_generateConstPlayfield(c);
  117. // Select two items of the same group.
  118. c.selectedId = 0;
  119. c.recentField = "selectedId";
  120. c = memory_selectItem(c);
  121. c.selectedId = 1;
  122. c.recentField = "selectedId";
  123. c = memory_selectItem(c);
  124. // Hide matching items.
  125. c = memory_hideMatchingItems(c);
  126. // See if the two selected items match.
  127. if (
  128. c.recentField == "hiddenItems" &&
  129. c.hiddenItems.size() == 2 &&
  130. c.hiddenItems[0] == 0 &&
  131. c.hiddenItems[1] == 1
  132. ) {
  133. return "OK: memory_hideMatchingItems";
  134. }
  135. return "ERR: memory_hideMatchingItems";
  136. }
  137. std::string memory_test_selectItem_1x(
  138. ) {
  139. auto c = memory_createContext();
  140. c.playfieldSize = 2;
  141. c.recentField = "playfieldSize";
  142. c = memory_generateConstPlayfield(c);
  143. // Select the first item.
  144. c.selectedId = 0;
  145. c.recentField = "selectedId";
  146. c = memory_selectItem(c);
  147. // See if it's in selectedItems now.
  148. if (
  149. c.recentField == "selectedItems" &&
  150. c.selectedItems.size() == 1 &&
  151. c.selectedItems[0] == 0
  152. ) {
  153. return "OK: memory_selectItem_1x";
  154. }
  155. return "ERR: memory_selectItem_1x";
  156. }
  157. std::string memory_test_selectItem_2x(
  158. ) {
  159. auto c = memory_createContext();
  160. c.playfieldSize = 2;
  161. c.recentField = "playfieldSize";
  162. c = memory_generateConstPlayfield(c);
  163. // Select the first two items.
  164. c.selectedId = 0;
  165. c.recentField = "selectedId";
  166. c = memory_selectItem(c);
  167. c.selectedId = 1;
  168. c.recentField = "selectedId";
  169. c = memory_selectItem(c);
  170. // See if both items are selected now.
  171. if (
  172. c.recentField == "selectedItems" &&
  173. c.selectedItems.size() == 2 &&
  174. c.selectedItems[0] == 0 &&
  175. c.selectedItems[1] == 1
  176. ) {
  177. return "OK: memory_selectItem_2x";
  178. }
  179. return "ERR: memory_selectItem_2x";
  180. }
  181. std::string memory_test_selectItem_3x(
  182. ) {
  183. auto c = memory_createContext();
  184. c.playfieldSize = 2;
  185. c.recentField = "playfieldSize";
  186. c = memory_generateConstPlayfield(c);
  187. // Select three items.
  188. c.selectedId = 0;
  189. c.recentField = "selectedId";
  190. c = memory_selectItem(c);
  191. c.selectedId = 1;
  192. c.recentField = "selectedId";
  193. c = memory_selectItem(c);
  194. c.selectedId = 2;
  195. c.recentField = "selectedId";
  196. c = memory_selectItem(c);
  197. // See if only one (last) item is selected now.
  198. if (
  199. c.recentField == "selectedItems" &&
  200. c.selectedItems.size() == 1 &&
  201. c.selectedItems[0] == 2
  202. ) {
  203. return "OK: memory_selectItem_3x";
  204. }
  205. return "ERR: memory_selectItem_3x";
  206. }