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

211 行
5.0KB

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