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.

236 lines
5.5KB

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