Research portable Memory game | Исследовать портируемую игру Память
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

210 строки
5.0KB

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