|
@@ -2,7 +2,7 @@ from entities import * |
|
|
|
|
|
|
|
|
def memory_generateConstPlayfield( |
|
|
def memory_generateConstPlayfield( |
|
|
c: MemoryContext |
|
|
c: MemoryContext |
|
|
) -> str: |
|
|
|
|
|
|
|
|
) -> MemoryContext: |
|
|
idGroups: dict[int, int] = { } |
|
|
idGroups: dict[int, int] = { } |
|
|
id = 0 |
|
|
id = 0 |
|
|
for gid in range(0, c.playfieldSize): |
|
|
for gid in range(0, c.playfieldSize): |
|
@@ -12,15 +12,33 @@ def memory_generateConstPlayfield( |
|
|
id += 1 |
|
|
id += 1 |
|
|
#} |
|
|
#} |
|
|
c.playfieldItems = idGroups |
|
|
c.playfieldItems = idGroups |
|
|
return "playfieldItems" |
|
|
|
|
|
|
|
|
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( |
|
|
def memory_selectItem( |
|
|
c: MemoryContext, |
|
|
|
|
|
id: int |
|
|
|
|
|
) -> str: |
|
|
|
|
|
c.selectedItems.append(id) |
|
|
|
|
|
return "selectedItems" |
|
|
|
|
|
|
|
|
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. |
|
|
# Test. |
|
@@ -29,9 +47,9 @@ def test_memory_generateConstPlayfield( |
|
|
) -> str: |
|
|
) -> str: |
|
|
c = memory_createEmptyContext() |
|
|
c = memory_createEmptyContext() |
|
|
c.playfieldSize = 2 |
|
|
c.playfieldSize = 2 |
|
|
fieldName = memory_generateConstPlayfield(c) |
|
|
|
|
|
|
|
|
c = memory_generateConstPlayfield(c) |
|
|
if ( |
|
|
if ( |
|
|
fieldName == "playfieldItems" and |
|
|
|
|
|
|
|
|
c.recentField == "playfieldItems" and |
|
|
len(c.playfieldItems) == 4 and |
|
|
len(c.playfieldItems) == 4 and |
|
|
c.playfieldItems[0] == 0 and |
|
|
c.playfieldItems[0] == 0 and |
|
|
c.playfieldItems[1] == 0 and |
|
|
c.playfieldItems[1] == 0 and |
|
@@ -43,21 +61,78 @@ def test_memory_generateConstPlayfield( |
|
|
return "ERR: memory_generateConstPlayfield" |
|
|
return "ERR: memory_generateConstPlayfield" |
|
|
#} |
|
|
#} |
|
|
|
|
|
|
|
|
def test_memory_selectItem( |
|
|
|
|
|
|
|
|
def test_memory_selectOneItem( |
|
|
) -> str: |
|
|
) -> str: |
|
|
c = memory_createEmptyContext() |
|
|
c = memory_createEmptyContext() |
|
|
c.playfieldSize = 2 |
|
|
c.playfieldSize = 2 |
|
|
memory_generateConstPlayfield(c) |
|
|
|
|
|
# Select the item with group 0. |
|
|
|
|
|
fieldName = memory_selectItem(c, 0) |
|
|
|
|
|
|
|
|
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. |
|
|
# See if it's in selectedItems now. |
|
|
if ( |
|
|
if ( |
|
|
fieldName == "selectedItems" and |
|
|
|
|
|
|
|
|
c.recentField == "selectedItems" and |
|
|
len(c.selectedItems) == 1 and |
|
|
len(c.selectedItems) == 1 and |
|
|
c.selectedItems[0] == 0 |
|
|
c.selectedItems[0] == 0 |
|
|
): |
|
|
): |
|
|
return "OK: memory_selectItem" |
|
|
|
|
|
|
|
|
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_selectItem" |
|
|
|
|
|
|
|
|
return "ERR: memory_selectThreeItems" |
|
|
#} |
|
|
#} |