from entities import * def memory_generateConstPlayfield( c: MemoryContext ) -> str: idGroups: dict[int, int] = { } id = 0 for gid in range(0, c.playfieldSize): idGroups[id] = gid id += 1 idGroups[id] = gid id += 1 #} c.playfieldItems = idGroups return "playfieldItems" #} def memory_selectItem( c: MemoryContext, id: int ) -> str: c.selectedItems.append(id) return "selectedItems" #} # Test. def test_memory_generateConstPlayfield( ) -> str: c = memory_createEmptyContext() c.playfieldSize = 2 fieldName = memory_generateConstPlayfield(c) if ( fieldName == "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_generateConstPlayfield" #} return "ERR: memory_generateConstPlayfield" #} def test_memory_selectItem( ) -> str: c = memory_createEmptyContext() c.playfieldSize = 2 memory_generateConstPlayfield(c) # Select the item with group 0. fieldName = memory_selectItem(c, 0) # See if it's in selectedItems now. if ( fieldName == "selectedItems" and len(c.selectedItems) == 1 and c.selectedItems[0] == 0 ): return "OK: memory_selectItem" #} return "ERR: memory_selectItem" #}