diff --git a/C++/Memory.Aux.cpp b/C++/Memory.Aux.cpp deleted file mode 100644 index af6888e..0000000 --- a/C++/Memory.Aux.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include "Memory.h" - -std::map memory_generateConstPlayfield( - int n -) { - std::map idGroups; - auto id = 0; - for (int gid = 0; gid < n; ++gid) { - idGroups[id] = gid; - id += 1; - idGroups[id] = gid; - id += 1; - } - return idGroups; -} diff --git a/C++/main.cpp b/C++/main.cpp deleted file mode 100644 index 404e5ee..0000000 --- a/C++/main.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "Memory.h" -#include - -int main() { - std::cout - << test_memory_generateConstPlayfield() - << std::endl; -} diff --git a/C++/Memory.Test.cpp b/Memory.Test.cpp similarity index 100% rename from C++/Memory.Test.cpp rename to Memory.Test.cpp diff --git a/C++/Memory.h b/Memory.h similarity index 100% rename from C++/Memory.h rename to Memory.h diff --git a/gen-C++ b/gen-C++ index 5167d64..cbf52cd 100755 --- a/gen-C++ +++ b/gen-C++ @@ -1,6 +1 @@ -c++ -o test_memory_C++ \ - -std=c++11 \ - -IC++ \ - C++/Memory.Aux.cpp \ - C++/Memory.Test.cpp \ - C++/main.cpp +c++ -o test_memory_C++ -std=c++11 main.cpp diff --git a/gen-JavaScript b/gen-JavaScript new file mode 100755 index 0000000..134379b --- /dev/null +++ b/gen-JavaScript @@ -0,0 +1,2 @@ +echo "node main.js" > test_memory_JavaScript +chmod +x test_memory_JavaScript diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..add1041 --- /dev/null +++ b/main.cpp @@ -0,0 +1,35 @@ +#include +#include + +std::map memory_generateConstPlayfield( + int n +) { + std::map idGroups; + auto id = 0; + for (auto gid = 0; gid < n; ++gid) { + idGroups[id] = gid; + id += 1; + idGroups[id] = gid; + id += 1; + } + return idGroups; +} + +std::string test_memory_generateConstPlayfield() { + auto idGroups = memory_generateConstPlayfield(2); + if ( + idGroups.size() == 4 && + idGroups[0] == 0 && + idGroups[1] == 0 && + idGroups[2] == 1 && + idGroups[3] == 1 + ) { + return "OK: memory_generateConstPlayfield"; + } + + return "ERR: memory_generateConstPlayfield"; +} + +int main() { + printf("%s\n", test_memory_generateConstPlayfield().c_str()); +} diff --git a/main.js b/main.js new file mode 100644 index 0000000..6f2559c --- /dev/null +++ b/main.js @@ -0,0 +1,31 @@ +function memory_generateConstPlayfield( + n +) { + var idGroups = {}; + var id = 0; + for (let gid = 0; gid < n; ++gid) { + idGroups[id] = gid; + id += 1; + idGroups[id] = gid; + id += 1; + } + + return idGroups; +} + +function test_memory_generateConstPlayfield() { + let idGroups = memory_generateConstPlayfield(2) + if ( + Object.keys(idGroups).length == 4 && + idGroups[0] == 0 && + idGroups[1] == 0 && + idGroups[2] == 1 && + idGroups[3] == 1 + ) { + return "OK: memory_generateConstPlayfield" + } + + return "ERR: memory_generateConstPlayfield" +} + +console.log(test_memory_generateConstPlayfield())