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.

212 lines
4.9KB

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