Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Blackjack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pascal Engeler
Blackjack
Commits
c3215407
Commit
c3215407
authored
2 years ago
by
Flavia Taras
Browse files
Options
Downloads
Patches
Plain Diff
finished hand tests
parent
cc58f090
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
source/general/game_state/hand.hpp
+1
-1
1 addition, 1 deletion
source/general/game_state/hand.hpp
unit-tests/hand.cpp
+57
-0
57 additions, 0 deletions
unit-tests/hand.cpp
with
58 additions
and
1 deletion
source/general/game_state/hand.hpp
+
1
−
1
View file @
c3215407
...
@@ -31,7 +31,7 @@ public:
...
@@ -31,7 +31,7 @@ public:
bool
add_card
(
card
*
card
,
std
::
string
&
err
);
//checked
bool
add_card
(
card
*
card
,
std
::
string
&
err
);
//checked
int
get_points
(
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
();
std
::
vector
<
card
*>::
iterator
get_card_iterator
();
};
};
...
...
This diff is collapsed.
Click to expand it.
unit-tests/hand.cpp
+
57
−
0
View file @
c3215407
...
@@ -259,4 +259,61 @@ TEST_F(HandTest, SetupRoundManyCardsWithDuplicates) {
...
@@ -259,4 +259,61 @@ TEST_F(HandTest, SetupRoundManyCardsWithDuplicates) {
player_hand
.
setup_round
(
err
);
player_hand
.
setup_round
(
err
);
std
::
vector
<
card
*>
expected_hand
=
{};
std
::
vector
<
card
*>
expected_hand
=
{};
EXPECT_EQ
(
expected_hand
,
player_hand
.
get_cards
());
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment