From 2bb1bf5fa8c6b4884d966cb2759731403b85f643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Sat, 13 Apr 2024 23:15:41 +0300 Subject: [PATCH] d --- v2/entities.py | 3 ++- v2/functions.py | 36 ++++++++++++++++++++++++++++++------ v2/gen-Python | 2 ++ v2/main.py | 1 + 4 files changed, 35 insertions(+), 7 deletions(-) create mode 100755 v2/gen-Python diff --git a/v2/entities.py b/v2/entities.py index f23babe..b12e9b9 100644 --- a/v2/entities.py +++ b/v2/entities.py @@ -1,6 +1,7 @@ class MemoryContext: - playfieldSize = 0 playfieldItems = {} + playfieldSize = 0 + selectedItems = [] def memory_createEmptyContext(): return MemoryContext() diff --git a/v2/functions.py b/v2/functions.py index d46aa4d..18b398d 100644 --- a/v2/functions.py +++ b/v2/functions.py @@ -1,8 +1,5 @@ from entities import * - -# L4: Function. - def memory_generateConstPlayfield( c: MemoryContext ) -> str: @@ -15,10 +12,18 @@ def memory_generateConstPlayfield( id += 1 #} c.playfieldItems = idGroups - return "MemoryContext.playfieldItems" + return "playfieldItems" #} -# L20: Test. +def memory_selectItem( + c: MemoryContext, + id: int +) -> str: + c.selectedItems.append(id) + return "selectedItems" +#} + +# Test. def test_memory_generateConstPlayfield( ) -> str: @@ -26,7 +31,7 @@ def test_memory_generateConstPlayfield( c.playfieldSize = 2 fieldName = memory_generateConstPlayfield(c) if ( - fieldName == "MemoryContext.playfieldItems" and + fieldName == "playfieldItems" and len(c.playfieldItems) == 4 and c.playfieldItems[0] == 0 and c.playfieldItems[1] == 0 and @@ -37,3 +42,22 @@ def test_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" +#} diff --git a/v2/gen-Python b/v2/gen-Python new file mode 100755 index 0000000..44f45f4 --- /dev/null +++ b/v2/gen-Python @@ -0,0 +1,2 @@ +echo "python3 main.py" > test_memory_Python +chmod +x test_memory_Python diff --git a/v2/main.py b/v2/main.py index 01ff942..bd9a29c 100644 --- a/v2/main.py +++ b/v2/main.py @@ -2,3 +2,4 @@ from entities import * from functions import * print(test_memory_generateConstPlayfield()) +print(test_memory_selectItem())