Research portable Memory game | Исследовать портируемую игру Память
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

182 linhas
4.0KB

  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_shouldDetectVictory(
  105. ) -> str:
  106. c = memory_createContext()
  107. c.playfieldSize = 2
  108. c = memory_generateConstPlayfield(c)
  109. # Select the first two items of the same group.
  110. c.selectedId = 0
  111. c = memory_selectItem(c)
  112. c.selectedId = 1
  113. c = memory_selectItem(c)
  114. # Hide the first pair.
  115. c = memory_shouldHideMatchingItems(c)
  116. # Select the last two items of the same group.
  117. c.selectedId = 2
  118. c = memory_selectItem(c)
  119. c.selectedId = 3
  120. c = memory_selectItem(c)
  121. # Hide the second pair.
  122. c = memory_shouldHideMatchingItems(c)
  123. # Detect victory.
  124. c = memory_shouldDetectVictory(c)
  125. # See if victory has been detected.
  126. if (
  127. c.recentField == "victory" and
  128. c.victory == True
  129. ):
  130. return "OK: memory_shouldDetectVictory"
  131. #}
  132. return "ERR: memory_shouldDetectVictory"
  133. #}
  134. def memory_test_shouldHideMatchingItems(
  135. ) -> str:
  136. c = memory_createContext()
  137. c.playfieldSize = 2
  138. c = memory_generateConstPlayfield(c)
  139. # Select two items of the same group.
  140. c.selectedId = 0
  141. c = memory_selectItem(c)
  142. c.selectedId = 1
  143. c = memory_selectItem(c)
  144. # Hide matching items.
  145. c = memory_shouldHideMatchingItems(c)
  146. # See if the two selected items match.
  147. if (
  148. c.recentField == "hiddenItems" and
  149. len(c.hiddenItems) == 2 and
  150. c.hiddenItems[0] == 0 and
  151. c.hiddenItems[1] == 1
  152. ):
  153. return "OK: memory_shouldHideMatchingItems"
  154. #}
  155. return "ERR: memory_shouldHideMatchingItems"
  156. #}