diff --git a/source/general/game_state/hand.hpp b/source/general/game_state/hand.hpp index 4d76b9a68376cf4e28b6bae6c7c0aaca2395a96b..394ac03af33547cd488ee99b58ca51ee7b81e0a6 100644 --- a/source/general/game_state/hand.hpp +++ b/source/general/game_state/hand.hpp @@ -31,7 +31,7 @@ public: bool add_card(card* card, std::string& err); //checked int get_points(std::string &err); //checked - bool is_over_21(std::string &err); //TODO + bool is_over_21(std::string &err); //checked std::vector<card*>::iterator get_card_iterator(); }; diff --git a/unit-tests/hand.cpp b/unit-tests/hand.cpp index 43eb45975e2e6343977ece9704fa056b9103fa01..7fe7b1832ccaf13971339ce3e13ec15631d31d74 100644 --- a/unit-tests/hand.cpp +++ b/unit-tests/hand.cpp @@ -259,4 +259,61 @@ TEST_F(HandTest, SetupRoundManyCardsWithDuplicates) { player_hand.setup_round(err); std::vector<card*> expected_hand = {}; EXPECT_EQ(expected_hand, player_hand.get_cards()); +} + +// An empty hand will not have a score of over 21 +TEST_F(HandTest, IsOver21NoCards) { + EXPECT_FALSE(player_hand.is_over_21(err)); +} + +// A hand with only one card will not have a score of over 21 +TEST_F(HandTest, IsOver21OneCard) { + EXPECT_FALSE(player_hand.is_over_21(err)); +} + +// A hand with less than 21 points will not have a score of over 21 +TEST_F(HandTest, IsOver21ManyCardsFalse) { + player_hand.add_card(cards[2][0], err); + player_hand.add_card(cards[7][0], err); + player_hand.add_card(cards[9][0], err); + EXPECT_FALSE(player_hand.is_over_21(err)); +} +// A hand (including an ace) with less than 21 points will not have a score of over 21 +TEST_F(HandTest, IsOver21ManyCardsWithAceFalse) { + player_hand.add_card(cards[1][0], err); + player_hand.add_card(cards[7][0], err); + player_hand.add_card(cards[9][0], err); + EXPECT_FALSE(player_hand.is_over_21(err)); +} + +// A hand of 21 points will not have a score of over 21 +TEST_F(HandTest, IsOver21Exactly) { + player_hand.add_card(cards[4][0], err); + player_hand.add_card(cards[7][0], err); + player_hand.add_card(cards[10][0], err); + EXPECT_FALSE(player_hand.is_over_21(err)); +} + +// A hand of 21 points (one ace and a face card) will not have a score of over 21 +TEST_F(HandTest, IsOver21ExactlyWithAce) { + player_hand.add_card(cards[1][0], err); + player_hand.add_card(cards[13][0], err); + EXPECT_FALSE(player_hand.is_over_21(err)); +} + +// A hand of over 21 points will return true for is_over_21() +TEST_F(HandTest, IsOver21ManyCardsTrue) { + player_hand.add_card(cards[10][0], err); + player_hand.add_card(cards[4][0], err); + player_hand.add_card(cards[13][0], err); + EXPECT_TRUE(player_hand.is_over_21(err)); +} + +// A hand of over 21 points (with ace) will return true for is_over_21() +TEST_F(HandTest, IsOver21TrueWithAce) { + player_hand.add_card(cards[1][0], err); + player_hand.add_card(cards[7][0], err); + player_hand.add_card(cards[13][0], err); + player_hand.add_card(cards[5][0], err); + EXPECT_TRUE(player_hand.is_over_21(err)); } \ No newline at end of file