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.

213 lines
4.9KB

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