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.

memory_test.py 5.3KB

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