from memory_api import * from memory_api_Context import * def memory_api_test_deselectMismatchedItems( ) -> str: c = memory_api_createContext() c.playfieldSize = 2 c = memory_api_generateConstPlayfield(c) # Select two items of different groups. c.selectedId = 0 c.recentField = "selectedId" c = memory_api_selectItem(c) c.selectedId = 2 c.recentField = "selectedId" c = memory_api_selectItem(c) # Detect mismatching. c = memory_api_deselectMismatchedItems(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_api_deselectMismatchedItems" #} return "ERR: memory_api_deselectMismatchedItems" #} def memory_api_test_detectVictory( ) -> str: c = memory_api_createContext() c.playfieldSize = 2 c = memory_api_generateConstPlayfield(c) # Select the first two items of the same group. c.selectedId = 0 c.recentField = "selectedId" c = memory_api_selectItem(c) c.selectedId = 1 c.recentField = "selectedId" c = memory_api_selectItem(c) # Hide the first pair. c = memory_api_hideMatchingItems(c) # Select the last two items of the same group. c.selectedId = 2 c.recentField = "selectedId" c = memory_api_selectItem(c) c.selectedId = 3 c.recentField = "selectedId" c = memory_api_selectItem(c) # Hide the second pair. c = memory_api_hideMatchingItems(c) # Detect victory. c = memory_api_detectVictory(c) # See if victory has been detected. if ( c.recentField == "victory" and c.victory == True ): return "OK: memory_api_detectVictory" #} return "ERR: memory_api_detectVictory" #} def memory_api_test_generateConstPlayfield( ) -> str: c = memory_api_createContext() c.playfieldSize = 2 c = memory_api_generateConstPlayfield(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_api_generateConstPlayfield" #} return "ERR: memory_api_generateConstPlayfield" #} def memory_api_test_hideMatchingItems( ) -> str: c = memory_api_createContext() c.playfieldSize = 2 c = memory_api_generateConstPlayfield(c) # Select two items of the same group. c.selectedId = 0 c.recentField = "selectedId" c = memory_api_selectItem(c) c.selectedId = 1 c.recentField = "selectedId" c = memory_api_selectItem(c) # Hide matching items. c = memory_api_hideMatchingItems(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_api_hideMatchingItems" #} return "ERR: memory_api_hideMatchingItems" #} def memory_api_test_selectItem( ) -> str: c = memory_api_createContext() c.playfieldSize = 2 c = memory_api_generateConstPlayfield(c) # Select the first item. c.selectedId = 0 c.recentField = "selectedId" c = memory_api_selectItem(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_api_selectItem" #} return "ERR: memory_api_selectItem" #}