|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- from entities import *
-
- def memory_generateConstPlayfield(
- c: MemoryContext
- ) -> MemoryContext:
- 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
- c.recentField = "playfieldItems"
- return c
- #}
-
- # Select item
- #
- # Conditions:
- # 0. Remove obsolete selected items
- # 1. If selectedId is recent
- # 2. If it's not recent
- def memory_selectItem(
- c: MemoryContext
- ) -> MemoryContext:
- if (
- len(c.selectedItems) == 2
- ):
- c.selectedItems = []
-
- if (
- c.recentField == "selectedId"
- ):
- c.selectedItems.append(c.selectedId)
- c.recentField = "selectedItems"
- return c
-
- c.recentField = None
- return c
- #}
-
- # Test.
-
- def test_memory_generateConstPlayfield(
- ) -> str:
- c = memory_createEmptyContext()
- c.playfieldSize = 2
- c = memory_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_generateConstPlayfield"
- #}
- return "ERR: memory_generateConstPlayfield"
- #}
-
- def test_memory_selectOneItem(
- ) -> str:
- c = memory_createEmptyContext()
- c.playfieldSize = 2
- c = memory_generateConstPlayfield(c)
-
- # Select the first item.
- c.selectedId = 0
- c.recentField = "selectedId"
- c = memory_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_selectOneItem"
- #}
- return "ERR: memory_selectOneItem"
- #}
-
- def test_memory_selectTwoItems(
- ) -> str:
- c = memory_createEmptyContext()
- c.playfieldSize = 2
- c = memory_generateConstPlayfield(c)
-
- # Select the first two items.
- c.selectedId = 0
- c.recentField = "selectedId"
- c = memory_selectItem(c)
- c.selectedId = 1
- c.recentField = "selectedId"
- c = memory_selectItem(c)
-
- # See if it's 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_selectTwoItems"
- #}
- return "ERR: memory_selectTwoItems"
- #}
-
- def test_memory_selectThreeItems(
- ) -> str:
- c = memory_createEmptyContext()
- c.playfieldSize = 2
- c = memory_generateConstPlayfield(c)
-
- # Select three items.
- c.selectedId = 0
- c.recentField = "selectedId"
- c = memory_selectItem(c)
- c.selectedId = 1
- c.recentField = "selectedId"
- c = memory_selectItem(c)
- c.selectedId = 2
- c.recentField = "selectedId"
- c = memory_selectItem(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_selectThreeItems"
- #}
- return "ERR: memory_selectThreeItems"
- #}
|