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 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