From 1d5d88e3157881e94b27c12f101295f9dd9fb271 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: Mon, 25 Mar 2024 23:26:56 +0300 Subject: [PATCH] d --- gen-C++ | 2 +- gen-Swift | 4 +++- language-C++/src/{test.cpp => main.cpp} | 0 language-Swift/Memory/src/Memory.Aux.swift | 26 +++++++-------------- language-Swift/Memory/src/Memory.Test.swift | 14 +++++++++++ language-Swift/src/main.swift | 1 + language-Swift/src/test.swift | 6 ----- 7 files changed, 28 insertions(+), 25 deletions(-) rename language-C++/src/{test.cpp => main.cpp} (100%) create mode 100644 language-Swift/Memory/src/Memory.Test.swift create mode 100644 language-Swift/src/main.swift delete mode 100644 language-Swift/src/test.swift diff --git a/gen-C++ b/gen-C++ index 8bad2ba..415cab1 100755 --- a/gen-C++ +++ b/gen-C++ @@ -2,4 +2,4 @@ c++ -o test_memory_C++ \ -Ilanguage-C++/Memory/src \ language-C++/Memory/src/Memory.Aux.cpp \ language-C++/Memory/src/Memory.Test.cpp \ - language-C++/src/test.cpp + language-C++/src/main.cpp diff --git a/gen-Swift b/gen-Swift index 8a6c661..0622974 100755 --- a/gen-Swift +++ b/gen-Swift @@ -1,2 +1,4 @@ swiftc -o test_memory_Swift \ - language-Swift/src/test.swift + language-Swift/Memory/src/Memory.Aux.swift \ + language-Swift/Memory/src/Memory.Test.swift \ + language-Swift/src/main.swift diff --git a/language-C++/src/test.cpp b/language-C++/src/main.cpp similarity index 100% rename from language-C++/src/test.cpp rename to language-C++/src/main.cpp diff --git a/language-Swift/Memory/src/Memory.Aux.swift b/language-Swift/Memory/src/Memory.Aux.swift index 50f36a2..4d28373 100644 --- a/language-Swift/Memory/src/Memory.Aux.swift +++ b/language-Swift/Memory/src/Memory.Aux.swift @@ -1,22 +1,14 @@ -#include -#include "Memory.h" - - -std::map memory_generateConstPlayfield( - int n -) { - std::map idGroups; - int id = 0; - for (int gid = 0; gid < n; ++gid) { - idGroups[id++] = gid; - idGroups[id++] = gid; - } - return idGroups; -} - func memory_generateConstPlayfield( - n: Int + _ n: Int ) -> [Int: Int] { var idGroups = [Int: Int]() + var id = 0 + for gid in stride(from: 0, to: n, by: 1) { + idGroups[id] = gid + id += 1 + idGroups[id] = gid + id += 1 + } + return idGroups } diff --git a/language-Swift/Memory/src/Memory.Test.swift b/language-Swift/Memory/src/Memory.Test.swift new file mode 100644 index 0000000..01b7cd6 --- /dev/null +++ b/language-Swift/Memory/src/Memory.Test.swift @@ -0,0 +1,14 @@ +func test_memory_generateConstPlayfield() -> String { + let idGroups = memory_generateConstPlayfield(2) + if ( + idGroups.count == 4 && + idGroups[0] == 0 && + idGroups[1] == 0 && + idGroups[2] == 1 && + idGroups[3] == 1 + ) { + return "OK: memory_generateConstPlayfield" + } + + return "ERR: memory_generateConstPlayfield"; +} diff --git a/language-Swift/src/main.swift b/language-Swift/src/main.swift new file mode 100644 index 0000000..a19c5a7 --- /dev/null +++ b/language-Swift/src/main.swift @@ -0,0 +1 @@ +print(test_memory_generateConstPlayfield()) diff --git a/language-Swift/src/test.swift b/language-Swift/src/test.swift deleted file mode 100644 index 2deff4e..0000000 --- a/language-Swift/src/test.swift +++ /dev/null @@ -1,6 +0,0 @@ -print("Hello, world from Swift") -/* - std::cout - << test_memory_generateConstPlayfield() - << std::endl; -*/