Research portable Memory game | Исследовать портируемую игру Память
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

memory_test.cpp 5.6KB

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