Research portable Memory game | Исследовать портируемую игру Память
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

memory_test.py 4.7KB

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