From c32154076911054c7b279e9b544253e7a659e7b1 Mon Sep 17 00:00:00 2001
From: Flavia Taras <flaviataras@student-net-cx-0991.intern.ethz.ch>
Date: Wed, 25 May 2022 09:22:13 +0200
Subject: [PATCH] finished hand tests

---
 source/general/game_state/hand.hpp |  2 +-
 unit-tests/hand.cpp                | 57 ++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/source/general/game_state/hand.hpp b/source/general/game_state/hand.hpp
index 4d76b9a..394ac03 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 43eb459..7fe7b18 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
-- 
GitLab