diff --git a/src/common/game_state/player/hand.cpp b/src/common/game_state/player/hand.cpp index 3f0fa64e2e8c01816a8061c7c4126abf0dbefc86..930c06b770175bda4425facd0dd02aa10ed9730a 100644 --- a/src/common/game_state/player/hand.cpp +++ b/src/common/game_state/player/hand.cpp @@ -1,5 +1,7 @@ #include "hand.h" +#include <bits/ranges_util.h> + #include "../../exceptions/WizardException.h" #include "../../serialization/vector_utils.h" diff --git a/unit-tests/CMakeLists.txt b/unit-tests/CMakeLists.txt index 81af0b5a7c58b3bbc21c4600d9a296cf17e0ad46..de5d2cb8cca78cc789329b1d3214bb0d328d1597 100644 --- a/unit-tests/CMakeLists.txt +++ b/unit-tests/CMakeLists.txt @@ -1,11 +1,11 @@ project(Wizard-unit-tests) set(TEST_SOURCE_FILES - #card.cpp + card.cpp # deck.cpp - hand.cpp) - # player.cpp) - #trick.cpp) + hand.cpp + player.cpp + trick.cpp) add_executable(Wizard-tests ${TEST_SOURCE_FILES}) diff --git a/unit-tests/card.cpp b/unit-tests/card.cpp index 658608ac372e1ff3227a88be2b6dcfc838301fca..a15b064ee2d57027d70167d158ea689e1000bbbb 100644 --- a/unit-tests/card.cpp +++ b/unit-tests/card.cpp @@ -7,9 +7,13 @@ #include "../src/common/game_state/cards/card.h" #include "../src/common/serialization/json_utils.h" +class CardTest : public ::testing::Test { + + +}; // check proper initialization and getters -TEST(CardTest, MakeCardGetMembers) { +TEST_F(CardTest, MakeCardGetMembers) { card c_1(0,0); card c_2(14,0); card c_3(1,2); @@ -37,7 +41,7 @@ TEST(CardTest, MakeCardGetMembers) { } // Serialization and subsequent deserialization must yield the same object -TEST(CardTest, SerializationEquality) { +TEST_F(CardTest, SerializationEquality) { card card_send(1,1); rapidjson::Document* json_send = card_send.to_json(); std::string message = json_utils::to_string(json_send); @@ -54,7 +58,7 @@ TEST(CardTest, SerializationEquality) { } // Deserializing an invalid string must throw a WizardException -TEST(CardTest, SerializationException) { +TEST_F(CardTest, SerializationException) { rapidjson::Document json = rapidjson::Document(rapidjson::kObjectType); json.Parse("not json"); EXPECT_THROW(card::from_json(json), WizardException); diff --git a/unit-tests/player.cpp b/unit-tests/player.cpp index 36159c117b8f16ed19ac40e3d46f7bf82110d9b0..6ff8e1bab5a8f45901ca7deca7f8e89814056650 100644 --- a/unit-tests/player.cpp +++ b/unit-tests/player.cpp @@ -8,8 +8,11 @@ #include "../src/common/game_state/player/player.h" #include "../src/common/serialization/json_utils.h" +class PlayerTest : public ::testing::Test { -TEST(PlayerTest, CreatePlayer) +}; + +TEST_F(PlayerTest, CreatePlayer) { std::string name = "vatkruidvat"; player test_player(name); @@ -40,7 +43,7 @@ TEST(PlayerTest, CreatePlayer) } -TEST(HandTest, RemoveFromEmptyHand) +TEST_F(PlayerTest, RemoveFromEmptyHand) { std::string name = "vatkruidvat"; @@ -60,7 +63,7 @@ TEST(HandTest, RemoveFromEmptyHand) } // checks add_card, get_nof_cards, remove card -TEST(HandTest, HandWithOneCard) +TEST_F(PlayerTest, HandWithOneCard) { std::string name = "vatkruidvat"; @@ -90,7 +93,7 @@ TEST(HandTest, HandWithOneCard) //delete test_card; } -TEST(HandTest, HandWithThreeCards) +TEST_F(PlayerTest, HandWithThreeCards) { std::string name = "vatkruidvat"; player test_player(name); @@ -152,7 +155,7 @@ TEST(HandTest, HandWithThreeCards) //incorrect estimate -> -10 for each trick offset // tests if score is computed correctly if predicted tricks == collected tricks -TEST(HandTest, WrapUpRoundBadPrediction) +TEST_F(PlayerTest, WrapUpRoundBadPrediction) { std::string name = "vatkruidvat"; @@ -176,7 +179,7 @@ TEST(HandTest, WrapUpRoundBadPrediction) } // tests if score is computed correctly if predicted tricks == collected tricks -TEST(HandTest, WrapUpRoundGoodGameplay) +TEST_F(PlayerTest, WrapUpRoundGoodGameplay) { std::string name = "vatkruidvat"; @@ -202,7 +205,7 @@ TEST(HandTest, WrapUpRoundGoodGameplay) } // Serialization and subsequent deserialization must yield the same object -TEST(CardTest, SerializationEquality) { +TEST_F(PlayerTest, SerializationEquality) { std::string name = "vatkruidvat"; player player_send(name); player_send.set_scores(20); @@ -231,7 +234,7 @@ TEST(CardTest, SerializationEquality) { } // Deserializing an invalid string must throw a WizardException -TEST(CardTest, SerializationException) { +TEST_F(PlayerTest, SerializationException) { rapidjson::Document json = rapidjson::Document(rapidjson::kObjectType); json.Parse("not json"); EXPECT_THROW(player::from_json(json), WizardException); diff --git a/unit-tests/trick.cpp b/unit-tests/trick.cpp index 9741c8098ed6c407c0535fb24ac0cc7a3b2a848c..ec2fdd3e4cee1ca8de2697496daa09441f135655 100644 --- a/unit-tests/trick.cpp +++ b/unit-tests/trick.cpp @@ -9,7 +9,7 @@ #include "../src/common/game_state/cards/trick.h" #include "../src/common/serialization/json_utils.h" -class trick_testing : public ::testing::Test +class TrickTest : public ::testing::Test { protected: serializable_value<int>* trick_color = nullptr; @@ -34,7 +34,7 @@ protected: //note about cards: 1-13 are number cards (x4), 0 are jester cards (x4), 14 are wizard cards (x4) //note about trick color setup: if trick color == 0, it means the trick color has not been set yet. if first card is a wizard, it's set to -1 // -TEST_F(trick_testing, CreateAndChangeTrick) { +TEST_F(TrickTest, CreateAndChangeTrick) { trick_color = new serializable_value<int>(2); //trick color is 2 trump_color = new serializable_value<int>(3); @@ -61,7 +61,7 @@ TEST_F(trick_testing, CreateAndChangeTrick) { // scoring scenarios // have any card be a wizard --> wins -TEST_F(trick_testing, OneWizard) +TEST_F(TrickTest, OneWizard) { trick_color = new serializable_value<int>(0); // trick color is 0 trump_color = new serializable_value<int>(3);// trump color is 3 @@ -92,7 +92,7 @@ TEST_F(trick_testing, OneWizard) } //first wizard card wins -TEST_F(trick_testing, AllWizards) +TEST_F(TrickTest, AllWizards) { trick_color = new serializable_value<int>(0); // trick color is 0 trump_color = new serializable_value<int>(3); // trump color is 3 @@ -124,7 +124,7 @@ TEST_F(trick_testing, AllWizards) //first card is a jester --> wins only if everyone plays a jester, otherwise the jester looses -TEST_F(trick_testing, OneJesterHighestCard) +TEST_F(TrickTest, OneJesterHighestCard) { trick_color = new serializable_value<int>(2); // trick color is 2 trump_color = new serializable_value<int>(4);// trump color is 4 @@ -154,7 +154,7 @@ TEST_F(trick_testing, OneJesterHighestCard) } //first card is a jester, trump card wins -TEST_F(trick_testing, OneJesterWithTrump) +TEST_F(TrickTest, OneJesterWithTrump) { trick_color = new serializable_value<int>(2); // trick color is 2 trump_color = new serializable_value<int>(4);// trump color is 4 @@ -187,7 +187,7 @@ TEST_F(trick_testing, OneJesterWithTrump) //first card is a jester, wizard card wins -TEST_F(trick_testing, OneJesterWithWizard) +TEST_F(TrickTest, OneJesterWithWizard) { trick_color = new serializable_value<int>(0); // trick color is 0 trump_color = new serializable_value<int>(4);// trump color is 4 @@ -218,7 +218,7 @@ TEST_F(trick_testing, OneJesterWithWizard) } //first card is a jester, wizard card wins -TEST_F(trick_testing, OneJesterWithWizardAndTrump) +TEST_F(TrickTest, OneJesterWithWizardAndTrump) { trick_color = new serializable_value<int>(2); // trick color is 2 trump_color = new serializable_value<int>(4);// trump color is 4 @@ -249,7 +249,7 @@ TEST_F(trick_testing, OneJesterWithWizardAndTrump) } //all jesters -TEST_F(trick_testing, AllJesters) +TEST_F(TrickTest, AllJesters) { trick_color = new serializable_value<int>(0); // trick color is 0 trump_color = new serializable_value<int>(4);// trump color for this trick is 4 @@ -283,7 +283,7 @@ TEST_F(trick_testing, AllJesters) //highest trump card wins -TEST_F(trick_testing, HighestTrump) +TEST_F(TrickTest, HighestTrump) { trick_color = new serializable_value<int>(3); // trick color is 3 trump_color = new serializable_value<int>(2);// trump color is 2 @@ -316,7 +316,7 @@ TEST_F(trick_testing, HighestTrump) //only trump played -> highest trump card wins -TEST_F(trick_testing, OnlyTrump) +TEST_F(TrickTest, OnlyTrump) { trick_color = new serializable_value<int>(1); // trick color is 1 trump_color = new serializable_value<int>(1);// trump color is 1 @@ -347,7 +347,7 @@ TEST_F(trick_testing, OnlyTrump) EXPECT_EQ(cards_and_players[2].first->get_value(), 13); //third card should be a 13 } // if no trump is played, the highest card wins -TEST_F(trick_testing, NoTrump) +TEST_F(TrickTest, NoTrump) { trick_color = new serializable_value<int>(1); // trick color is 1 trump_color = new serializable_value<int>(3);// trump color is 3 @@ -377,7 +377,7 @@ TEST_F(trick_testing, NoTrump) } //check setup round -TEST_F(trick_testing, SetupRound) +TEST_F(TrickTest, SetupRound) { trick_color = new serializable_value<int>(1); // trick color is 1 trump_color = new serializable_value<int>(3);// trump color is 3 @@ -409,7 +409,7 @@ TEST_F(trick_testing, SetupRound) } //check add card -TEST_F(trick_testing, AddCard) +TEST_F(TrickTest, AddCard) { int trump_color = 3; std::string err = ""; @@ -433,7 +433,7 @@ TEST_F(trick_testing, AddCard) //test a full round -TEST_F(trick_testing, EntireRound) +TEST_F(TrickTest, EntireRound) { int trump_color = 4; std::string err = ""; @@ -484,7 +484,7 @@ TEST_F(trick_testing, EntireRound) // Serialization and subsequent deserialization must yield the same object -TEST_F(trick_testing, SerializationEquality) { +TEST_F(TrickTest, SerializationEquality) { trick_color = new serializable_value<int>(2); //trick color is 2 trump_color = new serializable_value<int>(3); @@ -512,9 +512,10 @@ TEST_F(trick_testing, SerializationEquality) { } // Deserializing an invalid string must throw a WizardException -TEST_F(trick_testing, SerializationException) { +TEST_F(TrickTest, SerializationException) { rapidjson::Document json = rapidjson::Document(rapidjson::kObjectType); json.Parse("not json"); EXPECT_THROW(trick::from_json(json), WizardException); } +//version 5.12 17:10 \ No newline at end of file