This commit is contained in:
Михаил Капелько
2024-04-11 16:46:56 +03:00
parent 374b21d68e
commit 4095389578
9 changed files with 90 additions and 7 deletions

5
v2/entities.cpp Normal file
View File

@@ -0,0 +1,5 @@
#include "entities.h"
MemoryContext memory_createEmptyContext() {
return MemoryContext();
}

9
v2/entities.h Normal file
View File

@@ -0,0 +1,9 @@
#include <map>
#include <string>
struct MemoryContext {
int playfieldSize = 0;
std::map<int, int> playfieldItems;
};
MemoryContext memory_createEmptyContext();

42
v2/functions.cpp Normal file
View File

@@ -0,0 +1,42 @@
#include <map>
#include <string>
#include "entities.h"
// L4: Function.
std::string memory_generateConstPlayfield(
MemoryContext& c
) {
std::map<int, int> idGroups = { };
auto id = 0;
for (auto gid = 0; gid < c.playfieldSize; ++gid) {
idGroups[id] = gid;
id += 1;
idGroups[id] = gid;
id += 1;
}
c.playfieldItems = idGroups;
return "MemoryContext.playfieldItems";
}
// L20: Test.
std::string test_memory_generateConstPlayfield(
) {
auto c = memory_createEmptyContext();
c.playfieldSize = 2;
auto fieldName = memory_generateConstPlayfield(c);
if (
fieldName == "MemoryContext.playfieldItems" &&
c.playfieldItems.size() == 4 &&
c.playfieldItems[0] == 0 &&
c.playfieldItems[1] == 0 &&
c.playfieldItems[2] == 1 &&
c.playfieldItems[3] == 1
) {
return "OK: memory_generateConstPlayfield";
}
return "ERR: memory_generateConstPlayfield";
}

8
v2/functions.h Normal file
View File

@@ -0,0 +1,8 @@
#include "entities.h"
std::string memory_generateConstPlayfield(
MemoryContext& c
);
std::string test_memory_generateConstPlayfield(
);

View File

@@ -25,14 +25,13 @@ def test_memory_generateConstPlayfield(
c = memory_createEmptyContext()
c.playfieldSize = 2
fieldName = memory_generateConstPlayfield(c)
idGroups = c.playfieldItems
if (
fieldName == "MemoryContext.playfieldItems" and
len(idGroups) == 4 and
idGroups[0] == 0 and
idGroups[1] == 0 and
idGroups[2] == 1 and
idGroups[3] == 1
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"
#}

1
v2/gen-C++ Executable file
View File

@@ -0,0 +1 @@
c++ -o test_memory_C++ -std=c++11 -I. entities.cpp functions.cpp main.cpp

8
v2/main.cpp Normal file
View File

@@ -0,0 +1,8 @@
#include <map>
#include <string>
#include "functions.h"
int main() {
printf("%s\n", test_memory_generateConstPlayfield().c_str());
}