From afd40d2b63e3037888677a1ea3b922aba1c99c6b Mon Sep 17 00:00:00 2001 From: Denis Koinash Date: Sat, 1 Feb 2025 16:00:52 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=82=D0=BE=D1=80=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=B5=D0=BD=D1=81=D1=82=D0=B0=20=D0=B7=D0=BD=D0=B0=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=BA=D0=BE=D0=BE=D1=80=D0=B4=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- projects/core/include/core/common.h | 10 ++++++++++ projects/core/src/core/common.cpp | 7 +++++++ 2 files changed, 17 insertions(+) create mode 100644 projects/core/src/core/common.cpp diff --git a/projects/core/include/core/common.h b/projects/core/include/core/common.h index 6dfd322..3f3f26c 100644 --- a/projects/core/include/core/common.h +++ b/projects/core/include/core/common.h @@ -21,6 +21,16 @@ struct Position int8_t y; }; +/** + * @brief Оператор сравнения позиций + * + * @param current Текущая позиция + * @param other Позиция для сравнения + * @return Возвращает true если координаты совпадают, иначе false + */ +bool +operator==(const Position current, const Position other); + /** * @brief Уровни сложности * diff --git a/projects/core/src/core/common.cpp b/projects/core/src/core/common.cpp new file mode 100644 index 0000000..e322325 --- /dev/null +++ b/projects/core/src/core/common.cpp @@ -0,0 +1,7 @@ +#include + +bool +OpenIT::operator==(const Position current, const Position other) +{ + return current.x == other.x && current.y == other.y; +} \ No newline at end of file From fec70d2ff3531ddeb0f9e6824b06b63d6c0f9321 Mon Sep 17 00:00:00 2001 From: Denis Koinash Date: Sat, 1 Feb 2025 17:00:33 +0300 Subject: [PATCH 2/2] =?UTF-8?q?Unit-=D1=82=D0=B5=D1=81=D1=82=D1=8B=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20Gam?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- projects/core/tests/test.cpp | 75 ++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 12 deletions(-) diff --git a/projects/core/tests/test.cpp b/projects/core/tests/test.cpp index 9ce2b6a..7faa177 100644 --- a/projects/core/tests/test.cpp +++ b/projects/core/tests/test.cpp @@ -1,31 +1,82 @@ +#include #include #include using namespace OpenIT; -TEST(TestPlayer, ConstructorWithoutParameter_Check) +#if DEPRECATED +TEST(TestGame, Constructor) { - Player player; + // ToDo Constractor test + Game game; - ASSERT_EQ(player.GetNickname(), ""); + ASSERT_EQ(true, true); } +#endif // DEPRECATED -TEST(TestPlayer, ConstructorWithParameter_Check) +TEST(TestGame, Start_Check) { - const std::string name = "SomeName"; + Game game; - Player player(name); + game.Start(); - ASSERT_EQ(player.GetNickname(), name); + Position carriage = { FIELD_SIZE / 2, FIELD_SIZE / 2 }; + + ASSERT_EQ(game.GetCarriage(), carriage); + ASSERT_EQ(game.GetActivePlayer(), 0); + ASSERT_EQ(game.IsGameOver(), false); +} + +TEST(TestGame, AddPlayer_Check) +{ + Game game; + + Player first; + + Player second; + + Player third; + + game.Start(); + + ASSERT_EQ(game.AddPlayer(second), true); + ASSERT_EQ(game.AddPlayer(first), true); + ASSERT_EQ(game.AddPlayer(third), false); +} + +TEST(TestGame, RemotePlayer_Check) +{ + Game game; + + Player first; + + Player second; + + game.Start(); + + game.AddPlayer(first); + game.AddPlayer(second); + + ASSERT_EQ(game.RemovePlayer(1), true); + ASSERT_EQ(game.RemovePlayer(1), false); + ASSERT_EQ(game.RemovePlayer(0), true); + ASSERT_EQ(game.RemovePlayer(0), false); } -TEST(TestPlayer, SetNickname_Check) +TEST(TestGame, Player_SetNames) { - Player player; + Player first; + + Player second; + + std::string firstName = "MrFirst"; + + std::string secondName = "MsSecond"; - const std::string name = "SomeName"; + first.SetNickname(firstName); - player.SetNickname(name); + second.SetNickname(secondName); - ASSERT_EQ(player.GetNickname(), name); + ASSERT_EQ(first.GetNickname(), firstName); + ASSERT_EQ(second.GetNickname(), secondName); } \ No newline at end of file