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.

310 lines
6.4KB

  1. #include <map>
  2. #include <string>
  3. #include <vector>
  4. #include "cli.h"
  5. #include "cli_Context.h"
  6. #include "memory.h"
  7. #include "memory_Context.h"
  8. #include "shell.h"
  9. std::string cli_test_exit_e(
  10. ) {
  11. auto c = memory_createContext();
  12. c.input = "e";
  13. c.recentField = "input";
  14. c = cli_exit(c);
  15. if (
  16. c.recentField == "exit"
  17. ) {
  18. return "OK: cli_exit_e";
  19. }
  20. return "ERR: cli_exit_e";
  21. }
  22. std::string cli_test_exit_exit(
  23. ) {
  24. auto c = memory_createContext();
  25. c.input = "exit";
  26. c.recentField = "input";
  27. c = cli_exit(c);
  28. if (
  29. c.recentField == "exit"
  30. ) {
  31. return "OK: cli_exit_exit";
  32. }
  33. return "ERR: cli_exit_e";
  34. }
  35. std::string cli_test_exit_victory(
  36. ) {
  37. auto c = memory_createContext();
  38. c.playfieldSize = 2;
  39. c.recentField = "playfieldSize";
  40. c = memory_generateConstPlayfield(c);
  41. // Match the first pair of tiles.
  42. c.input = "1";
  43. c.recentField = "input";
  44. c = cli_selectItem(c);
  45. c = memory_selectItem(c);
  46. c.input = "2";
  47. c.recentField = "input";
  48. c = cli_selectItem(c);
  49. c = memory_selectItem(c);
  50. c = memory_hideMatchingItems(c);
  51. // Match the second pair of tiles.
  52. c.input = "3";
  53. c.recentField = "input";
  54. c = cli_selectItem(c);
  55. c = memory_selectItem(c);
  56. c.input = "4";
  57. c.recentField = "input";
  58. c = cli_selectItem(c);
  59. c = memory_selectItem(c);
  60. c = memory_hideMatchingItems(c);
  61. c = memory_detectVictory(c);
  62. c = cli_reportVictory(c);
  63. c = cli_exit(c);
  64. if (
  65. c.recentField == "exit"
  66. ) {
  67. return "OK: cli_exit_victory";
  68. }
  69. return "ERR: cli_exit_victory";
  70. }
  71. std::string cli_test_exit_q(
  72. ) {
  73. auto c = memory_createContext();
  74. c.input = "q";
  75. c.recentField = "input";
  76. c = cli_exit(c);
  77. if (
  78. c.recentField == "exit"
  79. ) {
  80. return "OK: cli_exit_q";
  81. }
  82. return "ERR: cli_exit_q";
  83. }
  84. std::string cli_test_exit_quit(
  85. ) {
  86. auto c = memory_createContext();
  87. c.input = "quit";
  88. c.recentField = "input";
  89. c = cli_exit(c);
  90. if (
  91. c.recentField == "exit"
  92. ) {
  93. return "OK: cli_exit_quit";
  94. }
  95. return "ERR: cli_exit_quit";
  96. }
  97. std::string cli_test_goOn(
  98. ) {
  99. auto c = memory_createContext();
  100. c.playfieldSize = 2;
  101. c.recentField = "playfieldSize";
  102. c = memory_generateConstPlayfield(c);
  103. // Match the first pair of items.
  104. c.input = "1";
  105. c.recentField = "input";
  106. c = cli_selectItem(c);
  107. c = memory_selectItem(c);
  108. c.input = "2";
  109. c.recentField = "input";
  110. c = cli_selectItem(c);
  111. c = memory_selectItem(c);
  112. c = memory_hideMatchingItems(c);
  113. c = cli_reportMatchedItems(c);
  114. c = cli_goOn(c);
  115. if (
  116. c.recentField == "outputGoOn"
  117. ) {
  118. return "OK: cli_goOn";
  119. }
  120. return "ERR: cli_goOn";
  121. }
  122. std::string cli_test_greetUser(
  123. ) {
  124. auto c = memory_createContext();
  125. c.didLaunch = true;
  126. c.recentField = "didLaunch";
  127. c = cli_greetUser(c);
  128. if (
  129. c.recentField == "outputGreeting"
  130. ) {
  131. return "OK: cli_greetUser";
  132. }
  133. return "ERR: cli_greetUser";
  134. }
  135. std::string cli_test_promptSecondItemSelection(
  136. ) {
  137. auto c = memory_createContext();
  138. c.input = "1";
  139. c.recentField = "input";
  140. c = cli_selectItem(c);
  141. c = memory_selectItem(c);
  142. c = cli_promptSecondItemSelection(c);
  143. if (
  144. c.recentField == "outputPromptSelection"
  145. ) {
  146. return "OK: cli_promptSecondItemSelection";
  147. }
  148. return "ERR: cli_promptSecondItemSelection";
  149. }
  150. std::string cli_test_reportMatchedItems(
  151. ) {
  152. auto c = memory_createContext();
  153. c.playfieldSize = 2;
  154. c.recentField = "playfieldSize";
  155. c = memory_generateConstPlayfield(c);
  156. c.input = "1";
  157. c.recentField = "input";
  158. c = cli_selectItem(c);
  159. c = memory_selectItem(c);
  160. c.input = "2";
  161. c.recentField = "input";
  162. c = cli_selectItem(c);
  163. c = memory_selectItem(c);
  164. c = memory_hideMatchingItems(c);
  165. c = cli_reportMatchedItems(c);
  166. if (
  167. c.recentField == "outputMatchedItems"
  168. ) {
  169. return "OK: cli_reportMatchedItems";
  170. }
  171. return "ERR: cli_reportMatchedItems";
  172. }
  173. std::string cli_test_reportMismatchedItems(
  174. ) {
  175. auto c = memory_createContext();
  176. c.playfieldSize = 2;
  177. c.recentField = "playfieldSize";
  178. c = memory_generateConstPlayfield(c);
  179. c.input = "1";
  180. c.recentField = "input";
  181. c = cli_selectItem(c);
  182. c = memory_selectItem(c);
  183. c.input = "3";
  184. c.recentField = "input";
  185. c = cli_selectItem(c);
  186. c = memory_selectItem(c);
  187. c = memory_detectMismatchedItems(c);
  188. c = cli_reportMismatchedItems(c);
  189. if (
  190. c.recentField == "outputMismatchedItems"
  191. ) {
  192. return "OK: cli_reportMismatchedItems";
  193. }
  194. return "ERR: cli_reportMismatchedItems";
  195. }
  196. std::string cli_test_selectItem(
  197. ) {
  198. auto c = memory_createContext();
  199. c.input = "1";
  200. c.recentField = "input";
  201. c = cli_selectItem(c);
  202. if (
  203. c.recentField == "selectedId" &&
  204. c.selectedId == 0
  205. ) {
  206. return "OK: cli_selectItem";
  207. }
  208. return "ERR: cli_selectItem";
  209. }
  210. std::string cli_test_showHelp_h(
  211. ) {
  212. auto c = memory_createContext();
  213. c.input = "h";
  214. c.recentField = "input";
  215. c = cli_showHelp(c);
  216. if (
  217. c.recentField == "outputHelp"
  218. ) {
  219. return "OK: cli_showHelp_h";
  220. }
  221. return "ERR: cli_showHelp_h";
  222. }
  223. std::string cli_test_showHelp_help(
  224. ) {
  225. auto c = memory_createContext();
  226. c.input = "help";
  227. c.recentField = "input";
  228. c = cli_showHelp(c);
  229. if (
  230. c.recentField == "outputHelp"
  231. ) {
  232. return "OK: cli_showHelp_help";
  233. }
  234. return "ERR: cli_showHelp_help";
  235. }
  236. std::string cli_test_reportVictory(
  237. ) {
  238. auto c = memory_createContext();
  239. c.playfieldSize = 2;
  240. c.recentField = "playfieldSize";
  241. c = memory_generateConstPlayfield(c);
  242. // Match the first pair of tiles.
  243. c.input = "1";
  244. c.recentField = "input";
  245. c = cli_selectItem(c);
  246. c = memory_selectItem(c);
  247. c.input = "2";
  248. c.recentField = "input";
  249. c = cli_selectItem(c);
  250. c = memory_selectItem(c);
  251. c = memory_hideMatchingItems(c);
  252. // Match the second pair of tiles.
  253. c.input = "3";
  254. c.recentField = "input";
  255. c = cli_selectItem(c);
  256. c = memory_selectItem(c);
  257. c.input = "4";
  258. c.recentField = "input";
  259. c = cli_selectItem(c);
  260. c = memory_selectItem(c);
  261. c = memory_hideMatchingItems(c);
  262. c = memory_detectVictory(c);
  263. c = cli_reportVictory(c);
  264. if (
  265. c.recentField == "outputVictory"
  266. ) {
  267. return "OK: cli_reportVictory";
  268. }
  269. return "ERR: cli_reportVictory";
  270. }
  271. //def cli_test_shouldReportIvalidItemSelection_outOfBoundsMin(
  272. //) -> str:
  273. // c = cli_createContext()
  274. // c.cMemory = memory_createContext()
  275. // c.input = "0"
  276. // c = cli_selectItem(c)
  277. // c = cli_shouldReportInvalidItemSelection(c)
  278. // if (
  279. // c.recentField == "outputInvalidItemSelection"
  280. // ):
  281. // return "OK: cli_shouldReportInvalidItemSelection"
  282. // //}
  283. // return "ERR: cli_shouldReportInvalidItemSelection"
  284. ////}
  285. //