|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- from memory import *
- from memory_Context import *
-
- def memory_test_shouldDeselectMismatchedItems(
- ) -> str:
- c = memory_createContext()
- c.playfieldSize = 2
- c.recentField = "playfieldSize"
- c = memory_shouldGenerateConstPlayfield(c)
-
- # Select two items of different groups.
- c.selectedId = 0
- c.recentField = "selectedId"
- c = memory_shouldSelectItem(c)
- c.selectedId = 2
- c.recentField = "selectedId"
- c = memory_shouldSelectItem(c)
-
- # Detect mismatching.
- c = memory_shouldDeselectMismatchedItems(c)
-
- # See if the two selected items do not match.
- if (
- c.recentField == "mismatchedItems" and
- len(c.mismatchedItems) == 2 and
- c.mismatchedItems[0] == 0 and
- c.mismatchedItems[1] == 2
- ):
- return "OK: memory_shouldDeselectMismatchedItems"
- #}
- return "ERR: memory_shouldDeselectMismatchedItems"
- #}
-
- def memory_test_shouldDeselectMismatchedItems_itemTwice(
- ) -> str:
- c = memory_createContext()
- c.playfieldSize = 2
- c.recentField = "playfieldSize"
- c = memory_shouldGenerateConstPlayfield(c)
-
- # Select the same item twice.
- c.selectedId = 0
- c.recentField = "selectedId"
- c = memory_shouldSelectItem(c)
- c.selectedId = 0
- c.recentField = "selectedId"
- c = memory_shouldSelectItem(c)
-
- # Detect mismatching.
- c = memory_shouldDeselectMismatchedItems(c)
-
- # See if the two selected items do not match.
- if (
- c.recentField == "mismatchedItems" and
- len(c.mismatchedItems) == 1 and
- c.mismatchedItems[0] == 0
- ):
- return "OK: memory_shouldDeselectMismatchedItems_itemTwice"
- #}
- return "ERR: memory_shouldDeselectMismatchedItems_itemTwice"
- #}
-
- def memory_test_shouldDetectVictory(
- ) -> str:
- c = memory_createContext()
- c.playfieldSize = 2
- c.recentField = "playfieldSize"
- c = memory_shouldGenerateConstPlayfield(c)
-
- # Select the first two items of the same group.
- c.selectedId = 0
- c.recentField = "selectedId"
- c = memory_shouldSelectItem(c)
- c.selectedId = 1
- c.recentField = "selectedId"
- c = memory_shouldSelectItem(c)
-
- # Hide the first pair.
- c = memory_shouldHideMatchingItems(c)
-
- # Select the last two items of the same group.
- c.selectedId = 2
- c.recentField = "selectedId"
- c = memory_shouldSelectItem(c)
- c.selectedId = 3
- c.recentField = "selectedId"
- c = memory_shouldSelectItem(c)
-
- # Hide the second pair.
- c = memory_shouldHideMatchingItems(c)
-
- # Detect victory.
- c = memory_shouldDetectVictory(c)
-
- # See if victory has been detected.
- if (
- c.recentField == "victory" and
- c.victory == True
- ):
- return "OK: memory_shouldDetectVictory"
- #}
- return "ERR: memory_shouldDetectVictory"
- #}
-
- def memory_test_shouldGenerateConstPlayfield(
- ) -> str:
- c = memory_createContext()
- c.playfieldSize = 2
- c.recentField = "playfieldSize"
- c = memory_shouldGenerateConstPlayfield(c)
- if (
- c.recentField == "playfieldItems" and
- len(c.playfieldItems) == 4 and
- c.playfieldItems[0] == 0 and
- c.playfieldItems[1] == 0 and
- c.playfieldItems[2] == 1 and
- c.playfieldItems[3] == 1
- ):
- return "OK: memory_shouldGenerateConstPlayfield"
- #}
- return "ERR: memory_shouldGenerateConstPlayfield"
- #}
-
- def memory_test_shouldHideMatchingItems(
- ) -> str:
- c = memory_createContext()
- c.playfieldSize = 2
- c.recentField = "playfieldSize"
- c = memory_shouldGenerateConstPlayfield(c)
-
- # Select two items of the same group.
- c.selectedId = 0
- c.recentField = "selectedId"
- c = memory_shouldSelectItem(c)
- c.selectedId = 1
- c.recentField = "selectedId"
- c = memory_shouldSelectItem(c)
-
- # Hide matching items.
- c = memory_shouldHideMatchingItems(c)
-
- # See if the two selected items match.
- if (
- c.recentField == "hiddenItems" and
- len(c.hiddenItems) == 2 and
- c.hiddenItems[0] == 0 and
- c.hiddenItems[1] == 1
- ):
- return "OK: memory_shouldHideMatchingItems"
- #}
- return "ERR: memory_shouldHideMatchingItems"
- #}
-
- def memory_test_shouldSelectItem_1x(
- ) -> str:
- c = memory_createContext()
- c.playfieldSize = 2
- c.recentField = "playfieldSize"
- c = memory_shouldGenerateConstPlayfield(c)
-
- # Select the first item.
- c.selectedId = 0
- c.recentField = "selectedId"
- c = memory_shouldSelectItem(c)
-
- # See if it's in selectedItems now.
- if (
- c.recentField == "selectedItems" and
- len(c.selectedItems) == 1 and
- c.selectedItems[0] == 0
- ):
- return "OK: memory_shouldSelectItem_1x"
- #}
- return "ERR: memory_shouldSelectItem_1x"
- #}
-
- def memory_test_shouldSelectItem_2x(
- ) -> str:
- c = memory_createContext()
- c.playfieldSize = 2
- c.recentField = "playfieldSize"
- c = memory_shouldGenerateConstPlayfield(c)
-
- # Select the first two items.
- c.selectedId = 0
- c.recentField = "selectedId"
- c = memory_shouldSelectItem(c)
- c.selectedId = 1
- c.recentField = "selectedId"
- c = memory_shouldSelectItem(c)
-
- # See if both items are selected now.
- if (
- c.recentField == "selectedItems" and
- len(c.selectedItems) == 2 and
- c.selectedItems[0] == 0 and
- c.selectedItems[1] == 1
- ):
- return "OK: memory_shouldSelectItem_2x"
- #}
- return "ERR: memory_shouldSelectItem_2x"
- #}
-
- def memory_test_shouldSelectItem_3x(
- ) -> str:
- c = memory_createContext()
- c.playfieldSize = 2
- c.recentField = "playfieldSize"
- c = memory_shouldGenerateConstPlayfield(c)
-
- # Select three items.
- c.selectedId = 0
- c.recentField = "selectedId"
- c = memory_shouldSelectItem(c)
- c.selectedId = 1
- c.recentField = "selectedId"
- c = memory_shouldSelectItem(c)
- c.selectedId = 2
- c.recentField = "selectedId"
- c = memory_shouldSelectItem(c)
-
- # See if only one (last) item is selected now.
- if (
- c.recentField == "selectedItems" and
- len(c.selectedItems) == 1 and
- c.selectedItems[0] == 2
- ):
- return "OK: memory_shouldSelectItem_3x"
- #}
- return "ERR: memory_shouldSelectItem_3x"
- #}
|